This commit is contained in:
Thomas Grainger 2023-04-06 18:00:17 +08:00 committed by GitHub
commit 5cf544e2ac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 6 deletions

View File

@ -0,0 +1 @@
Fixed an issue where dirs without S_IXUSR prevented pytest from cleaning up the temp dir

View File

@ -6,7 +6,7 @@ import itertools
import os import os
import shutil import shutil
import sys import sys
import uuid import tempfile
import warnings import warnings
from enum import Enum from enum import Enum
from errno import EBADF from errno import EBADF
@ -268,11 +268,8 @@ def maybe_delete_a_numbered_dir(path: Path) -> None:
lock_path = None lock_path = None
try: try:
lock_path = create_cleanup_lock(path) lock_path = create_cleanup_lock(path)
parent = path.parent with tempfile.TemporaryDirectory(prefix="garbage-", dir=path.parent) as garbage:
path.replace(garbage)
garbage = parent.joinpath(f"garbage-{uuid.uuid4()}")
path.rename(garbage)
rm_rf(garbage)
except OSError: except OSError:
# known races: # known races:
# * other process did a cleanup at the same time # * other process did a cleanup at the same time

View File

@ -377,6 +377,26 @@ def test_long_path_during_cleanup(tmp_path: Path) -> None:
assert not os.path.isdir(extended_path) assert not os.path.isdir(extended_path)
def test_permission_denied_during_cleanup(tmp_path) -> None:
"""
Ensure that deleting a numbered dir does not fail because of missing file
permission bits (#7940).
"""
path = tmp_path / "temp-1"
p = path / "ham" / "spam" / "eggs"
p.parent.mkdir(parents=True)
p.touch(mode=0)
for p in p.parents:
if p == path:
break
p.chmod(mode=0)
lock_path = get_lock_path(path)
maybe_delete_a_numbered_dir(path)
assert not path.exists()
assert not lock_path.is_file()
def test_get_extended_length_path_str() -> None: def test_get_extended_length_path_str() -> None:
assert get_extended_length_path_str(r"c:\foo") == r"\\?\c:\foo" assert get_extended_length_path_str(r"c:\foo") == r"\\?\c:\foo"
assert get_extended_length_path_str(r"\\share\foo") == r"\\?\UNC\share\foo" assert get_extended_length_path_str(r"\\share\foo") == r"\\?\UNC\share\foo"