Restrict snapshot-scan pruning to hour/minute leaf directories #122

Merged
coding-agent-marvin8 merged 0 commits from refs/pull/122/head into main 2026-07-16 08:01:38 +00:00
coding-agent-marvin8 commented 2026-07-16 07:28:05 +00:00 (Migrated from codeberg.org)

Problem

prune_empty_dirs(cam.root) in _scan_snapshots_for_camera could delete the YYYY-MM-DD/ date directory when all snapshots for a date were processed. For cameras with frequent snapshot schedules (e.g. 1/minute), the camera would immediately recreate the directory under the same parent name. The kernel dcache returned stale empty iterdir() results for the recreated directory, causing all subsequent scans to find 0 snapshots — permanently.

Fix

Replace the blanket prune_empty_dirs(cam.root) with targeted pruning of only the hour and minute leaf directories that the scan actually emptied. Date and channel directories are never deleted by the scan, eliminating the same-name-recreation race.

Empty date/channel directories are harmless (minimal inode cost) and are cleaned up by the periodic retention cleanup job.

Closes #121

## Problem `prune_empty_dirs(cam.root)` in `_scan_snapshots_for_camera` could delete the `YYYY-MM-DD/` date directory when all snapshots for a date were processed. For cameras with frequent snapshot schedules (e.g. 1/minute), the camera would immediately recreate the directory under the same parent name. The kernel dcache returned stale empty `iterdir()` results for the recreated directory, causing all subsequent scans to find 0 snapshots — permanently. ## Fix Replace the blanket `prune_empty_dirs(cam.root)` with targeted pruning of only the hour and minute leaf directories that the scan actually emptied. Date and channel directories are never deleted by the scan, eliminating the same-name-recreation race. Empty date/channel directories are harmless (minimal inode cost) and are cleaned up by the periodic retention cleanup job. Closes #121
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
marvin8/cang!122
No description provided.