Refactor the process of deleting dead symlink
This commit is contained in:
parent
dc11283794
commit
b04bbb1dcb
|
@ -335,6 +335,13 @@ def cleanup_candidates(root: Path, prefix: str, keep: int) -> Iterator[Path]:
|
||||||
yield path
|
yield path
|
||||||
|
|
||||||
|
|
||||||
|
def cleanup_dead_symlink(root: Path):
|
||||||
|
for left_dir in root.iterdir():
|
||||||
|
if left_dir.is_symlink():
|
||||||
|
if not left_dir.resolve().exists():
|
||||||
|
left_dir.unlink()
|
||||||
|
|
||||||
|
|
||||||
def cleanup_numbered_dir(
|
def cleanup_numbered_dir(
|
||||||
root: Path, prefix: str, keep: int, consider_lock_dead_if_created_before: float
|
root: Path, prefix: str, keep: int, consider_lock_dead_if_created_before: float
|
||||||
) -> None:
|
) -> None:
|
||||||
|
@ -346,11 +353,7 @@ def cleanup_numbered_dir(
|
||||||
for path in root.glob("garbage-*"):
|
for path in root.glob("garbage-*"):
|
||||||
try_cleanup(path, consider_lock_dead_if_created_before)
|
try_cleanup(path, consider_lock_dead_if_created_before)
|
||||||
|
|
||||||
# remove dead symlink
|
cleanup_dead_symlink(root)
|
||||||
for left_dir in root.iterdir():
|
|
||||||
if left_dir.is_symlink():
|
|
||||||
if not left_dir.resolve().exists():
|
|
||||||
left_dir.unlink()
|
|
||||||
|
|
||||||
|
|
||||||
def make_numbered_dir_with_cleanup(
|
def make_numbered_dir_with_cleanup(
|
||||||
|
|
|
@ -23,6 +23,7 @@ from .pathlib import LOCK_TIMEOUT
|
||||||
from .pathlib import make_numbered_dir
|
from .pathlib import make_numbered_dir
|
||||||
from .pathlib import make_numbered_dir_with_cleanup
|
from .pathlib import make_numbered_dir_with_cleanup
|
||||||
from .pathlib import rm_rf
|
from .pathlib import rm_rf
|
||||||
|
from .pathlib import cleanup_dead_symlink
|
||||||
from _pytest.compat import final
|
from _pytest.compat import final
|
||||||
from _pytest.config import Config
|
from _pytest.config import Config
|
||||||
from _pytest.config import ExitCode
|
from _pytest.config import ExitCode
|
||||||
|
@ -281,10 +282,7 @@ def tmp_path(
|
||||||
basetemp = tmp_path_factory._basetemp
|
basetemp = tmp_path_factory._basetemp
|
||||||
if basetemp is None:
|
if basetemp is None:
|
||||||
return
|
return
|
||||||
for left_dir in basetemp.iterdir():
|
cleanup_dead_symlink(basetemp)
|
||||||
if left_dir.is_symlink():
|
|
||||||
if not left_dir.resolve().exists():
|
|
||||||
left_dir.unlink()
|
|
||||||
|
|
||||||
|
|
||||||
def pytest_sessionfinish(session, exitstatus: Union[int, ExitCode]):
|
def pytest_sessionfinish(session, exitstatus: Union[int, ExitCode]):
|
||||||
|
|
Loading…
Reference in New Issue