Skip to main content

atomic_write

Function atomic_write 

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

Write bytes to path atomically.

Implementation: write to <path>.tmp, then rename into place. If the rename fails the orphan .tmp is unlinked so we don’t leak temp files across crashes. The caller is responsible for ensuring the parent directory exists.

§Errors

Returns the underlying std::io::Error from either the temp-file write or the final rename. On rename failure the temp file is removed best-effort before returning — the original error is surfaced regardless, since the cleanup outcome is rarely actionable.