Skip to main content

save_bytes_atomic

Function save_bytes_atomic 

Source
pub fn save_bytes_atomic(path: &Path, bytes: &[u8]) -> Result<(), Error>
Expand description

Atomically replace path with bytes, forcing mode 0o600.

Creates the parent directory if needed, stages the write in a sibling temporary file (mode 0o600 on Unix), fsyncs it, and renames it over the target. On any failure the staging file is removed and the previous contents of path are left untouched.

For files that belong to the user rather than to par-term, use save_bytes_atomic_preserving_mode instead.

ยงErrors

Returns an error if the parent directory cannot be created, if the staging file cannot be written, fsynced or permission-restricted, or if the rename fails.