atomic

package
v1.11.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 19, 2026 License: MIT Imports: 6 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

func Resolve(path string) string

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

func SetWriteHook(replacement func(path, content string) error) (restore func())

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

func Write(path, content string) error

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

func WriteDirect(path, content string) error

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL