Documentation
¶
Overview ¶
Package atomic provides a stage-then-rename WriteFile primitive. Using a sibling temp file + os.Rename collapses what would otherwise be a create-write-close-chmod-rename sequence into a single visible transition, satisfying POSIX atomicity for cache writers that must never expose a partial or zero-byte file to concurrent readers.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func WriteFile ¶
WriteFile writes data to path atomically. The file is first written to a sibling temp file in the same directory (ensuring rename stays on the same filesystem / inode device), then renamed into place. Readers always observe either the previous complete contents or the new complete contents.
perm is applied to the staged file before rename; umask still applies via CreateTemp. On any error after staging, the temp file is removed and path is left untouched.
syncDir controls the durability guarantee. When true the function calls Sync on the staged file before rename, then opens and fsyncs the directory after rename — this flushes the rename journal entry so the new name survives a power loss. Set false for high-churn caches whose values are cheap to re-derive on the next reconcile.
Types ¶
This section is empty.