Skip to main content

atomic_write

Function atomic_write 

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

Atomically write content to path. Uses a temp file in the same parent directory (avoids EXDEV on iCloud/Dropbox symlinks), fsyncs the file before persist, then fsyncs the parent directory for POSIX durability.

On Windows, tempfile::NamedTempFile::persist uses MoveFileExW with MOVEFILE_REPLACE_EXISTING | MOVEFILE_WRITE_THROUGH so the rename is atomic even when the target exists.

mode is the Unix file mode. Use 0o644 for normal config files and 0o600 for secrets (tokens, OAuth credentials). Ignored on Windows for now; ACL handling is a P8 follow-up.