Skip to main content

Module atomic

Module atomic 

Source
Expand description

Crash-safe file publication: write to a fresh sibling, sync it, rename it over the destination, sync the directory.

The temp file is created with create_new under an unpredictable name and mode 0600, so a symlink or file planted at a guessable path is never followed or truncated. One helper for the revocation log (amesh) and the Seen record (crate::RevocationGuard), so there is a single copy of the dance.

Functionsยง

atomic_write
Replace dest with bytes atomically and durably: temp file, sync_all, rename, then sync_all on the directory (Unix). On failure the temp file is removed and dest is untouched.
create_tmp
A fresh temp file beside dest: create_new (never follows or truncates an existing path) under an unpredictable name, mode 0600 on Unix.