MCPcopy
hub / github.com/pytest-dev/pytest / maybe_delete_a_numbered_dir

Function maybe_delete_a_numbered_dir

src/_pytest/pathlib.py:279–304  ·  view source on GitHub ↗

Remove a numbered directory if its lock can be obtained and it does not seem to be in use.

(path: Path)

Source from the content-addressed store, hash-verified

277
278
279def maybe_delete_a_numbered_dir(path: Path) -> None:
280 """Remove a numbered directory if its lock can be obtained and it does
281 not seem to be in use."""
282 path = ensure_extended_length_path(path)
283 lock_path = None
284 try:
285 lock_path = create_cleanup_lock(path)
286 parent = path.parent
287
288 garbage = parent.joinpath(f"garbage-{uuid.uuid4()}")
289 path.rename(garbage)
290 rm_rf(garbage)
291 except OSError:
292 # known races:
293 # * other process did a cleanup at the same time
294 # * deletable directory was found
295 # * process cwd (Windows)
296 return
297 finally:
298 # If we created the lock, ensure we remove it even if we failed
299 # to properly remove the numbered dir.
300 if lock_path is not None:
301 try:
302 lock_path.unlink()
303 except OSError:
304 pass
305
306
307def ensure_deletable(path: Path, consider_lock_dead_if_created_before: float) -> bool:

Callers 4

try_cleanupFunction · 0.85

Calls 4

create_cleanup_lockFunction · 0.85
rm_rfFunction · 0.85
renameMethod · 0.80

Used in the wild real call sites across dependent graphs

searching dependent graphs…