Skip to main content

Module atomic

Module atomic 

Source
Expand description

Atomic file writes for crash-safe output.

All output files are written via a temporary file alongside the final destination, flushed and fsynced, then atomically renamed into place. This guarantees that the final path either contains the complete, valid output or does not exist at all — partial or corrupt files are never left behind even if the process crashes or is interrupted.

§Platform Notes

  • On POSIX systems, std::fs::rename is atomic within the same filesystem. The temporary file is created in the same directory as the destination to ensure they share a mount point.
  • File::sync_all() is called before rename to flush OS and hardware buffers.
  • On rename failure, the temporary file is cleaned up on a best-effort basis.

Structs§

AtomicFileWriter
An atomic file writer that writes to a temporary file and renames on completion.

Functions§

atomic_write
Write data to dest atomically.