Skip to main content

write_atomic

Function write_atomic 

Source
pub fn write_atomic<F>(path: &Path, write: F) -> Result<()>
where F: FnOnce(&mut File) -> Result<()>,
Expand description

Replaces path with the bytes write puts into a sibling temporary file.

The temporary file is .{name}.tmp-{pid}-{counter} in the destination’s folder, created with create_new (another name is tried when one exists). After write returns it is flushed with sync_all, closed and renamed over path; std’s rename replaces an existing destination on every platform. On any error the temporary file is removed and path keeps its previous content. The destination’s folder must already exist.