Skip to main content

write_atomic

Function write_atomic 

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

Replaces path’s contents so that readers see the old or the new bytes, never a partial file: writes a temporary file beside it, flushes it to disk and renames it over path. An existing file keeps its permissions, and a new one gets create_mode (Unix, less the umask). A symbolic link keeps pointing at its target, which receives the contents. On error the file is unchanged.