generation

package
v0.21.3 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ActiveStoreDirs added in v0.13.1

func ActiveStoreDirs(pkgs map[string]string, storeRoot string) []string

ActiveStoreDirs resolves each (name, version) in pkgs to its on-disk store dir. Returned in an arbitrary order. Seeds FarmStoreDirs, which Build and `gale doctor` use for the shared dylib farm.

func ActiveVersions added in v0.16.3

func ActiveVersions(pkgs map[string]string, storeRoot string) map[string]string

ActiveVersions resolves each (name, version) in pkgs to the store-dir basename ("<version>-<revision>", or a bare "<version>" for legacy pre-revision installs) that a fresh Build would link against. Used by `gale doctor` to compare against CurrentVersions — which reads the active gen's actual symlink targets — and surface revision drift when the gen carries a stale link to an older revision.

func Build

func Build(pkgs map[string]string, galeDir, storeRoot string) error

Build creates a new generation from the package map and atomically swaps the current symlink. Packages whose store dir is missing are silently skipped with a warning on stderr: gale.toml legitimately lists packages that aren't installed locally (`gale add` without sync, a fresh clone on a new host, an unsupported-platform skip), and erroring the rebuild would desync PATH from config (gh#68). The missing package is reported on stderr so the user learns which package fell off PATH. Previous generations are retained for history and rollback.

func Current

func Current(galeDir string) (int, error)

Current returns the active generation number by resolving the current symlink. Returns 0 if no current generation exists.

func CurrentVersions added in v0.16.3

func CurrentVersions(galeDir, storeRoot string) (map[string]string, error)

CurrentVersions returns the package name → version map of the active generation by reading its symlinks. Returns an empty map (no error) when no generation is active yet. Used by sync to detect whether gale.toml has drifted from the active generation — drift means the rebuild must run even if no installs happened, so removed packages drop off PATH.

func FarmStoreDirs added in v0.17.0

func FarmStoreDirs(pkgs map[string]string, storeRoot string) []string

FarmStoreDirs returns the store dirs whose versioned dylibs belong in the shared farm: the resolved dir for every package in pkgs plus the transitive dep closure recorded in each dir's .gale-deps.toml. Runtime deps are farmed at install time but never appear in gale.toml, so rebuilding the farm from the config set alone deletes the entries dependents' rpaths resolve through (gh#43). Dep dirs missing from the store are skipped — the farm can only link what's on disk. Visited dirs are not re-expanded, so dep cycles terminate.

func PruneOldGenerations added in v0.16.3

func PruneOldGenerations(galeDir, storeRoot string, keep int) ([]int, error)

PruneOldGenerations removes generation directories older than (curGen - keep + 1), preserving the most recent `keep` gens (including the current one). Anything at or above curGen — including any in-flight gen/curGen+1 a concurrent Build may have created — is preserved. Holds the store-rooted gen lock for its critical section so it serializes with Build.

Returns the removed gen numbers in ascending order so the caller can report them. keep<=0 or no current symlink is a no-op (returns nil).

Intended as an auto-gc hook after Build: callers pass the user-configured retention (default 10) so per-install gen accumulation can't drown the filesystem in inodes (the dev- host incident with ~3M gen/ inodes across 33 untouched gens).

func Resolve added in v0.16.3

func Resolve(galeDir string) (int, string, error)

Resolve is Current plus a target-existence check. It returns (gen, relTarget, nil) when the current symlink points at an extant gen directory, (0, "", nil) when no current symlink exists yet, and a descriptive error when the symlink dangles (target gen directory absent) or its name doesn't parse. `gale doctor` uses this to flag a corrupted current pointer — the case where the active generation has been deleted out from under us by rm -rf, a partial gc, or a half-restored backup — which Current alone cannot detect because it only Readlinks the symlink.

func Rollback added in v0.8.0

func Rollback(galeDir, storeRoot string, target int) error

Rollback atomically swaps the current symlink to point at the given generation number and rebuilds the shared dylib farm from that generation's package set. Acquires the generation lock so it serializes with Build and PruneOldGenerations.

Types

type GenDiff added in v0.8.0

type GenDiff struct {
	From    int
	To      int
	Added   []string // "name@version"
	Removed []string // "name@version"
}

GenDiff describes differences between two generations.

func Diff added in v0.8.0

func Diff(galeDir, storeRoot string, from, to int) (*GenDiff, error)

Diff compares two generations and returns the packages added and removed between them.

type GenInfo added in v0.8.0

type GenInfo struct {
	Number   int
	Current  bool
	Packages map[string]string // name → version
}

GenInfo describes one generation.

func List added in v0.8.0

func List(galeDir, storeRoot string) ([]GenInfo, error)

List returns all generations sorted by number ascending.

Jump to

Keyboard shortcuts

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