artifactcache

package
v0.23.9 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2026 License: MIT Imports: 15 Imported by: 1

Documentation

Overview

Package artifactcache acquires pinned publisher archives into a private, content-addressed cache. The trusted host owns the catalog, consent and paths; never construct a Spec from untrusted renderer or network input.

Index

Constants

This section is empty.

Variables

View Source
var ErrBusy = errors.New("archive cache is in use")
View Source
var ErrIntegrity = errors.New("archive integrity check failed")
View Source
var ErrInvalid = errors.New("invalid archive acquisition configuration")

Functions

func SelectSource added in v0.22.15

func SelectSource(ctx context.Context, specs []Spec, options Options) (int, error)

SelectSource probes a small representative set of trusted catalog entries and returns the source index with the lowest total probe latency. The canonical source remains the safe fallback when no source passes validation.

func Verify

func Verify(ctx context.Context, name string, spec Spec) error

Verify checks an existing regular file against the pinned length and digest. It never changes the file. Cancellation and filesystem errors remain distinct from ErrIntegrity; missing files retain their os.ErrNotExist classification.

Types

type Maintenance added in v0.9.0

type Maintenance struct {
	RemovedFiles int   `json:"removed_files"`
	RemovedBytes int64 `json:"removed_bytes"`
}

func Maintain added in v0.9.0

func Maintain(ctx context.Context, root string, policy Policy, try bool) (Maintenance, error)

Maintain skips an active cache when try is true. Callers may log maintenance failures independently of an already successful installation or transfer.

type Options

type Options struct {
	// Client is a trusted integration hook, primarily for network policy/tests.
	// Nil selects a client with a fifteen-minute timeout. HTTPS remains required.
	Client *http.Client
	// PreferredSource selects the first URL to try. -1 uses the canonical URL.
	// Remaining trusted URLs are tried in catalog order after it fails.
	PreferredSource int
	// OnProgress may stop acquisition by returning an error.
	OnProgress func(Progress) error
}

type Policy added in v0.9.0

type Policy struct {
	MaxIdleAge time.Duration
	MaxBytes   int64
}

Policy is opt-in. Zero disables the corresponding eviction limit. MaxBytes counts verified archive files, not locks or temporary bundles.

type Progress

type Progress struct {
	Phase         string
	ReceivedBytes int64
	TotalBytes    int64
}

Progress reports absolute byte counts. Phase is checking, downloading or verifying. Cache validation performs no network request.

type Result

type Result struct {
	Path      string
	FromCache bool
}

func Acquire

func Acquire(ctx context.Context, root string, spec Spec, options Options) (Result, error)

Acquire revalidates cached bytes or downloads and atomically publishes the exact archive. root must be an absolute private directory owned by the host. Concurrent calls share an exclusive cache lease and recheck after waiting. A verified cache entry is never deleted by cancellation. Returned paths must not be used concurrently with maintenance; use Session for protected reads.

type Session added in v0.9.0

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

Session owns an exclusive OS lease until Close. Consumers must keep it open through their last archive read. Methods are used sequentially by the owner. A session is not an authorization boundary; root belongs to the trusted host.

func OpenSession added in v0.9.0

func OpenSession(ctx context.Context, root string, options SessionOptions) (*Session, error)

func (*Session) Acquire added in v0.9.0

func (s *Session) Acquire(ctx context.Context, spec Spec, options Options) (Result, error)

func (*Session) Close added in v0.9.0

func (s *Session) Close() error

func (*Session) Path added in v0.9.0

func (s *Session) Path(spec Spec) (string, error)

func (*Session) Prune added in v0.9.0

func (s *Session) Prune(ctx context.Context, policy Policy) (Maintenance, error)

Prune only removes recognized regular files under the exclusive lease. It never follows symlinks, unlinks lock files, or examines unrelated subdirectories.

func (*Session) Touch added in v0.9.0

func (s *Session) Touch(spec Spec) error

Touch records successful use without changing archive bytes. Existing archives need no migration; their original modification time is the initial last use.

func (*Session) Verify added in v0.9.0

func (s *Session) Verify(ctx context.Context, spec Spec) error

type SessionOptions added in v0.9.0

type SessionOptions struct {
	Try    bool
	OnWait func() error
}

type Spec

type Spec struct {
	URL       string
	Mirrors   []string
	SHA256    string
	SizeBytes int64
}

Spec describes exact original publisher bytes selected by the trusted host.

Jump to

Keyboard shortcuts

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