reth_fs_util

Function atomic_write_file

Source
pub fn atomic_write_file<F, E>(file_path: &Path, write_fn: F) -> Result<()>
where F: FnOnce(&mut File) -> Result<(), E>, E: Into<Box<dyn Error + Send + Sync>>,
Expand description

Writes atomically to file.

  1. Creates a temporary file with a .tmp extension in the same file directory.
  2. Writes content with write_fn.
  3. Fsyncs the temp file to disk.
  4. Renames the temp file to the target path.
  5. Fsyncs the file directory.

Atomic writes are hard: