Non-atomic cache writes in analyze.py can corrupt cache.json on interruption #3
Loading…
Add table
Add a link
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?
Problem
analyze.pywritescache.jsonusingPath.write_text()both in the periodic progress-save path (every 100 images) and in thefinallyblock:write_texttruncates the file and then writes the new content. If the process is killed, the machine loses power, or an exception is raised mid-write, the file is left partially written and contains invalid JSON. On the next run, the parser will fail and the fallbackcache = {}causes all previously analysed images to be re-processed from scratch (or, more subtly, silently discarded if the corrupted file is not detected).Location
analyze.py— inside thetryblock (periodic save, ~line 120):And the
finallyblock (~line 125):Risk
Loss of all accumulated analysis work if the long-running process is interrupted at an unlucky moment. On a large export with thousands of photos the analysis can take minutes; losing the cache mid-run is a significant reliability failure.
Suggested fix direction
Write to a temporary file in the same directory and then atomically rename it over the target:
os.replace/Path.replaceis atomic on POSIX when source and destination are on the same filesystem.Severity
minor
Found by
Automated audit by Claude Code