Skip to main content

write_atomic

Function write_atomic 

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

Durable, atomic replacement of path with bytes (design §S5).

The single consolidated publication primitive for state descriptors, immutable generation snapshots, and configured bundle paths: write a fresh temporary file in the destination directory, fsync it, rename it over the target, then fsync the directory so the rename itself is durable. Readers see either the complete old or the complete new bytes.

A failure before the rename leaves the previous contents untouched (the temporary file is removed). A directory-fsync failure after the rename is reported as CoreError::DurabilityUncertain: the replacement may or may not survive a crash, and callers must neither claim rollback nor completion.