Periodic snapshot scan finds 0 files after prune_empty_dirs deletes and camera recreates date directory #121
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Shed Inside camera stopped being ingested after ~07:20 today. The periodic scan consistently reports "0 new, 0 already known" even though 816 jpg source files exist on disk.
What happens
Evidence
Diagnostic run inside the container confirms the stale cache:
Carpark avoids the bug because its motion-only snapshot schedule means the directory stays deleted between prunes — no stale cache to hit.
Root cause confirmed
The kernel dcache caches directory entries by (parent_ino, name). When prune_empty_dirs rmdirs the
2026-07-16/directory and the camera immediately recreates it under the same parent, the kernel returns the cached empty entry list for the new directory — even through a fresh file descriptor. This only manifests on cameras with frequent writes (Shed Inside does 1 snapshot/minute; Carpark only writes on motion, so the deleted directory stays gone).Plan
Fix the race, not the symptom. The correct fix is to stop deleting directories at a level where the dcache race can occur — specifically, never prune the date directory or channel directory from within the snapshot scan. Only prune leaf directories (
jpg/HH/MM/andjpg/HH/) that were actually emptied by the scan.Specific changes
_scan_snapshots_for_camerainlifespan.py: Replace the blanketprune_empty_dirs(cam.root)call with targeted pruning of only the hour and minute subdirectories that the scan emptied. Collect affected directories from the paths of deleted source files and rmdir them bottom-up.Ensure date-level cleanup still happens: Date and channel directories that become truly empty (no new files for the whole day) will be cleaned up by:
_run_cleanupwhich already prunes per-camera output dirs_run_cleanupthat handles empty camera source directories at a safe cadence (not racing with writes)Commit plan
:bug: Restrict snapshot-scan pruning to hour/minute directories below the date levelfix/issue-121-stale-dcache-after-prunemainFixed in release 0.10.1