Skip to main content

Module atomic

Module atomic 

Source
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_temps removes 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 path is a temp file write_atomic made: not a record, whatever its .json ending says.
rename_atomic
Atomic rename. Used for retire/unretire (same-directory tree).
sweep_stale_temps
Remove the temp files in dir that an interrupted write left behind: only files named like write_atomic’s, and only those last changed more than min_age ago. 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 bytes to path atomically: 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).