Documentation
¶
Overview ¶
Package archive provides archive creation and manipulation functionality.
This package implements a focused subset of tar/zip handling needed by YAP:
- Create compressed tar archives (.tar.zst / .tar.gz / .tar.xz) used as intermediate artifacts and as the on-disk format for Pacman / APK packages.
- Extract a small set of recognized archive types to disk: tar (plain or wrapped in gzip / zstd / xz / bz2) and zip. Other formats (rar, 7z, …) return the ErrUnrecognizedArchive sentinel so callers can fall through to a system binary or treat it as a no-op.
All extraction paths defend against zip-slip path traversal via safeJoin and against malicious symlink targets via safeSymlinkTarget.
Index ¶
- Variables
- func CreateTarCompressed(ctx context.Context, sourceDir, outputFile, compression string, formatGNU bool) error
- func CreateTarZst(ctx context.Context, sourceDir, outputFile string, formatGNU bool) error
- func Extract(ctx context.Context, source, destination string) error
- func ExtractFiltered(ctx context.Context, source, destination string, patterns []string) error
- func SafeJoin(destination, name string) (string, error)
- func SafeSymlinkTarget(entryName, target string) error
Constants ¶
This section is empty.
Variables ¶
var ErrUnrecognizedArchive = stderrors.New("archive format not recognized")
ErrUnrecognizedArchive is returned by Extract / ExtractFiltered when the input file's format is not recognized as an extractable archive. Callers that legitimately accept non-archive inputs (e.g. plain patch files in pkg/source.Source.Get) can detect this sentinel and treat it as a no-op; callers that expect a real archive should treat it as a hard error.
Functions ¶
func CreateTarCompressed ¶
func CreateTarCompressed( ctx context.Context, sourceDir, outputFile, compression string, formatGNU bool, ) error
CreateTarCompressed creates a compressed tar archive with the specified compression algorithm from the source directory. Supported compression algorithms are "zstd", "gzip", and "xz". If compression is empty, defaults to "zstd". Returns an error if the compression algorithm is unsupported.
formatGNU selects tar.FormatGNU when true (used for Pacman packages); the default is tar.FormatPAX (used for APK and source bundles).
func CreateTarZst ¶
CreateTarZst creates a compressed tar.zst archive from the specified source directory. This is a convenience wrapper around CreateTarCompressed that defaults to zstd compression.
func Extract ¶
Extract extracts an archive file to the specified destination directory. Supported formats: tar (plain or gzip / zstd / xz / bz2 wrapped) and zip. Returns ErrUnrecognizedArchive for any other input.
func ExtractFiltered ¶
ExtractFiltered extracts an archive file to the destination directory, only including entries whose name matches one of the provided glob patterns (filepath.Match semantics). If patterns is empty every entry is extracted.
func SafeJoin ¶ added in v2.0.5
SafeJoin is the exported wrapper around safeJoin, exposed for callers in sibling packages (e.g. pkg/builders/common.extractAPK) that need the same containment guarantee when extracting custom archive formats.
func SafeSymlinkTarget ¶ added in v2.0.5
SafeSymlinkTarget is the exported wrapper around safeSymlinkTarget. entryName is the path of the symlink itself within the archive (e.g. "opt/foo/sbin/slapacl"); target is the symlink target as stored in the archive (e.g. "../libexec/slapd").
Types ¶
This section is empty.