Skip to main content

atomic_write_fsync

Function atomic_write_fsync 

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

Atomically write bytes to dst via a tmp file with full durability.

Order of operations (must not change):

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

tmp and dst MUST be in the same directory; otherwise rename is not atomic and the parent fsync won’t cover both entries.