Skip to main content

Module atomic_file

Module atomic_file 

Source
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 path with contents.
write_atomic_private
Atomically replace path with contents, 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.