Skip to main content

atomic_write_fsync

Function atomic_write_fsync 

Source
pub fn atomic_write_fsync(dir: &Path, name: &str, bytes: &[u8]) -> Result<()>
Expand description

Atomically write bytes to dir/name via a dir/name.tmp staging file with full durability.

Order of operations (must not change):

  1. Create / truncate the tmp file and write bytes.
  2. sync_data() on the tmp file — forces file data pages to stable storage.
  3. rename(tmp, dst) — atomic on POSIX filesystems.
  4. fsync_directory(dir) — forces the directory entry durable so the new name survives power loss.

name must be one plain path component; anything else returns InvalidInput before a byte is written. Both paths are built here from dir, so the rename stays inside one filesystem directory and the single parent fsync covers both entries.