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):
- Create / truncate the tmp file and write
bytes. sync_data()on the tmp file — forces file data pages to stable storage.rename(tmp, dst)— atomic on POSIX filesystems.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.