[Buildbot-commits] buildbot/buildbot/slave commands.py,1.30,1.31

Brian Warner warner at users.sourceforge.net
Fri May 13 20:28:13 UTC 2005


Update of /cvsroot/buildbot/buildbot/buildbot/slave
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31279/buildbot/slave

Modified Files:
	commands.py 
Log Message:
(rmdirRecursive): replacement for shutil.rmtree which behaves correctly on
windows in the face of files that you have to chmod before deleting. Thanks
to Bear at the OSAF for the routine.
(SourceBase.doClobber): use rmdirRecursive


Index: commands.py
===================================================================
RCS file: /cvsroot/buildbot/buildbot/buildbot/slave/commands.py,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -d -r1.30 -r1.31
--- commands.py	12 May 2005 07:26:24 -0000	1.30
+++ commands.py	13 May 2005 20:28:11 -0000	1.31
@@ -29,6 +29,27 @@
     def __repr__(self):
         return "<AbandonChain rc=%s>" % self.args[0]
 
+def rmdirRecursive(dir):
+    """This is a replacement for shutil.rmtree that works better under
+    windows. Thanks to Bear at the OSAF for the code."""
+    if os.path.islink(dir):
+        os.remove(dir)
+        return
+
+    for name in os.listdir(dir):
+        full_name = os.path.join(dir, name)
+        # on Windows, if we don't have write permission we can't remove
+        # the file/directory either, so turn that on
+        if os.name == 'nt':
+            if not os.access(full_name, os.W_OK):
+                os.chmod(full_name, 0600)
+        if os.path.isdir(full_name):
+            rmdirRecursive(full_name)
+        else:
+            # print "removing file", full_name
+            os.remove(full_name)
+    os.rmdir(dir)
+
 class ShellCommandPP(ProcessProtocol):
     debug = False
 
@@ -616,7 +637,7 @@
         if runtime.platformType != "posix":
             # if we're running on w32, use rmtree instead. It will block,
             # but hopefully it won't take too long.
-            shutil.rmtree(d, ignore_errors=1)
+            rmdirRecursive(d)
             return defer.succeed(0)
         command = ["rm", "-rf", d]
         c = ShellCommand(self.builder, command, self.builder.basedir,





More information about the Commits mailing list