File tree Expand file tree Collapse file tree 3 files changed +27
-6
lines changed
Expand file tree Collapse file tree 3 files changed +27
-6
lines changed Original file line number Diff line number Diff line change 1+ Fixed an issue where dirs without S_IXUSR prevented pytest from cleaning up the temp dir
Original file line number Diff line number Diff line change 66import os
77import shutil
88import sys
9- import uuid
9+ import tempfile
1010import warnings
1111from enum import Enum
1212from functools import partial
@@ -254,11 +254,11 @@ def maybe_delete_a_numbered_dir(path: Path) -> None:
254254 lock_path = None
255255 try :
256256 lock_path = create_cleanup_lock (path )
257- parent = path . parent
258-
259- garbage = parent . joinpath ( f" garbage- { uuid . uuid4 () } " )
260- path . rename ( garbage )
261- rm_rf (garbage )
257+ with tempfile . TemporaryDirectory (
258+ prefix = "garbage-" , dir = os . fsdecode ( path . parent )
259+ ) as garbage :
260+ print ( f" { path = } { garbage = } " )
261+ path . replace (garbage )
262262 except OSError :
263263 # known races:
264264 # * other process did a cleanup at the same time
Original file line number Diff line number Diff line change @@ -351,6 +351,26 @@ def test_long_path_during_cleanup(tmp_path):
351351 assert not os .path .isdir (extended_path )
352352
353353
354+ def test_permission_denied_during_cleanup (tmp_path ):
355+ """
356+ Ensure that deleting a numbered dir does not fail because of missing file
357+ permission bits (#7940).
358+ """
359+ path = tmp_path / "temp-1"
360+ p = path / "ham" / "spam" / "eggs"
361+ p .parent .mkdir (parents = True )
362+ p .touch (mode = 0 )
363+ for p in p .parents :
364+ if p == path :
365+ break
366+ p .chmod (mode = 0 )
367+
368+ lock_path = get_lock_path (path )
369+ maybe_delete_a_numbered_dir (path )
370+ assert not path .exists ()
371+ assert not lock_path .is_file ()
372+
373+
354374def test_get_extended_length_path_str ():
355375 assert get_extended_length_path_str (r"c:\foo" ) == r"\\?\c:\foo"
356376 assert get_extended_length_path_str (r"\\share\foo" ) == r"\\?\UNC\share\foo"
You can’t perform that action at this time.
0 commit comments