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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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.