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.
This commit is contained in:
parent
61b0f4f84d
commit
cc7a29c55a
@ -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)
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user