Skip to main content

atomic_write

Function atomic_write 

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

Atomically write bytes to path.

Strategy: write to <path>.<rand>.tmp in the same directory, fsync the file, then rename it onto the destination. The rename is atomic on every supported platform (POSIX rename is atomic; Windows MoveFileEx with MOVEFILE_REPLACE_EXISTING behaves likewise).

ยงErrors

Returns the underlying I/O error if any step fails. The temporary file is removed before returning the error to avoid leaking droppings.