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

Function maybe_delete_a_numbered_dir

src/_pytest/pathlib.py:279–304  ·  src/_pytest/pathlib.py::maybe_delete_a_numbered_dir

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 class="st">"""Remove a numbered directory if its lock can be obtained and it does
281 not seem to be in use.class="st">"""
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(fclass="st">"garbage-{uuid.uuid4()}")
289 path.rename(garbage)
290 rm_rf(garbage)
291 except OSError:
292 class="cm"># known races:
293 class="cm"># * other process did a cleanup at the same time
294 class="cm"># * deletable directory was found
295 class="cm"># * process cwd (Windows)
296 return
297 finally:
298 class="cm"># If we created the lock, ensure we remove it even if we failed
299 class="cm"># 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