Documentation
¶
Overview ¶
Package perhost is THE single reader and writer of the per-host charly config (~/.config/charly/charly.yml, honoring CHARLY_DEPLOY_CONFIG).
The file is a SHARED document: the deploy overlay, the git-ref cache, the install ledger and the system info all live in it as top-level sections, written by DIFFERENT charly commands that can run CONCURRENTLY. Four independent copies of "take <path>.lock, read the yaml.Node, find-or-create my key, marshal, tempfile+rename" grew here, and the copies disagreed about the contract in ways that destroyed real data on 2026-11-24:
- one cleared a section by DELETING the whole file (every deploy entry with it);
- one wrote a stale in-memory value over a value another process had just changed.
Update is that contract, stated once: one lock, one read INSIDE the lock, one mutate that touches only the keys it owns, one atomic rename. A corrupt or unparseable file is never clobbered — mutate is not called at all. Callers supply ONLY the section logic; the file mechanics are here.
Index ¶
Constants ¶
const LockWait = 10 * time.Second
LockWait bounds the wait for the shared advisory lock. A section write is milliseconds, so a legitimate queue clears well inside this; a holder that outlives it is a stuck writer or a cross-command collision, and both deserve a fast, named error rather than an unbounded hang.
Variables ¶
This section is empty.
Functions ¶
func Get ¶
Get returns the value node at the given key path (e.g. Get(root, "cache", "git", "bypass")), or nil when any step is absent or not a mapping.
func Read ¶
Read parses the per-host config at path. A missing file is (nil, nil) — a fresh host; a corrupt file is an error, never an empty document (a writer must refuse, not truncate).
func Set ¶
Set stores value at the given key path, creating intermediate mappings. A nil value REMOVES the leaf key. It reports whether the document changed.
func Update ¶
Update runs ONE locked read-modify-write cycle over the per-host config:
- take <path>.lock (bounded: LockWait);
- Read the CURRENT on-disk document — never a caller's snapshot, which is how a concurrent writer's change gets lost;
- call mutate on the document's root mapping; mutate touches ONLY the keys it owns and reports whether anything changed;
- when it did, marshal and replace the file atomically (tempfile in the same directory + rename), so a reader never sees a half-written file.
A corrupt file is an error and mutate is NOT called: the bytes stay for recovery.
Types ¶
This section is empty.