installer

package
v1.11.0 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2026 License: Apache-2.0 Imports: 36 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

Index

Constants

View Source
const NoPercent = -1

NoPercent is a progress event's percent when nothing was measured.

Variables

View Source
var ErrBlockingApps = fmt.Errorf("%w: blocking applications running", ErrDeferred)

ErrBlockingApps is returned by Install when a listed blocking application is running (spec R6). It wraps ErrDeferred.

View Source
var ErrCanceled = errors.New("canceled by user")

ErrCanceled is returned by Install when the user withdrew the item before the run started its install or uninstall command. Nothing is recorded in the report: the item was neither attempted nor failed.

View Source
var ErrDeferred = errors.New("deferred")

ErrDeferred is wrapped by every error Install returns when it skipped the action and recorded it in the report's DeferredItems. The dependency walk cascades it to dependents instead of treating it as a failure, and the next run retries.

View Source
var ErrMissingSoftware = fmt.Errorf("%w: required software missing", ErrDeferred)

ErrMissingSoftware is returned by Install when software the item requires is not installed. It wraps ErrDeferred.

Functions

func KeptNupkgVersion added in v1.11.0

func KeptNupkgVersion(root, id string) (string, bool)

KeptNupkgVersion returns the nuspec version of the kept copy of package id under root, and whether a kept copy exists. A kept copy whose nuspec cannot be read exists with an empty version, so a status check treats it as installed at an unknown version rather than absent.

Types

type Cancels

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

Cancels lets the service withdraw items from managed runs that are already under way. An item can be withdrawn until a run starts its install or uninstall command; withdrawing it then aborts its download if one is in flight. A running installer command is never interrupted. The service keeps one Cancels for its lifetime and hands it to every run. A nil *Cancels withdraws nothing, which is what the command-line run uses.

func NewCancels

func NewCancels() *Cancels

func (*Cancels) Cancel

func (c *Cancels) Cancel(name string) bool

Cancel withdraws name. It returns false, and changes nothing, once a run has started name's install or uninstall command.

func (*Cancels) EndRun

func (c *Cancels) EndRun()

EndRun forgets the finished run: its withdrawals and the items it acted on. A cancel also reverted the self-serve selection, so later runs do not pick the item up again, and an item an admin manifest also requires must not stay skipped. An operation whose run has finished is refused as finished instead.

func (*Cancels) Reset

func (c *Cancels) Reset(name string)

Reset drops a withdrawal of name; the service calls it when a new install or removal of name is requested, which can happen while a run is under way. It leaves alone whether that run is acting on name: a cancel must still refuse while an installer for name runs.

type Outcome added in v1.11.0

type Outcome string

Outcome is what an inspect, apply or remove step found or did for one placement.

const (
	// OutcomeMissing (inspect): no tree yet; apply installs it.
	OutcomeMissing Outcome = "missing"
	// OutcomeUnchanged (inspect): the tree equals its receipt's placed_hash
	// but the receipt's tree_hash is not the catalog's; apply replaces it
	// with the catalog version.
	OutcomeUnchanged Outcome = "unchanged"
	// OutcomeCurrent: the tree equals its receipt's placed_hash, the receipt
	// matches the catalog and its rendered inputs are what this run would
	// render with.
	OutcomeCurrent Outcome = "current"
	// OutcomeAdopted: the tree equals its receipt's placed_hash with a stale
	// receipt or stale inputs, or equals the catalog's tree_hash as shipped;
	// its receipt is (inspect: is to be) written for the current version,
	// after a render in place where inputs or templates call for one.
	OutcomeAdopted Outcome = "adopted"
	// OutcomeInstalled (apply): the catalog tree was placed.
	OutcomeInstalled Outcome = "installed"
	// OutcomeRemoved (remove): the tree and its receipt are gone.
	OutcomeRemoved Outcome = "removed"
	// OutcomeConflict: the tree matches neither its receipt's placed_hash nor
	// the catalog's tree_hash, or has no receipt and differs from the
	// catalog; it is left alone.
	OutcomeConflict Outcome = "conflict"
	// OutcomeRefused: the placement may not be written.
	OutcomeRefused Outcome = "refused"
	// OutcomeFailed: an error other than a conflict or a refusal.
	OutcomeFailed Outcome = "failed"
)

type ProgressFn

type ProgressFn func(item catalog.Item, pulledBy []string, state string, percent int, message string)

ProgressFn receives coarse per-item progress events. States emitted per item: `downloading`, `installing`/`removing`, `done`/`failed`. percent is the measured share of the item done, or NoPercent when the phase measured nothing: only a download of known length is measured, and `done` is 100. pulledBy is Runner.PulledBy at the time; the callback must not keep it. The service attaches an operation-scoped callback for self-service mutations.

type Result added in v1.11.0

type Result struct {
	Placement string
	// Path is the tree's directory, <placement root>/<item> (in a
	// marketplace, <placement root>/plugins/<item>), when known.
	Path    string
	Outcome Outcome
	Err     error
}

Result is one placement's outcome. Err is set for OutcomeConflict, OutcomeRefused and OutcomeFailed.

func (Result) Code added in v1.11.0

func (r Result) Code() string

Code is the report error code of a failed result: placement_conflict, placement_refused, or "" for the generic item_failed.

func (Result) Failed added in v1.11.0

func (r Result) Failed() bool

Failed reports whether the result fails the item.

type Runner

type Runner struct {
	Report      *report.Report
	Checker     *status.Checker
	Emit        ProgressFn // nil = no progress events
	Cancels     *Cancels   // nil = nothing can be withdrawn
	URLPackages string
	CachePath   string
	CheckOnly   bool
	// Zip places zip items; nil fails every zip item as placement_refused.
	Zip *ZipInstaller
	// NupkgPath is the root of the kept nupkg copies (config.NupkgPath).
	NupkgPath string

	// PulledBy names the items, outermost first, whose install is pulling in
	// the current one as a dependency or updater; empty for a top-level item.
	PulledBy []string
}

Runner is the run-scoped install context (K7: no cross-run package globals)

func (*Runner) Install

func (r *Runner) Install(item catalog.Item, installerType string) (string, error)

Install determines if action needs to be taken on a item and then calls the appropriate function to install or uninstall

func (*Runner) Regenerate added in v1.11.0

func (r *Runner) Regenerate()

Regenerate rewrites every marketplace's generated files from the receipts (ZipInstaller.RegenerateAll), recording each failure as a FailedItem named for the placement, with action generate.

func (*Runner) ScopeExit added in v1.11.0

func (r *Runner) ScopeExit(keep func(item string) bool) error

ScopeExit removes, under R15, every receipt-tracked item that keep rejects: items that left the run's desired set and are not held. It runs after the install pass. Check-only runs remove nothing.

type Target added in v1.11.0

type Target struct {
	Placement string
	Variant   catalog.Variant
	// Spec is the harness table's entry; Known is false when the table lacks
	// the placement, which refuses it.
	Spec  harness.Placement
	Known bool
}

Target is one placement a zip item writes on this OS.

type ZipInstaller added in v1.11.0

type ZipInstaller struct {
	// Guard holds the OS, the write roots and the refusals every path passes.
	Guard     placement.Guard
	Harnesses harness.Table
	// ReceiptDir holds this installer's receipts.
	ReceiptDir string
	// Slug names the ownership marker and staging directories; identity.Slug
	// when empty.
	Slug string
	// CachePath and URLPackages locate archives: a variant's location is
	// downloaded from URLPackages+location to CachePath/location.
	CachePath   string
	URLPackages string
	// Managed reports whether a manifest lists item in managed_installs, for
	// the receipt's managed flag. Nil means never.
	Managed func(item string) bool
	// Held reports whether a held conditional block lists item. A held
	// item's managed flag is never rewritten: the run cannot tell whether it
	// is managed. Nil means nothing is held.
	Held func(item string) bool
	// Facts are the run's facts (pkg/facts), which placement file and tree
	// templates read through fact and cond. Nil means the machine has no
	// facts, so a template that reads one fails.
	Facts conditions.Facts
	// User is the login name, without domain, of the account this installer
	// runs as: the tree templates' .User in user scope. The service leaves
	// it empty; the per-user helper sets it.
	User string
	// contains filtered or unexported fields
}

ZipInstaller places the trees of zip items (site/src/content/docs/guides/zip-items.md). It holds no run state, so it works outside a managed run: the service builds one with NewMachineZip, and a per-user helper can build one with user roots and its own receipt directory.

func NewMachineZip added in v1.11.0

func NewMachineZip(cfg config.Configuration, table harness.Table) *ZipInstaller

NewMachineZip returns the service's zip installer for cfg and the repository's harness table: machine roots, receipts in the data directory.

func (*ZipInstaller) Apply added in v1.11.0

func (z *ZipInstaller) Apply(item catalog.Item, t Target, archive string) Result

Apply brings item's tree at t to the catalog version from archive, a verified copy of t's variant (see Fetch), following Inspect's decision. archive is read only when a tree is written: an adopted tree is rendered in place from the templates it holds, without the archive.

After it changes a marketplace placement (an install, an upgrade, or a receipt adopted or refreshed, as when only the managed flag changed) it regenerates the marketplace's generated files; a failure there fails the result.

func (*ZipInstaller) Fetch added in v1.11.0

func (z *ZipInstaller) Fetch(ctx context.Context, t Target, progress download.Progress) (string, error)

Fetch downloads t's archive into the cache unless a verified copy is there, and returns its path. Cancelling ctx aborts the download.

func (*ZipInstaller) Inspect added in v1.11.0

func (z *ZipInstaller) Inspect(item catalog.Item, t Target) Result

Inspect decides, without writing, what Apply would do for item at t (R14): missing; then a tree equal to its receipt's placed_hash, sofcat's own (current, adopted when the receipt or the rendered inputs are stale, or unchanged when the catalog moved on); then one equal to the catalog's tree_hash that sofcat did not place (adopted); then conflict.

func (*ZipInstaller) Installed added in v1.11.0

func (z *ZipInstaller) Installed(item catalog.Item) bool

Installed is a zip item's install status (R15), from receipts and placed trees only: true when every machine-scope placement for this OS has a receipt and a non-empty tree at the receipt's path, whatever its hash (current, older, or edited by the user). An edited tree is still sofcat's to remove, so a pending removal that met a conflict stays pending. An item with no machine-scope placement, a placement without a receipt, or a receipt whose tree is missing or empty is not installed.

func (*ZipInstaller) RegenerateAll added in v1.11.0

func (z *ZipInstaller) RegenerateAll() []Result

RegenerateAll regenerates every placement in the harness table that has generated files (generates) and a path on this OS, and returns a failed Result per placement that failed. A managed run calls it once, after scope exit, so a generated file deleted, refused or left stale by an earlier failure is restored even when no tree changes. A placement whose root does not exist is skipped: nothing was ever placed there, and an empty marketplace would only be clutter.

func (*ZipInstaller) Remove added in v1.11.0

func (z *ZipInstaller) Remove(rc receipt.Receipt) Result

Remove removes the tree rc records, under R15: only when the tree still matches the receipt's placed_hash. A tree already gone just drops the receipt. Like Apply, removing a marketplace plugin regenerates the generated files.

func (*ZipInstaller) Targets added in v1.11.0

func (z *ZipInstaller) Targets(item catalog.Item) (machine []Target, user []string)

Targets returns item's placements on this OS, in harness-table order, then any the table lacks, by name. Placements whose scope here is user are returned apart in user: a machine run skips them, neither failing nor succeeding the item.

Jump to

Keyboard shortcuts

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