Use the appropriate function to remove files in the stage directory (#29690)
We shouldn't be using "remove_linked_tree" to remove the lock file, since that function expects to receive a directory path as an argument. Also, as a further measure to avoid regression, this commit restores the "ignore_errors=True" argument on linux and adds a unit test checking that "remove_linked_tree" doesn't change file permissions as a side effect of a failure to remove.
This commit is contained in:

committed by
GitHub

parent
4702b49094
commit
048a0de35b
@@ -27,7 +27,7 @@
|
||||
from spack.util.executable import Executable
|
||||
from spack.util.path import path_to_os_path, system_path_filter
|
||||
|
||||
is_windows = _platform == 'win32'
|
||||
is_windows = _platform == 'win32'
|
||||
|
||||
if not is_windows:
|
||||
import grp
|
||||
@@ -1201,12 +1201,16 @@ def onerror(func, path, exe_info):
|
||||
tty.warn(e)
|
||||
pass
|
||||
|
||||
kwargs = {'ignore_errors': True}
|
||||
if is_windows:
|
||||
kwargs = {'onerror': onerror}
|
||||
|
||||
if os.path.exists(path):
|
||||
if os.path.islink(path):
|
||||
shutil.rmtree(os.path.realpath(path), onerror=onerror)
|
||||
shutil.rmtree(os.path.realpath(path), **kwargs)
|
||||
os.unlink(path)
|
||||
else:
|
||||
shutil.rmtree(path, onerror=onerror)
|
||||
shutil.rmtree(path, **kwargs)
|
||||
|
||||
|
||||
@contextmanager
|
||||
|
Reference in New Issue
Block a user