Skip to main content

atomic_write_file

Function atomic_write_file 

Source
pub fn atomic_write_file<F>(path: &Path, write_fn: F) -> Result<()>
where F: FnOnce(&mut File) -> Result<()>,
Expand description

Write a file through a same-directory temporary file, then atomically rename it into place.

This avoids leaving critical index files truncated if a process is interrupted after opening with File::create but before the full payload is written.