Expand description
Crash-safe file writes.
Every write of something a user would mind losing goes through
write_atomically. std::fs::write truncates the target and then fills it,
so a crash, a kill, or a power cut partway through leaves a half-written file
where the previous good one used to be โ and for the document save that is the
drawing itself.
Functionsยง
- parent_
dir ๐ - The directory holding
target. A bare relative filename has an empty parent, which names nothing openable. - resolve ๐
- Follow symlinks, so writing a symlinked document replaces what it points at โ
the way
fs::writedoes. Renaming onto the link would instead replace the link with a regular file and quietly detach it from its target. - sync_
dir ๐ - Flush the directory entry itself, so the rename survives a power cut and not just a process crash.
- temp_
path ๐ - A dot-prefixed sibling of
target. It has to share the directory:renameis only atomic within one filesystem. - write_
and_ ๐replace - write_
atomically - Write
contentstopathso that dying partway through leaves the previous contents intact: the bytes land in a sibling temporary file, are flushed to the storage device, and only then replacepathwith one atomic rename.