Documentation
¶
Overview ¶
Package atomic provides crash-safe atomic file writes at an absolute path.
It is the unrooted counterpart to the root package: acfs.Write confines every write to a workspace root and replaces a symlinked destination, while atomic.WriteFile takes any absolute path and refuses a symlinked destination. The two symlink policies live in separate namespaces on purpose — reach for this package only when there is no natural root to confine the write to.
WriteFile writes to a temporary file in the destination's directory, fsyncs it, applies the requested permissions, and renames it onto the destination -- so a reader never observes a partially written file and a crash mid-write leaves the previous version intact.
WriteFile's temp-file/fsync/chmod/rename sequence and its destination check's refusal to write through a symlink/directory/named pipe/socket/device destination are adapted from moby's atomicwriter package:
Source: github.com/moby/sys/atomicwriter License: Apache License 2.0 (https://github.com/moby/sys/blob/main/LICENSE) File: https://github.com/moby/sys/blob/main/atomicwriter/atomicwriter.go
This is a reimplementation against only the standard library, not a copy, so this module stays dependency-free. It deliberately simplifies moby's version in a few ways:
- os.CreateTemp is used instead of moby's sequential.CreateTemp, a Windows standby-list optimization that isn't a correctness requirement here.
- WriteFile's destination check does not refuse setuid/setgid/sticky-bit destinations, and does not pre-check that the parent directory exists (every caller here already MkdirAll's its target directory).
- Parent-directory fsync is not performed, matching moby's own behavior: atomic rename already guarantees a reader never sees a torn file, and the extra fsync only narrows the crash-immediately-after-rename window.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
This section is empty.