Documentation
¶
Overview ¶
Package atomic is durable, all-or-nothing file replacement — the Go counterpart of lib/tasks/atomic.rb, and the only writer the store uses.
A plain write can be seen half-written by a concurrent reader (the live TUI, another CLI) and leaves a truncated tasks.jsonl behind if the process dies mid-write. Instead the full contents go to a sibling temp file, are flushed to disk, and the temp is renamed over the target: rename is atomic on a POSIX filesystem, so a reader — or a crash — only ever sees the whole old file or the whole new one, never a torn mix.
Because rename installs a new inode, three things keep the swap transparent, and every one of them is a behavior a port gets wrong by omission:
- the target's symlink is followed, so a rename does not replace the link itself and orphan a Dropbox/dotfiles setup;
- its permission bits are carried onto the replacement, because a fresh temp is born at the umask and a chmod-600 tasks.jsonl would otherwise silently widen to 644;
- the parent directory is fsynced after the rename, so the swap is durable across a crash rather than merely atomic.
Hardlinks are not preserved: atomic-rename replacement is fundamentally incompatible with keeping a second hardlink name in sync.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Resolve ¶
Resolve is the concrete file the write should land on. A symlink is followed to the real file so we replace IT, not the link — even a dangling link (a target on a briefly-unmounted volume) resolves to its intended path rather than being overwritten into a plain file. A path with no link and no file yet (archive.jsonl before the first sweep) is used as given.
func SetWriteHook ¶
SetWriteHook installs a replacement for Write and returns a function that removes it. It is a TEST SEAM: production code must never call it.
The returned restore function is what a test defers; nesting is not supported, and a second SetWriteHook while one is installed replaces it rather than stacking, which keeps a leaked hook loud instead of subtle.
func Write ¶
Write replaces path's contents with content, atomically and durably.
The temp name carries the process id and a goroutine-unique counter for the same reason Ruby's carries pid and thread object id: concurrent writers to DIFFERENT files must not collide on the temp name, while writers to the same file are already serialized by the store's lock.
func WriteDirect ¶
WriteDirect is Write without the test seam — the real replacement, always. A fault-injection hook calls it to pass a write through, the way Ruby's stub calls `original.call`.
Types ¶
This section is empty.