diff options
Diffstat (limited to 'lib/spack/llnl/util/filesystem.py')
-rw-r--r-- | lib/spack/llnl/util/filesystem.py | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/lib/spack/llnl/util/filesystem.py b/lib/spack/llnl/util/filesystem.py index 9f46b275b2..22ca97c347 100644 --- a/lib/spack/llnl/util/filesystem.py +++ b/lib/spack/llnl/util/filesystem.py @@ -1094,12 +1094,23 @@ def remove_linked_tree(path): Parameters: path (str): Directory to be removed """ + # On windows, cleaning a Git stage can be an issue + # as git leaves readonly files that Python handles + # poorly on Windows. Remove readonly status and try again + def onerror(func, path, exe_info): + os.chmod(path, stat.S_IWUSR) + try: + func(path) + except Exception as e: + tty.warn(e) + pass + if os.path.exists(path): if os.path.islink(path): - shutil.rmtree(os.path.realpath(path), True) + shutil.rmtree(os.path.realpath(path), onerror=onerror) os.unlink(path) else: - shutil.rmtree(path, True) + shutil.rmtree(path, onerror=onerror) @contextmanager @@ -1237,9 +1248,6 @@ def find(root, files, recursive=True): return _find_non_recursive(root, files) -# here and in _find_non_recursive below we only take the first -# index to check for system path safety as glob handles this -# w.r.t. search_files @system_path_filter def _find_recursive(root, search_files): |