Skip to main content

write_atomic

Function write_atomic 

Source
pub fn write_atomic(path: &Path, data: &[u8]) -> Result<()>
Expand description

Replace path with data atomically.

The data goes to a uniquely named temp file beside path, gets a best-effort fsync, and is then renamed over path. Readers see the old file or the new file, never a mix. Concurrent writers each move their own complete payload into place, and the last rename wins. A failed write removes its temp file.

ยงErrors

Returns the IO error when path has no parent directory or file name, or when the temp file cannot be created, written, or renamed into place.