Expand description
Atomic file write + rename helpers. All registry mutations route through these so readers never observe a half-written file.
Constants§
- STALE_
TEMP_ AGE - How old a leftover temp file must be before
sweep_stale_tempsremoves it. A write holds its temp file for milliseconds (a write, an fsync, a rename), so a file this old belongs to a write that was cut short, never to one in flight in another process sharing the folder.
Functions§
- is_
temp_ file - Whether
pathis a temp filewrite_atomicmade: not a record, whatever its.jsonending says. - rename_
atomic - Atomic rename. Used for retire/unretire (same-directory tree).
- sweep_
stale_ temps - Remove the temp files in
dirthat an interrupted write left behind: only files named likewrite_atomic’s, and only those last changed more thanmin_ageago. Returns how many were removed. A folder that can’t be read or a file that can’t be removed is logged and left, never an error: this runs at start and must not stop it. - write_
atomic - Write
bytestopathatomically: sibling temp file → fsync → rename over the target. Rename is atomic on every supported filesystem when source and destination live on the same volume, which is guaranteed here (sibling temp).