Skip to main content

Module atomic

Module atomic 

Source
Expand description

Atomic file publication primitives: lock-file guarded writes published by rename.

Consolidates the hand-rolled create_new(temp) + optional barrier + rename(target) dances scattered across writers. The LockFile guard owns the exclusive-create temp/lock file and removes it on drop unless the write is explicitly persisted (or deliberately kept, for mkstemp-style creators whose temporary name is the deliverable).

Naming conventions stay at call sites: LockFile::acquire uses git’s sibling <name>.lock convention, while LockFile::create accepts an exact path for load-bearing names such as odb tmp_obj_<pid>_<n> temps.

Structs§

LockFile
An exclusively created lock/temp file with atomic publication semantics.

Functions§

atomic_write
Atomically replace path with contents: sibling .lock temp, write, rename. Fails when the lock already exists; callers create parent directories themselves when needed.
atomic_write_with
Atomically replace path using a writer callback, so streamed encoders avoid buffering the whole payload twice.
lock_path_for
Lock path for path: the file name suffixed .lock in the same directory (git’s lockfile convention, e.g. packed-refs -> packed-refs.lock).