pub fn write_atomic(path: &Path, data: &[u8], mode: u32) -> Result<()>Expand description
Atomically replace path with data at file mode mode.
Creates the parent directory, then writes a sibling temp file named
<name>.tmp-<8 random hex> opened create_new with mode (so two
concurrent writers, threads or processes, never share a temp file), sets
the exact mode regardless of umask, fsyncs it, renames it over path, and
fsyncs the directory so the rename itself survives a power cut. On any
error the temp file is removed.