[Zope3-checkins] SVN: zdaemon/trunk/src/zdaemon/ fix directory chown and add a test

Christian Zagrodnick cz at gocept.com
Thu Jan 29 03:43:31 EST 2009


Log message for revision 95384:
  fix directory chown and add a test
  

Changed:
  U   zdaemon/trunk/src/zdaemon/tests/testzdrun.py
  U   zdaemon/trunk/src/zdaemon/zdctl.py

-=-
Modified: zdaemon/trunk/src/zdaemon/tests/testzdrun.py
===================================================================
--- zdaemon/trunk/src/zdaemon/tests/testzdrun.py	2009-01-29 08:35:16 UTC (rev 95383)
+++ zdaemon/trunk/src/zdaemon/tests/testzdrun.py	2009-01-29 08:43:30 UTC (rev 95384)
@@ -392,7 +392,31 @@
         open(config_file, 'w').write(config)
         return config_file
 
+    def testDirectoryChown(self):
+        path = os.path.join(self.root, 'foodir')
+        options = zdctl.ZDCtlOptions()
+        options.realize(['-p', self.cmd])
+        cmd = zdctl.ZDCmd(options)
+        options.uid = 27
+        options.gid = 28
+        # Patch chown and geteuid, because we're not root
+        chown = os.chown
+        geteuid = os.geteuid
+        calls = []
+        def my_chown(*args):
+            calls.append(('chown',) + args)
+        def my_geteuid():
+            return 0
+        try:
+            os.chown = my_chown
+            os.geteuid = my_geteuid
+            cmd.create_directory(path)
+        finally:
+            os.chown = chown
+            os.geteuid = geteuid
+        self.assertEqual([('chown', path, 27, 28)], calls)
 
+
 def send_action(action, sockname):
     """Send an action to the zdrun server and return the response.
 

Modified: zdaemon/trunk/src/zdaemon/zdctl.py
===================================================================
--- zdaemon/trunk/src/zdaemon/zdctl.py	2009-01-29 08:35:16 UTC (rev 95383)
+++ zdaemon/trunk/src/zdaemon/zdctl.py	2009-01-29 08:43:30 UTC (rev 95384)
@@ -167,7 +167,7 @@
         uid = os.geteuid()
         if uid == 0 and uid != self.options.uid:
             # Change owner of directory to target
-            os.chown(self.options.uid, self.options.gid)
+            os.chown(directory, self.options.uid, self.options.gid)
 
     def set_uid(self):
         if self.options.uid is None:



More information about the Zope3-Checkins mailing list