Documentation
¶
Overview ¶
Package atomicfile writes files atomically so that a reader never observes a partially written file. It is used for the repo cache and the config, where an interrupted in-place write (crash, SIGKILL, power loss, or a full disk) would otherwise truncate the file and silently destroy data that cannot be regenerated, such as frecency history.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func WriteFile ¶
WriteFile writes data to path atomically. It writes to a temporary file in the same directory, sets the requested permissions, then renames it over path. Rename is atomic on POSIX, so a concurrent reader sees either the complete old file or the complete new one, never a partial write. On any failure before the rename, path is left untouched and the temp file is removed.
It deliberately does not fsync. The guarantee is no-torn-file, not durability-of-the-latest-write: after a crash a reader may see the previous complete contents, which is the safe failure mode for a rebuildable cache.
Types ¶
This section is empty.