From 64775c0fd335c53604a295426d9d6ab4aae24cf8 Mon Sep 17 00:00:00 2001 From: Xavier Claessens Date: Thu, 25 Mar 2021 11:25:37 -0400 Subject: [PATCH] windows_proof_rmtree: Also retry os.chmod() part It looks like when Windows media scanner holds files we can't change their permission neither. --- mesonbuild/mesonlib/universal.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/mesonbuild/mesonlib/universal.py b/mesonbuild/mesonlib/universal.py index b0b987e3f..45c3e5c0c 100644 --- a/mesonbuild/mesonlib/universal.py +++ b/mesonbuild/mesonlib/universal.py @@ -1530,9 +1530,16 @@ def windows_proof_rmtree(f: str) -> None: # 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) + writable = False for d in delays: + try: + # Start by making the tree writable. + if not writable: + _make_tree_writable(f) + writable = True + except PermissionError: + time.sleep(d) + continue try: shutil.rmtree(f) return