[zorg] r329637 - [annotated_builder] try harder to clean build directories

Bob Haarman via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 9 16:06:15 PDT 2018


Author: inglorion
Date: Mon Apr  9 16:06:15 2018
New Revision: 329637

URL: http://llvm.org/viewvc/llvm-project?rev=329637&view=rev
Log:
[annotated_builder] try harder to clean build directories

Summary:
llvm-objcopy has a test that creates a non-writable file. This file
is causing the clang-with-thin-lto-windows bot to fail because it
cannot clean its build directory. This change makes util.clean_dir()
try harder to remove directory trees, which should allow the bot
to succeed.

Reviewers: gkistanova, rnk, zturner, amccarth

Reviewed By: amccarth

Subscribers: inglorion, amccarth, mehdi_amini, llvm-commits

Differential Revision: https://reviews.llvm.org/D45345

Modified:
    zorg/trunk/zorg/buildbot/builders/annotated/util.py

Modified: zorg/trunk/zorg/buildbot/builders/annotated/util.py
URL: http://llvm.org/viewvc/llvm-project/zorg/trunk/zorg/buildbot/builders/annotated/util.py?rev=329637&r1=329636&r2=329637&view=diff
==============================================================================
--- zorg/trunk/zorg/buildbot/builders/annotated/util.py (original)
+++ zorg/trunk/zorg/buildbot/builders/annotated/util.py Mon Apr  9 16:06:15 2018
@@ -10,11 +10,11 @@ import sys
 
 def clean_dir(path):
     """
-    Remove directory path if it exists and create a new, empty directory
-    in its place.
+    Removes directory at path (and all its subdirectories) if it exists,
+    and creates an empty directory in its place.
     """
     try:
-        shutil.rmtree(path)
+        rmtree(path)
     except OSError as e:
         if e.errno != errno.ENOENT:
             raise
@@ -58,6 +58,24 @@ def mkdirp(path):
             raise
 
 
+def rmtree(path):
+    """
+    Remove directory path and all its subdirectories. This differs from
+    shutil.rmtree() in that it tries to adjust permissions so that deletion
+    will succeed.
+    """
+    # Some files will not be deletable, so we set permissions that allow
+    # deletion before we try deleting files.
+    for root, dirs, files in os.walk(path):
+        os.chmod(root, 0o755)
+        for f in files:
+            p = os.path.join(root, f)
+            os.chmod(p, 0o644)
+            os.unlink(p)
+    # At this point, we should have a tree of deletable directories.
+    shutil.rmtree(path)
+
+
 def safe_pjoin(dirname, *args):
     """
     Join path components with os.path.join, skipping the first component




More information about the llvm-commits mailing list