store

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2026 License: MIT Imports: 13 Imported by: 0 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

Overview

Package store installs, upgrades, lists and removes reviewed packages under a caller-supplied root. A package is a packagekit manifest plus the artifacts it lists. The store has no default location and no product vocabulary; it copies and re-verifies content but never launches it or grants authority. Concurrent mutation from several processes is the caller's responsibility.

Index

Constants

View Source
const (
	// DefaultMaxTreeFiles bounds the files in one tree artifact.
	DefaultMaxTreeFiles = 250000
	// DefaultMaxTreeBytes bounds the total size of one tree artifact.
	DefaultMaxTreeBytes int64 = 16 << 30
)

Defaults for Limits.

View Source
const DefaultMaxArtifactBytes int64 = 4 << 30

DefaultMaxArtifactBytes bounds one artifact when Limits does not.

View Source
const ManifestName = "plugin.json"

ManifestName is the manifest file at the top of every package directory: the ext.package/v1 document. A package.json at the top level is an ordinary file, which a package may ship as an artifact (an npm package, say) like any other; only this name is read as the manifest. An artifact may not use this path, whatever its case, and a tree may hold a file of this name of its own.

Variables

View Source
var (
	ErrExists   = errors.New("plugin package already installed")
	ErrNotFound = errors.New("plugin package not installed")
)

Functions

func WriteManifest

func WriteManifest(dir string, m packagekit.Manifest) error

WriteManifest validates m and writes it as ManifestName in dir, for authors assembling a package directory that Install will copy.

Types

type Check

type Check struct {
	// ID is the package ID, or the directory name when it is not a valid one.
	ID string
	// Directory is where the entry lives.
	Directory string
	// Err is why the entry failed: a manifest that does not decode or validate,
	// an artifact that is missing, changed, linked or oversized, an unlisted
	// file, a directory that does not match its manifest, or an entry that is
	// not a package directory. Nil means the package verified.
	Err error
}

Check is the verification result for one entry under a store root.

func (Check) OK

func (c Check) OK() bool

OK reports whether the entry verified.

type Installed

type Installed struct {
	Manifest  packagekit.Manifest
	Directory string
	// contains filtered or unexported fields
}

Installed is one package directory. Methods re-verify content on use.

func (Installed) ArtifactPath

func (p Installed) ArtifactPath(name string) (string, error)

ArtifactPath verifies the named artifact and returns its filesystem path (under Directory): a file, or for a tree artifact its directory. Use it to locate source files, a vendored tree or an executable.

func (Installed) Digest

func (p Installed) Digest() (string, error)

Digest returns the directory digest of the verified package directory, for consumers that record trust against exact installed content.

func (Installed) Executable

func (p Installed) Executable() (string, error)

Executable returns the digest-verified path of the first entrypoint's artifact. A package without entrypoints returns plugin.ErrNotFound.

func (Installed) IsExecutable

func (p Installed) IsExecutable() bool

IsExecutable reports whether the package declares an entrypoint, as opposed to shipping source files the consumer runs under a runtime it owns.

func (Installed) Name

func (p Installed) Name() string

Name is the package identity ID.

func (Installed) Supports

func (p Installed) Supports(name, version string) bool

Supports reports whether the package serves an exact contract version.

func (Installed) Verify

func (p Installed) Verify() error

Verify rechecks the manifest, every listed artifact (type, size, digest) and that the directory holds nothing else, so Digest is stable and complete.

func (Installed) Version

func (p Installed) Version() string

Version is the package release version, which may be empty.

type Layered

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

Layered is a read-only view over several stores. Earlier stores shadow later ones: a package ID is served from the first store that holds it, so a user installation can override a system one. It has no default roots and no product vocabulary; the consumer decides which roots exist and their order, for example a user root followed by a read-only system root.

Layered never writes. Install, upgrade and remove stay on the Store the caller owns, so a system root is never created or modified through it.

Shadowing is by ID only. If the winning copy fails verification, Load and List fail closed instead of falling back to a copy in a later store: a damaged override must not silently turn into a different package. A shadowed copy is never read or verified.

func NewLayered

func NewLayered(stores ...*Store) (*Layered, error)

NewLayered returns a view over stores in priority order, highest first. It needs at least one store and rejects nil entries and repeated roots.

func (*Layered) List

func (l *Layered) List() ([]Installed, error)

List verifies and returns one package per ID, sorted by ID, each from the highest-priority store that holds it. It fails closed on the first bad package or unexpected entry in any store. A missing root is empty.

func (*Layered) ListUnverified

func (l *Layered) ListUnverified() ([]Installed, []Check, error)

ListUnverified returns one package's manifest per ID, each from the highest-priority store that holds it, without verifying any content, and reports the packages it could not read separately. See Store.ListUnverified: the result is unverified, content is checked only by Installed.Verify, host.Open and ArtifactPath, and that check is against the manifest read at listing time. Shadowing is as in List and Verify: an ID belongs to the highest-priority store whose directory holds it, even if that copy cannot be read, in which case it is reported rather than replaced by a copy in a later store; a shadowed copy is never read. An entry that is not a package directory is reported in the store it sits in. Results are sorted by ID. The error is only for a root that cannot be read.

func (*Layered) Load

func (l *Layered) Load(id string) (Installed, error)

Load returns the verified package from the first store that holds id. ErrNotFound means no store holds it.

func (*Layered) Roots

func (l *Layered) Roots() []string

Roots returns the store roots in priority order. An Installed package's Directory lies under the root of the store that served it.

func (*Layered) Verify

func (l *Layered) Verify() ([]Check, error)

Verify checks what Load and List would serve and reports every failure instead of stopping at the first. A package is checked in the highest-priority store that holds it; shadowed copies are skipped, as in List. An entry that is not a package directory is reported in the store it sits in. It runs nothing and changes nothing. Results are sorted by ID, then by store priority. The error is only for a root that cannot be read.

type Limits

type Limits struct {
	// MaxArtifactBytes bounds one file, including each file inside a tree.
	MaxArtifactBytes int64
	// MaxTreeFiles bounds the files in one tree artifact.
	MaxTreeFiles int
	// MaxTreeBytes bounds the total bytes of one tree artifact.
	MaxTreeBytes int64
}

Limits are optional size bounds. Zero values use defaults.

type Store

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

func New

func New(root string, limits Limits) (*Store, error)

New returns a store rooted at root. The directory is created on first install. root must be supplied by the consumer.

func (*Store) Install

func (s *Store) Install(source string) (Installed, error)

Install copies the package in source (a directory holding ManifestName and the listed artifacts) into the store. It never replaces an existing package.

func (*Store) List

func (s *Store) List() ([]Installed, error)

List verifies every installed package and fails closed on the first bad one. A missing root is an empty store. Staging directories (leading ".") are skipped.

func (*Store) ListUnverified

func (s *Store) ListUnverified() ([]Installed, []Check, error)

ListUnverified returns every installed package's manifest and directory without verifying any content, and reports the packages it could not read separately. It is for a caller that needs to know what is installed, such as a catalog or a picker, and cannot afford to hash every artifact: it costs one directory listing and one small manifest read per package, whatever the size of the artifacts, where List hashes them all.

THE RESULT IS UNVERIFIED. A returned package has a manifest that decodes and validates and a directory that matches it, nothing more: artifacts may be missing, changed, linked, unlisted or oversized. Content is checked only by Installed.Verify, by host.Open (which verifies before it launches) and by ArtifactPath and Executable (which verify the artifact they return). Do not launch, load or trust anything from this result directly, and do not take its presence as proof that the package would pass List or Load. Name, Version, Supports and IsExecutable read only the manifest and are safe to use.

A returned Installed carries the manifest read at listing time, and Verify, host.Open and ArtifactPath check content against that manifest, not against whatever plugin.json holds later. If the manifest on disk changes after the listing, list again to see the change.

A package that cannot be read does not hide the others. Each one is reported in the second result, in the same form Verify uses: its ID (the directory name when that is not a valid ID), its directory and why, which is a manifest that does not decode or validate, a directory that does not match its manifest, or an entry that is not a package directory. Every Check returned here has a non-nil Err. Both results are sorted by ID. The error is only for a root that cannot be read; a missing root is empty. Staging directories (leading ".") are skipped.

List and Load are unchanged and still fail closed.

func (*Store) Load

func (s *Store) Load(id string) (Installed, error)

Load reads and verifies one installed package.

func (*Store) Remove

func (s *Store) Remove(id string) error

Remove deletes one installed package directory. It never follows links.

func (*Store) Root

func (s *Store) Root() string

func (*Store) Upgrade

func (s *Store) Upgrade(source string) (Installed, error)

Upgrade replaces an installed package with a new revision of the same ID. Contract names and versions must match; operations may change, so the caller must re-review authority. The previous installation survives any failure.

func (*Store) Verify

func (s *Store) Verify() ([]Check, error)

Verify checks every package under the root and reports each one. Unlike List it does not stop at the first bad package, so a caller can show everything that is wrong. It runs nothing and changes nothing. Results are sorted by ID. The error is only for a root that cannot be read; a missing root is empty.

Jump to

Keyboard shortcuts

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