storeroot

package
v0.2026324.1605 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 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 the single environment override that relocates the cache.

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 one override

`CHARLY_CACHE_DIR` relocates the CACHE root, and only that root: it is the single environment override in the whole system, and every named store lives under it. The value is used exactly as the operator wrote it — the resolver never absolutises, cleans or rewrites it, so a relative value stays relative. No other root has an override.

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. RootCache is special: the CHARLY_CACHE_DIR override is a complete root and is returned verbatim.

func (*Resolver) BaseDirs added in v0.2026324.1605

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

BaseDirs returns the RAW 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.

func (*Resolver) CacheDir added in v0.2026324.1605

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

CacheDir resolves the cache root: `$XDG_CACHE_HOME/charly`, or `CHARLY_CACHE_DIR` when set. 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.

func (*Resolver) Dirs added in v0.2026324.1605

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

Dirs returns the root's search path with charly's own tree first, then each search entry under 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. The single `CHARLY_CACHE_DIR` override relocates this one 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