Skip to main content

Module atomic_file

Module atomic_file 

Source
Expand description

Installing a local file’s complete contents so a crash leaves either the old bytes or the new ones, never a partial write.

This module is the crate’s blessed implementation of the durable write, and the only place allowed to call the raw sync methods that clippy.toml disallows everywhere else. Keeping it to one place is what lets the platform split below — Unix flushes the parent directory, nothing else can — stay correct in a single spot instead of in every caller.

Structs§

AtomicFile
One local file whose complete contents are installed with a durable rename.
AtomicFileStage
One unpublished file whose destination is chosen after its bytes have been written. This is the streaming counterpart to write_atomic: callers can compute a content address while implementing std::io::Write, then commit the completed file under that address with the owning durability policy’s file-sync, rename, and directory-sync sequence.

Enums§

FileError
A local filesystem operation that failed without erasing its I/O cause.
WriteError
A failed atomic write, tagged with whether the write had already committed.

Functions§

is_atomic_staging_file_name
Whether a directory entry is an unpublished sibling left by this module’s atomic writer. Callers that enumerate committed records exclude these; they are not part of the durable record set until renamed onto a target.
sync_parent_dir
Flush the directory entry a rename onto path just wrote, so the installed file survives a crash. Every durable rename in the crate ends here.
sync_parent_dir_blocking
sync_parent_dir for callers that are not on the async runtime.
write_atomic
Install bytes as the complete contents of path.