Expand description
Atomic file replacement: write a temp file in the destination directory, sync it, rename it into place, sync the parent directory. Readers see the old contents or the new, never a torn write, and a crash between any two steps leaves the destination untouched.
Ported from Oak cli/src/atomic_file.rs (v0.102.1, commit 8de9515,
Apache-2.0); error type changed to std::io::Error.
Functionsยง
- write_
atomic - Atomically replace
pathwithcontents. - write_
atomic_ private - Atomically replace
pathwithcontents, creating the replacement file with owner-only permissions (0600) before any contents are written on Unix. For secrets: unlike write-then-chmod there is no window where the bytes exist world-readable.