pub fn atomic_write_bytes(target_path: &Path, bytes: &[u8]) -> Result<()>Expand description
Write bytes to target_path atomically.
§Errors
Returns Err if:
target_pathexists and is a symlink (we will not follow or replace symlinks).- The parent directory of
target_pathis itself a symlink (detected after canonicalization). - The parent directory does not exist (caller’s responsibility).
- Any I/O error occurs during tempfile creation, writing, syncing, or renaming.
On error the target file is left unmodified. Any tempfile created during the operation is cleaned up before returning the error.
§Platform notes
- Unix:
fsync(2)is called on both the tempfile and, after the rename, on the parent directory file descriptor. This makes the rename durable against power loss. - Windows / other non-Unix: Parent-directory fsync is a no-op. The tempfile is still written and renamed atomically via the OS rename call.