File tree Expand file tree Collapse file tree 4 files changed +26
-0
lines changed Expand file tree Collapse file tree 4 files changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -265,6 +265,7 @@ Tom Dalton
265265Tom Viner
266266Tomáš Gavenčiak
267267Tomer Keren
268+ Tor Colvin
268269Trevor Bekolay
269270Tyler Goodlet
270271Tzu-ping Chung
Original file line number Diff line number Diff line change 1+ Support deleting paths longer than 260 characters on windows created inside tmpdir.
Original file line number Diff line number Diff line change @@ -99,11 +99,23 @@ def chmod_rw(p: str) -> None:
9999 func (path )
100100 return True
101101
102+ def create_long_path (path : Path ) -> Path :
103+ """Construct a path which will work on Windows if greater
104+ than 260 characters. Resolves into a absolute path which
105+ bypasses the typical MAX_PATH limitation:
106+ https://docs.microsoft.com/en-us/windows/win32/fileio/naming-a-file#maximum-path-length-limitation"""
107+ if sys .platform .startswith ("win32" ):
108+ path = path .resolve ()
109+ # for the API
110+ if not str (path ).startswith (r"\\ ?\" ):
111+ path = Path (r"\\ ?\" + str (path ))
112+ return path
102113
103114def rm_rf (path : Path ) -> None :
104115 """Remove the path contents recursively, even if some elements
105116 are read-only.
106117 """
118+ path = create_long_path (path )
107119 onerror = partial (on_rm_rf_error , start_path = path )
108120 shutil .rmtree (str (path ), onerror = onerror )
109121
Original file line number Diff line number Diff line change @@ -89,3 +89,15 @@ def renamed_failed(*args):
8989 lock_path = get_lock_path (path )
9090 maybe_delete_a_numbered_dir (path )
9191 assert not lock_path .is_file ()
92+
93+ def test_long_path_during_cleanup (tmp_path ):
94+ """Ensure that deleting long path works (particularly on Windows (#6775))."""
95+ path = tmp_path / ("a" * 200 )
96+ if sys .platform == "win32" :
97+ dirname = path .resolve ()
98+ dirname = r"\\ ?\" + str (path )
99+ os .mkdir (dirname )
100+
101+ lock_path = get_lock_path (path )
102+ maybe_delete_a_numbered_dir (path )
103+ assert not lock_path .is_file ()
You can’t perform that action at this time.
0 commit comments