materialize

package
v1.235.0 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: Apache-2.0 Imports: 24 Imported by: 1 module, 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 materialize extracts verified artifact content into a local directory.

Extraction always happens in a private staging directory next to the destination, written through an os.Root so no entry can land outside it. Every path is validated against the Record inventory: traversal, entries absent from the inventory, escaping or chained symlinks, special members, size or digest mismatches, and oversize content are explicit errors. A newly pulled tree is never merged over old files: replacing an existing destination deletes the old children inside the destination root only and then moves the staged tree in. Ordinary permission bits (including executable bits) are restored exactly; owner, group, and ACLs never are.

Index

Constants

View Source
const DefaultMaxBytes int64 = 64 << 30

DefaultMaxBytes bounds the total declared size of extracted file content.

Variables

This section is empty.

Functions

func Extract

func Extract(ctx context.Context, content *artifact.Content, stage, scratch string, opts ...Option) error

Extract writes content into the empty directory stage, verifying every member against the Record inventory, checking that no symlink resolves outside stage, and applying final modes last. The scratch directory is private and holds temporary spool files. Extract does not close content.

func Materialize

func Materialize(ctx context.Context, content *artifact.Content, dest string, opts ...Option) error

Materialize extracts content into a private staging directory beside dest and then replaces dest with it. An existing destination is exchanged atomically with the staged tree. If atomic exchange is unavailable (including on Windows), replacing an existing directory fails without modifying it. The caller decides beforehand (see InspectDestination) whether replacement is permitted.

Types

type DestinationState

type DestinationState int

DestinationState classifies an output directory relative to the artifact being pulled.

const (
	// DestinationAbsent means the destination does not exist.
	DestinationAbsent DestinationState = iota

	// DestinationEmpty means the destination is an existing empty directory.
	DestinationEmpty

	// DestinationMatches means the destination already holds exactly the artifact's inventory.
	DestinationMatches

	// DestinationDiffers means the destination holds other content; replacing it requires force.
	DestinationDiffers
)

Destination states.

func InspectBoundDestination

func InspectBoundDestination(root *os.Root, record *artifact.Record) (DestinationState, error)

InspectBoundDestination classifies the directory held by root without resolving its pathname. The caller retains ownership of root and must keep it open throughout inspection.

func InspectDestination

func InspectDestination(dest string, record *artifact.Record) (DestinationState, error)

InspectDestination classifies dest without modifying it. A symlink or non-directory destination is an error: a replacement must never follow a link out of the requested root.

type Option

type Option func(*options)

Option customizes extraction.

func WithMaxBytes

func WithMaxBytes(limit int64) Option

WithMaxBytes overrides the limit on total extracted file content.

func WithOwnerAccess

func WithOwnerAccess() Option

WithOwnerAccess keeps owner read access on files and owner read and traversal access on directories, whatever modes the Record declares. It is for a temporary tree that is read back before it is discarded: a valid Record can declare mode 0000, and an ordinary user could not read such a tree. The Record itself is never changed.

func WithReplaceGuard

func WithReplaceGuard(guard func(dest *os.Root) error) Option

WithReplaceGuard registers a check that runs right before an existing destination directory is replaced, after extraction finished and the destination was bound. A caller uses it to re-check the destination state it decided on earlier, because the destination may have changed during the download. The guard must inspect through the supplied root, never reopen its Name. The caller must not close the root. A non-nil error aborts the replacement and leaves the destination untouched.

Jump to

Keyboard shortcuts

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