diff options
author | James Smillie <83249606+jamessmillie@users.noreply.github.com> | 2024-08-16 12:16:13 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-08-16 11:16:13 -0700 |
commit | cc7a29c55a9fcd9fb15aa6ec37e045c03e6e77d9 (patch) | |
tree | ed03869fa17365053a196eca71ce414ce9e2d096 | |
parent | 61b0f4f84dda320fd93d287f50e773b2037e9ca3 (diff) | |
download | spack-cc7a29c55a9fcd9fb15aa6ec37e045c03e6e77d9.tar.gz spack-cc7a29c55a9fcd9fb15aa6ec37e045c03e6e77d9.tar.bz2 spack-cc7a29c55a9fcd9fb15aa6ec37e045c03e6e77d9.tar.xz spack-cc7a29c55a9fcd9fb15aa6ec37e045c03e6e77d9.zip |
Windows: fix stage cleaning for long paths (#45786)
Paths over 260 characters in length are not handled by `shutil.rmtree`
unless they use the extended-length path syntax (using a prefix of
"\\?\").
This fixes an issue where stage cleaning fails when paths in a stage
exceed the normal 260-character limit.
This indicates that other parts of the codebase should be examined/
refactored to handle long paths.
-rw-r--r-- | lib/spack/llnl/util/filesystem.py | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/lib/spack/llnl/util/filesystem.py b/lib/spack/llnl/util/filesystem.py index 6b2ba50c0e..308c6154e1 100644 --- a/lib/spack/llnl/util/filesystem.py +++ b/lib/spack/llnl/util/filesystem.py @@ -1624,6 +1624,12 @@ def remove_linked_tree(path): shutil.rmtree(os.path.realpath(path), **kwargs) os.unlink(path) else: + if sys.platform == "win32": + # Adding this prefix allows shutil to remove long paths on windows + # https://learn.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation?tabs=registry + long_path_pfx = "\\\\?\\" + if not path.startswith(long_path_pfx): + path = long_path_pfx + path shutil.rmtree(path, **kwargs) |