changeset 40471:bb5d74a35477 stable

run-tests: fix permission to clean up unreadable directories I found many hgtests.* directories left in $TMPDIR, which couldn't be deleted because test-ssh-repoerror.t created some directories with a-rx mode.
author Yuya Nishihara <yuya@tcha.org>
date Mon, 17 Dec 2018 20:46:09 +0900
parents 328557af18eb
children 03f7d0822ec1
files tests/run-tests.py
diffstat 1 files changed, 18 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- 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: