fix up lock consideration argument
This commit is contained in:
parent
642cd86dd1
commit
2532dc1dbb
|
@ -120,7 +120,7 @@ def delete_a_numbered_dir(path):
|
||||||
shutil.rmtree(str(garbage))
|
shutil.rmtree(str(garbage))
|
||||||
|
|
||||||
|
|
||||||
def ensure_deletable(path, consider_lock_dead_after):
|
def ensure_deletable(path, consider_lock_dead_if_created_before):
|
||||||
lock = get_lock_path(path)
|
lock = get_lock_path(path)
|
||||||
if not lock.exists():
|
if not lock.exists():
|
||||||
return True
|
return True
|
||||||
|
@ -129,15 +129,15 @@ def ensure_deletable(path, consider_lock_dead_after):
|
||||||
except Exception:
|
except Exception:
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
if lock_time > consider_lock_dead_after:
|
if lock_time < consider_lock_dead_if_created_before:
|
||||||
lock.unlink()
|
lock.unlink()
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def try_cleanup(path, consider_lock_dead_after):
|
def try_cleanup(path, consider_lock_dead_if_created_before):
|
||||||
if ensure_deletable(path, consider_lock_dead_after):
|
if ensure_deletable(path, consider_lock_dead_if_created_before):
|
||||||
delete_a_numbered_dir(path)
|
delete_a_numbered_dir(path)
|
||||||
|
|
||||||
|
|
||||||
|
@ -152,12 +152,12 @@ def cleanup_candidates(root, prefix, keep):
|
||||||
yield path
|
yield path
|
||||||
|
|
||||||
|
|
||||||
def cleanup_numbered_dir(root, prefix, keep, consider_lock_dead_after):
|
def cleanup_numbered_dir(root, prefix, keep, consider_lock_dead_if_created_before):
|
||||||
for path in cleanup_candidates(root, prefix, keep):
|
for path in cleanup_candidates(root, prefix, keep):
|
||||||
try_cleanup(path, consider_lock_dead_after)
|
try_cleanup(path, consider_lock_dead_if_created_before)
|
||||||
known_garbage = list(root.glob("garbage-*"))
|
known_garbage = list(root.glob("garbage-*"))
|
||||||
for path in known_garbage:
|
for path in known_garbage:
|
||||||
try_cleanup(path, consider_lock_dead_after)
|
try_cleanup(path, consider_lock_dead_if_created_before)
|
||||||
|
|
||||||
|
|
||||||
def make_numbered_dir_with_cleanup(root, prefix, keep, lock_timeout):
|
def make_numbered_dir_with_cleanup(root, prefix, keep, lock_timeout):
|
||||||
|
@ -169,12 +169,12 @@ def make_numbered_dir_with_cleanup(root, prefix, keep, lock_timeout):
|
||||||
except Exception:
|
except Exception:
|
||||||
raise
|
raise
|
||||||
else:
|
else:
|
||||||
consider_lock_dead_after = p.stat().st_mtime + lock_timeout
|
consider_lock_dead_if_created_before = p.stat().st_mtime + lock_timeout
|
||||||
cleanup_numbered_dir(
|
cleanup_numbered_dir(
|
||||||
root=root,
|
root=root,
|
||||||
prefix=prefix,
|
prefix=prefix,
|
||||||
keep=keep,
|
keep=keep,
|
||||||
consider_lock_dead_after=consider_lock_dead_after,
|
consider_lock_dead_if_created_before=consider_lock_dead_if_created_before,
|
||||||
)
|
)
|
||||||
return p
|
return p
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue