File tree Expand file tree Collapse file tree 3 files changed +20
-5
lines changed Expand file tree Collapse file tree 3 files changed +20
-5
lines changed Original file line number Diff line number Diff line change
1
+ :fixture: `tmpdir ` and :fixture: `tmp_path ` no longer raise an error if the lock to check for
2
+ stale temporary directories is not accessible.
Original file line number Diff line number Diff line change @@ -286,12 +286,17 @@ def maybe_delete_a_numbered_dir(path: Path) -> None:
286
286
287
287
288
288
def ensure_deletable (path : Path , consider_lock_dead_if_created_before : float ) -> bool :
289
- """checks if a lock exists and breaks it if its considered dead """
289
+ """checks if `path` is deletable based on whether the lock file is expired """
290
290
if path .is_symlink ():
291
291
return False
292
292
lock = get_lock_path (path )
293
- if not lock .exists ():
294
- return True
293
+ try :
294
+ if not lock .is_file ():
295
+ return True
296
+ except OSError :
297
+ # we might not have access to the lock file at all, in this case assume
298
+ # we don't have access to the entire directory (#7491).
299
+ return False
295
300
try :
296
301
lock_time = lock .stat ().st_mtime
297
302
except Exception :
Original file line number Diff line number Diff line change @@ -358,17 +358,25 @@ def test_get_extended_length_path_str():
358
358
359
359
360
360
def test_suppress_error_removing_lock (tmp_path ):
361
- """ensure_deletable should not raise an exception if the lock file cannot be removed (#5456)"""
361
+ """ensure_deletable should be resilient if lock file cannot be removed (#5456, #7491 )"""
362
362
path = tmp_path / "dir"
363
363
path .mkdir ()
364
364
lock = get_lock_path (path )
365
365
lock .touch ()
366
366
mtime = lock .stat ().st_mtime
367
367
368
- with unittest .mock .patch .object (Path , "unlink" , side_effect = OSError ):
368
+ with unittest .mock .patch .object (Path , "unlink" , side_effect = OSError ) as m :
369
369
assert not ensure_deletable (
370
370
path , consider_lock_dead_if_created_before = mtime + 30
371
371
)
372
+ assert m .call_count == 1
373
+ assert lock .is_file ()
374
+
375
+ with unittest .mock .patch .object (Path , "is_file" , side_effect = OSError ) as m :
376
+ assert not ensure_deletable (
377
+ path , consider_lock_dead_if_created_before = mtime + 30
378
+ )
379
+ assert m .call_count == 1
372
380
assert lock .is_file ()
373
381
374
382
# check now that we can remove the lock file in normal circumstances
You can’t perform that action at this time.
0 commit comments