storeroot

package
v0.2026326.408 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2026 License: MIT Imports: 4 Imported by: 3 modules, 2 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 storeroot resolves charly's roots — configuration, data, cache, state and runtime — and owns their charly-only overrides, the environment that relocates a root for charly alone.

Why the roots are a CONTRACT, not a mechanism

A root is not an implementation detail: the host and every plugin it serves must agree on WHERE the shared trees are, or a plugin writes its cache into a tree the host never sweeps and the host looks for a store the plugin never wrote. That agreement is a contract between two separately-built processes, so it lives on the contract side (this module), and it is the reason a plugin may import it just as freely as the host does.

The placement is forced by the host's own boundary law, not chosen for taste: core imports only permitted contract surfaces (spec/* + proto) and may never import an sdk mechanism kit, while `sdk/storekit` — where these roots used to be computed — is a mechanism kit. Leaving the ONE resolver there gave the host exactly two options, hand-build the paths (which is what it did: `charlyDaemonPids` composed `$XDG_CACHE_HOME/charly` and `$XDG_RUNTIME_DIR/charly` itself, and so could not see `CHARLY_CACHE_DIR` at all) or import across the boundary it is forbidden to cross. Resolving here satisfies both rules as written: the host reaches the ONE resolver through a permitted surface, and the mechanism kits re-export it rather than keeping a second copy (see `sdk/storekit`).

The charly-only overrides

Every XDG input a charly root is built from has a charly-only override that takes precedence for charly over that input (D-STORE-1): `CHARLY_CONFIG_HOME`, `CHARLY_CONFIG_DIRS`, `CHARLY_DATA_HOME`, `CHARLY_DATA_DIRS`, `CHARLY_STATE_HOME`, `CHARLY_CACHE_HOME` and `CHARLY_RUNTIME_DIR`. The `_HOME`/`_DIR` form names a COMPLETE charly root — an absolute path, not an XDG base — and the `_DIRS` form names a colon-separated list of complete charly directories. An override never moves the XDG base itself, so a path belonging to another application (a quadlet unit, a fish snippet, libvirt) keeps resolving against `$XDG_*`; only charly's own trees move. A relative or empty override is invalid and is ignored, so the XDG input's default applies. When both cache overrides are set, `CHARLY_CACHE_HOME` wins.

`CHARLY_CACHE_DIR` and `CHARLY_REPO_CACHE` remain compatibility overrides and are never dropped (operator direction of 2026-11-20): `CHARLY_CACHE_DIR` relocates the cache root and is used exactly as the operator wrote it — never absolutised, cleaned or rewritten, so a relative value stays relative — and `CHARLY_REPO_CACHE` names the remote-repo directory (see `refs`).

Cache and data are different trees

The cache root is re-derivable and holds the one content-addressed store (D-STORE-3). The data root holds durable user data that cannot be re-derived — SSH keys, VM disks and per-VM state, encrypted-volume plaintext, bind-mounted volumes (D-STORE-12). A built image or artifact is a cached item and stays in the cache store, and `charly clean` never evicts the data root (D-STORE-7).

This package resolves paths; it does not own the store

The content-addressed store, its entries, views and garbage collection are the sdk mechanism layer's (`sdk/storekit`, which re-exports the symbols below). The legacy config-root store that `spec/cache` still carries resolves a DIFFERENT root (`opencharly/spec#233`) and is not served by this package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Base added in v0.2026324.1605

func Base(root Root) (string, error)

Base resolves the unsuffixed XDG base through the process-environment resolver.

func BaseDirs added in v0.2026324.1605

func BaseDirs(root Root) ([]string, error)

BaseDirs returns the raw search path through the process-environment resolver.

func CacheDir

func CacheDir() (string, error)

CacheDir resolves the cache root through the process-environment resolver.

func DataDir added in v0.2026322.1111

func DataDir() (string, error)

DataDir resolves the durable data root through the process-environment resolver.

func Dir

func Dir(root Root) (string, error)

Dir resolves one of the roots through the process-environment resolver.

func Dirs added in v0.2026324.1605

func Dirs(root Root) ([]string, error)

Dirs returns the root search path through the process-environment resolver.

func Search(root Root, rel string) (string, bool, error)

Search finds a relative file through the process-environment resolver.

Types

type Bases added in v0.2026324.1532

type Bases struct {
	Data    string
	Config  string
	Cache   string
	State   string
	Runtime string
	// RuntimeSet reports whether `XDG_RUNTIME_DIR` was set to a VALID (absolute) path.
	// When false, Runtime carries the D-STORE-1 state fallback; the flag lets a caller
	// distinguish the two without re-reading the variable.
	RuntimeSet bool
}

Bases holds the XDG Base Directory Specification values resolved for the current user. Dir and CacheDir build charly's own roots from these; hostenv expands an operator-authored `$XDG_*` token from the SAME values, so a relocated base moves both charly's trees and every deployment path.

func XDG added in v0.2026324.1532

func XDG() (Bases, error)

XDG resolves the XDG bases ONCE. It applies the specification's Unix defaults and its rule that a non-absolute value is invalid and MUST be ignored. The error is non-nil only when at least one base had to fall back to a RELATIVE default because `$HOME` was unavailable while its variable was unset or relative; the returned Bases still carry every value that did resolve. A caller that needs one base should use it when it is absolute and treat the home error as fatal only for the base that fell back.

type Resolver added in v0.2026324.1605

type Resolver struct {
	Bases     func() (Bases, error)
	LookupEnv func(string) (string, bool)
}

Resolver is the D-STORE-8 test seam: it resolves the same roots from injected base values and an injected environment lookup, so a table test never depends on the process environment. Default() wires it to XDG() and os.LookupEnv; production callers use the package-level functions, which delegate here.

func Default added in v0.2026324.1605

func Default() *Resolver

Default returns the process-environment resolver.

func (*Resolver) Base added in v0.2026324.1605

func (r *Resolver) Base(root Root) (string, error)

Base resolves the UNSURFIXED XDG base a root lives under. It is what a path belonging to another application (systemd/quadlet, libvirt, opencharly, fish) is built from; use Dir for charly's own trees. The charly-only overrides are COMPLETE charly roots, not XDG bases, so they do not move the base of any other application's path.

RootCache is special, and only because the cache overrides replace that one root wholesale: `CHARLY_CACHE_HOME` and then `CHARLY_CACHE_DIR` are returned verbatim, so a charly-owned sibling of the cache root (the shared Go temp dir) lands beside it.

func (*Resolver) BaseDirs added in v0.2026324.1605

func (r *Resolver) BaseDirs(root Root) ([]string, error)

BaseDirs returns the RAW XDG search path for a root that has one (configuration or data), in specification order. An unset or empty variable takes the Unix defaults; a non-absolute entry is ignored. It reads the XDG input only: the charly-only `_DIRS` overrides name COMPLETE charly directories, so they are applied by Dirs, never here.

func (*Resolver) CacheDir added in v0.2026324.1605

func (r *Resolver) CacheDir() (string, error)

CacheDir resolves the cache root: `CHARLY_CACHE_HOME` when set, else the `CHARLY_CACHE_DIR` compatibility override (verbatim), else `$XDG_CACHE_HOME/charly`. Every named store lives under it.

func (*Resolver) DataDir added in v0.2026324.1605

func (r *Resolver) DataDir() (string, error)

DataDir resolves the durable data root (`$XDG_DATA_HOME/charly`).

func (*Resolver) Dir added in v0.2026324.1605

func (r *Resolver) Dir(root Root) (string, error)

Dir resolves one of the roots. It is THE resolver: no caller builds a `.config`, `.local/share` or `.cache` path by hand. A root's charly-only override is a complete charly root and is returned verbatim.

func (*Resolver) Dirs added in v0.2026324.1605

func (r *Resolver) Dirs(root Root) ([]string, error)

Dirs returns the root's search path: charly's own root first, then the search entries. A `CHARLY_CONFIG_DIRS`/`CHARLY_DATA_DIRS` override supplies complete charly directories and is used verbatim; otherwise each XDG search entry is read from its `charly` subdirectory. Only configuration and data have a search path.

func (*Resolver) Search added in v0.2026324.1605

func (r *Resolver) Search(root Root, rel string) (string, bool, error)

Search returns the first existing file named by rel across Dirs(root). rel must be relative and must not contain a `..` element. A missing file is ("", false, nil), not an error.

type Root

type Root string

Root names one of the roots.

const (
	// RootConfig — `$XDG_CONFIG_HOME/charly`: what the USER sets.
	RootConfig Root = "config"
	// RootData — `$XDG_DATA_HOME/charly`: durable user data that cannot be
	// re-derived. It is NOT a cache: a cached item stays in the cache store, and
	// `charly clean` never evicts this root.
	RootData Root = "data"
	// RootCache — `$XDG_CACHE_HOME/charly`: everything content-addressed and
	// re-derivable. `CHARLY_CACHE_HOME` (then the compatibility `CHARLY_CACHE_DIR`)
	// relocates this root and therefore every store.
	RootCache Root = "cache"
	// RootState — `$XDG_STATE_HOME/charly`: durable state that is NOT cache — install
	// ledgers, process locks, anything a restart must not lose and a `cache clear`
	// must not touch.
	RootState Root = "state"
	// RootRuntime — `$XDG_RUNTIME_DIR/charly`: per-boot runtime state.
	RootRuntime Root = "runtime"
)

Jump to

Keyboard shortcuts

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