archive

package
v0.0.0-...-3bfe646 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2023 License: Apache-2.0 Imports: 20 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrAbort = errors.New("abort iteration")

ErrAbort is a special error value used to abort an iteration

Functions

func AssertArchiveHasFiles

func AssertArchiveHasFiles(c *C, r io.ReadCloser, excludePatterns []string, filenames ...string)

AssertArchiveHasFiles validates that filenames are in the archive r.

func AssertArchiveHasItems

func AssertArchiveHasItems(c *C, r io.ReadCloser, excludePatterns []string, items ...TestItem)

AssertArchiveHasItems validates that items are in the archive r.

func AssertDirHasFiles

func AssertDirHasFiles(c *C, dir string, files ...TestFile)

AssertDirHasFiles validates that directory dir has files.

func CompressDirectory

func CompressDirectory(dir string, writer io.Writer, items ...*Item) error

CompressDirectory compresses the directory given with dir, using writer as a sink for the archive

func CreateMemArchive

func CreateMemArchive(items []*Item) (*bytes.Buffer, error)

CreateMemArchive creates in-memory archive from archive items

func DefaultOptions

func DefaultOptions() *dockerarchive.TarOptions

DefaultOptions returns an options object with sensible defaults

func Extract

func Extract(r io.Reader, dir string) error

Extract extracts the contents of the specified tarball under dir. The resulting files and directories are created using the current user context.

func ExtractWithPrefix

func ExtractWithPrefix(r io.Reader, dir, tarDirPrefix string) error

ExtractWithPrefix extracts the contents of the specified tarball under directory dir. Only the files/directories found in tarDirPrefix in the tarball matching patterns are extracted. Note, files from tarDir are written directly to dir omitting tarDir. The resulting files and directories are created using the current user context.

func FetchFiles

func FetchFiles(r io.ReadCloser, excludePatterns []string) (map[string]string, error)

FetchFiles fetches archive files as map

func GetChownOptionsForDir

func GetChownOptionsForDir(dir string) (*idtools.Identity, error)

GetChownOptionsForDir returns the ownership options for the specified directory dir. It will use the same options if directory already exists, and will fall back to current user otherwise

func HasFile

func HasFile(tarballPath, filename string) error

HasFile returns nil if the specified tarball contains specified file

func MustCreateMemArchive

func MustCreateMemArchive(items []*Item) *bytes.Buffer

MustCreateMemArchive creates in-memory archive from archive items

func PathMatch

func PathMatch(pattern PathPattern, path string) (bool, error)

PathMatch matches path against the specified path pattern. The pattern can use double-asterisks (`**`) to denote arbitrary intermediate directories in the path. Returns True upon a successful match and error if the pattern is invalid. Based on docker/docker/pkg/fileutils/fileutils#regexpMatch

func SanitizeTarPath

func SanitizeTarPath(header *tar.Header, dir string) error

SanitizeTarPath checks that the tar header paths resolve to a subdirectory path, and don't contain file paths or links that could escape the tar file (e.g. ../../etc/passwrd)

func TarGlob

func TarGlob(source *tar.Reader, dir string, patterns []string, handler func(match string, file io.Reader) error) (err error)

TarGlob iterates the contents of the specified tarball and invokes handler for each file matching the list of specified patterns. If the handler returns a special Abort error, iteration will be aborted without errors.

func TarGlobWithPrefix

func TarGlobWithPrefix(source *tar.Reader, prefix string, handler TarGlobHandler) (err error)

TarGlobWithPrefix iterates the contents of the specified tarball and invokes handler for each file in the directory with the specified prefix (and all its sub-directories). If the handler returns a special Abort error, iteration will be aborted without errors.

func Unpack

func Unpack(path string) (unpackedDir string, err error)

Unpack unpacks the specified tarball to a temporary directory and returns the directory where it was unpacked

Types

type Filename

type Filename string

func (Filename) AssertItem

func (r Filename) AssertItem(*C, *tar.Reader, *tar.Header)

func (Filename) SameName

func (r Filename) SameName(name string) bool

type Item

type Item struct {
	tar.Header
	// Data is the data payload
	Data io.ReadCloser
}

Item defines a unit of compression

func DirItem

func DirItem(path string) *Item

DirItem creates a new virtual directory item

func ItemFromFile

func ItemFromFile(localPath, path string, fi os.FileInfo) (*Item, error)

ItemFromFile creates an Item from the specified file

func ItemFromStream

func ItemFromStream(path string, rc io.ReadCloser, size, mode int64) *Item

ItemFromStream creates an Item from given io.ReadCloser

func ItemFromString

func ItemFromString(path, value string) *Item

ItemFromString creates an Item from given string

func ItemFromStringMode

func ItemFromStringMode(path, value string, mode int64) *Item

ItemFromStringMode creates a new Item from a given string with the provided permissions

type NameMatcher

type NameMatcher interface {
	SameName(name string) bool
}

type PathPattern

type PathPattern string

PathPattern defines a type for a file path pattern

type TarAppender

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

TarAppender wraps a tar writer and can append items to it

func NewTarAppender

func NewTarAppender(w io.Writer) *TarAppender

NewTarAppender creates a new tar appender writing to w

func (*TarAppender) Add

func (r *TarAppender) Add(items ...*Item) (err error)

Add adds the specified items to the underlined archive

func (*TarAppender) Close

func (r *TarAppender) Close() error

Close closes the underlined archive

type TarGlobHandler

type TarGlobHandler func(match *tar.Header, r *tar.Reader) error

TarGlobHandler defines a handler for the match when iterating files in the tarball r.

type TestFile

type TestFile interface {
	NameMatcher
	AssertFile(c *C, path string, fi os.FileInfo)
}

type TestItem

type TestItem interface {
	NameMatcher
	AssertItem(c *C, tarball *tar.Reader, hdr *tar.Header)
}

Jump to

Keyboard shortcuts

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