make state_skipped harsher

This commit is contained in:
2026-02-23 10:45:55 -07:00
parent b173331155
commit 54d039644e
3 changed files with 363 additions and 39 deletions
+4 -38
View File
@@ -1124,44 +1124,10 @@ def run_zip(requested_workers: int | None, *, verbose: bool) -> int:
if not is_archive_present(zip_path) and old_stored_state is not None:
stored_state = old_stored_state
# If .7z archive exists and we have stored state, do quick check before computing full state
if is_archive_present(zip_path) and stored_state is not None:
# Quick check: if directory mtime is older than archive, likely unchanged
# But first verify that all files in stored state still exist (catches deletions)
try:
# Quick check: verify stored files still exist (catches file deletions)
stored_files_exist = True
for entry in stored_state.get("files", []):
# Skip Thumbs.db entries (they're filtered out anyway)
if Path(entry.get("path", "")).name.lower() == "thumbs.db":
continue
file_path = seq_dir / entry["path"]
if not file_path.exists():
stored_files_exist = False
break
# Only do mtime check if all stored files still exist
if stored_files_exist:
dir_mtime = seq_dir.stat().st_mtime_ns
archive_file = zip_path if zip_path.exists() else (zip_path.parent / (zip_path.name + ".001"))
archive_mtime = archive_file.stat().st_mtime_ns
# If directory wasn't modified since archive was created, skip state computation
if dir_mtime <= archive_mtime:
quick_skipped += 1
if quick_skipped <= 5:
log("scan", f"Skipping {rel} (unchanged since archive)")
# Still need to check for old .zip cleanup (we have .7z, so .zip is obsolete)
if old_zip_path and old_zip_path.exists():
old_zip_path.unlink(missing_ok=True)
old_state_path = state_path_for(old_zip_path)
if old_state_path.exists():
old_state_path.unlink(missing_ok=True)
continue
except OSError:
# If stat fails, fall through to full state computation
pass
# Compute current state only if we need to
# Always compute full state and compare; directory mtime is unreliable (e.g. on Windows
# it often doesn't update when files inside change), so we no longer quick-skip on mtime.
# Compute current state
seq_state = compute_state(seq_dir)
if not seq_state["files"]:
empty_dirs += 1