Skip to main content

atomic_write

Function atomic_write 

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

Write data to path atomically: write to a per-write unique temp file, fsync, then rename onto the target.

The temp name carries a UUID so two concurrent writers of the same path do not collide on a fixed <path>.tmp. If any step fails the temp file is best-effort removed so unique temps don’t accumulate on error.

On Unix, the temp file is created with mode 0o600 atomically via OpenOptions::mode, so it is never world-readable even momentarily. On Windows no explicit permission change is applied; rely on the directory ACL to restrict access.