tests/run-tests.py
branchstable
changeset 40987 bb5d74a35477
parent 40270 8783710b1d58
child 40989 e10adebf8176
--- a/tests/run-tests.py	Sun Dec 16 17:08:46 2018 +0900
+++ b/tests/run-tests.py	Mon Dec 17 20:46:09 2018 +0900
@@ -586,6 +586,17 @@
     shutil.copy(src, dst)
     os.remove(src)
 
+def makecleanable(path):
+    """Try to fix directory permission recursively so that the entire tree
+    can be deleted"""
+    for dirpath, dirnames, _filenames in os.walk(path, topdown=True):
+        for d in dirnames:
+            p = os.path.join(dirpath, d)
+            try:
+                os.chmod(p, os.stat(p).st_mode & 0o777 | 0o700)  # chmod u+rwx
+            except OSError:
+                pass
+
 _unified_diff = difflib.unified_diff
 if PYTHON3:
     import functools
@@ -952,7 +963,13 @@
                 (self._testtmp.decode('utf-8'),
                  self._threadtmp.decode('utf-8')))
         else:
-            shutil.rmtree(self._testtmp, True)
+            try:
+                shutil.rmtree(self._testtmp)
+            except OSError:
+                # unreadable directory may be left in $TESTTMP; fix permission
+                # and try again
+                makecleanable(self._testtmp)
+                shutil.rmtree(self._testtmp, True)
             shutil.rmtree(self._threadtmp, True)
 
         if self._usechg: