perhost

package
v0.2026328.1009 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: MIT Imports: 6 Imported by: ? 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 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

View Source
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

func Get(root *yaml.Node, keys ...string) *yaml.Node

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

func Read(path string) (*yaml.Node, error)

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

func Set(root *yaml.Node, value *yaml.Node, keys ...string) bool

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

func Update(path string, mutate func(root *yaml.Node) (changed bool, err error)) error

Update runs ONE locked read-modify-write cycle over the per-host config:

  1. take <path>.lock (bounded: LockWait);
  2. Read the CURRENT on-disk document — never a caller's snapshot, which is how a concurrent writer's change gets lost;
  3. call mutate on the document's root mapping; mutate touches ONLY the keys it owns and reports whether anything changed;
  4. 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.

Jump to

Keyboard shortcuts

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