versions

package
v1.0.0-rc.5 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package versions stores retained gridctl binaries under a home-scoped directory so a standalone install can roll back without a download.

Layout: manifest.json (0644), .lock, and <tag>/gridctl (0755). The store knows nothing about GitHub, tarballs, or daemons. Callers copy a file in with Retain and install it themselves.

Index

Constants

View Source
const (
	// OriginReplaced marks a binary copied from the executable that was
	// about to be replaced.
	OriginReplaced = "replaced"
	// OriginDownloaded marks a binary copied from a verified release archive.
	OriginDownloaded = "downloaded"
)
View Source
const (
	// ManifestSchemaVersion is the current manifest schema. A newer
	// value is refused rather than rewritten (Article XVII).
	ManifestSchemaVersion = 1
)

Variables

View Source
var (
	// ErrNewerManifest marks a manifest written by a newer gridctl.
	// Callers must not rewrite it.
	ErrNewerManifest = errors.New("versions manifest written by a newer gridctl")
	// ErrChecksumMismatch marks a retained binary whose SHA256 does not
	// match the manifest. The installed binary must not be replaced.
	ErrChecksumMismatch = errors.New("retained binary checksum mismatch")
	// ErrInvalidTag marks a tag that is not safe to use as a single
	// directory name under the store.
	ErrInvalidTag = errors.New("invalid version tag")
	// ErrSymlinkSource marks a retain source that is a symlink resolving
	// outside the allowed temp directory or executable path.
	ErrSymlinkSource = errors.New("retain source symlink resolves outside allowed paths")
)

Functions

func ValidateTag

func ValidateTag(tag string) error

ValidateTag reports whether tag is a single directory name with no separator and no "..". Rollback callers also require a semver tag.

Types

type Entry

type Entry struct {
	Tag        string    `json:"tag"`
	SHA256     string    `json:"sha256"`
	Size       int64     `json:"size"`
	RetainedAt time.Time `json:"retained_at"`
	Origin     string    `json:"origin"`
	Schemas    *Schemas  `json:"schemas"`
}

Entry is one retained binary.

type Manifest

type Manifest struct {
	SchemaVersion int     `json:"schema_version"`
	Active        string  `json:"active"`
	Previous      string  `json:"previous"`
	Entries       []Entry `json:"entries"`
}

Manifest is the on-disk index. Active is the tag last installed. Previous is the tag to restore when rollback is given no tag.

type Schemas

type Schemas struct {
	DaemonState  int    `json:"daemon_state"`
	ProjectLock  int    `json:"project_lock"`
	ImportLock   int    `json:"import_lock"`
	ToolPins     string `json:"tool_pins"`
	SkillPins    string `json:"skill_pins"`
	PinApprovals string `json:"pin_approvals"`
	ContextPins  string `json:"context_pins"`
}

Schemas is the schema advertisement a binary reported at retention time. Nil means the retaining release did not record one (serialized as null). Pin fields are strings because the on-disk constants are strings; an absent pin field decodes as "".

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store is an exclusively locked versions directory. Close releases the lock.

func Open

func Open(ctx context.Context, dir string) (*Store, error)

Open creates dir (0755) if needed and acquires a cross-process exclusive flock on .lock. A manifest with schema_version greater than ManifestSchemaVersion returns ErrNewerManifest and does not hold the lock. A missing manifest is an empty store.

func (*Store) Active

func (s *Store) Active() string

Active returns the tag last recorded as installed.

func (*Store) AllowSources

func (s *Store) AllowSources(paths ...string)

AllowSources records files and directories a symlink retain source may resolve into. A symlink that resolves outside every allowed path is refused. A regular file is accepted. When no sources have been allowed, every symlink is refused.

func (*Store) Close

func (s *Store) Close() error

Close releases the lock. It is safe to call more than once.

func (*Store) Entries

func (s *Store) Entries() []Entry

Entries returns a copy of the manifest entries, newest RetainedAt first.

func (*Store) Lookup

func (s *Store) Lookup(tag string) (Entry, string, bool)

Lookup returns the entry and the binary path. ok is false when the tag is not in the manifest. The file may be missing until the next write drops the entry.

func (*Store) Orphans

func (s *Store) Orphans() []string

Orphans returns directory names present on disk but absent from the manifest, sorted. They are never deleted.

func (*Store) Previous

func (s *Store) Previous() string

Previous returns the tag recorded for a tagless rollback.

func (*Store) Prune

func (s *Store) Prune(ctx context.Context, keep int) ([]string, error)

Prune removes oldest RetainedAt entries first until the count is at or below keep. Active and Previous are never removed, so the floor can exceed keep. Removed tags are returned. Directories that are not in the manifest are left in place (see Orphans).

func (*Store) Retain

func (s *Store) Retain(ctx context.Context, tag, srcPath, origin string, schemas *Schemas) error

Retain copies srcPath into <tag>/gridctl through a temp sibling and rename, then upserts the entry. Re-retaining an existing tag with the same SHA256 is a no-op. A different SHA256 replaces the file and entry. On every write, entries whose file is missing are dropped from the manifest.

func (*Store) SetActive

func (s *Store) SetActive(active, previous string) error

SetActive records the installed tag and the rollback tag, then writes the manifest. Entries whose file is missing are dropped.

func (*Store) Verify

func (s *Store) Verify(ctx context.Context, tag string) error

Verify recomputes the binary SHA256 and compares it to the manifest. ErrChecksumMismatch includes the expected and actual digests.

Jump to

Keyboard shortcuts

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