summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFilipe Brandenburger <filbranden@google.com>2018-05-31 10:16:54 -0700
committerNirbheek Chauhan <nirbheek.chauhan@gmail.com>2018-06-02 04:50:32 +0000
commitdf2f6a71e7c32a477c141808d2dfdd49df8021fc (patch)
tree7724a99bbe6242433fbffcde08b78a6c7568682c
parent05c43cdcd19db98d53d5c9f1b50028d881471c2f (diff)
downloadmeson-df2f6a71e7c32a477c141808d2dfdd49df8021fc.tar.gz
Make windows_proof_rmtree resilient to read-only files
Start the process by traversing the tree and adding the S_IWRITE and S_IREAD bits to the file's mode (which are also preserved on Windows.) This fixes windows_proof_rmtree's inability to remove read-only files, which was uncovered in testing the new `install_mode` feature. Tested: ./run_tests.py passes on Linux, appveyor CI on Windows passes.
-rw-r--r--mesonbuild/mesonlib.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/mesonbuild/mesonlib.py b/mesonbuild/mesonlib.py
index eaa5359ec..d7000410c 100644
--- a/mesonbuild/mesonlib.py
+++ b/mesonbuild/mesonlib.py
@@ -975,12 +975,25 @@ def get_filenames_templates_dict(inputs, outputs):
return values
+def _make_tree_writable(topdir):
+ # Ensure all files and directories under topdir are writable
+ # (and readable) by owner.
+ for d, _, files in os.walk(topdir):
+ os.chmod(d, os.stat(d).st_mode | stat.S_IWRITE | stat.S_IREAD)
+ for fname in files:
+ fpath = os.path.join(d, fname)
+ if os.path.isfile(fpath):
+ os.chmod(fpath, os.stat(fpath).st_mode | stat.S_IWRITE | stat.S_IREAD)
+
+
def windows_proof_rmtree(f):
# On Windows if anyone is holding a file open you can't
# delete it. As an example an anti virus scanner might
# be scanning files you are trying to delete. The only
# way to fix this is to try again and again.
delays = [0.1, 0.1, 0.2, 0.2, 0.2, 0.5, 0.5, 1, 1, 1, 1, 2]
+ # Start by making the tree wriable.
+ _make_tree_writable(f)
for d in delays:
try:
shutil.rmtree(f)