file

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2024 License: Apache-2.0 Imports: 20 Imported by: 32

Documentation

Index

Constants

View Source
const (
	WhiteoutPrefix = ".wh."
	OpaqueWhiteout = WhiteoutPrefix + WhiteoutPrefix + ".opq"
	DirSeparator   = "/"
)
View Source
const (
	KB = 1 << (10 * iota)
	MB
	GB
)

Variables

View Source
var ErrTarStopIteration = fmt.Errorf("halt iterating tar")

Functions

func IterateTar

func IterateTar(reader io.Reader, visitor TarFileVisitor) error

IterateTar is a function that reads across a tar and invokes a visitor function for each entry discovered. The iterator stops when there are no more entries to read, if there is an error in the underlying reader or visitor function, or if the visitor function returns a ErrTarStopIteration sentinel error.

func MIMEType

func MIMEType(reader io.Reader) string

MIMEType attempts to guess at the MIME type of a file given the contents. If there is no contents, then an empty string is returned. If the MIME type could not be determined and the contents are not empty, then a MIME type of "application/octet-stream" is returned.

func ReaderFromTar

func ReaderFromTar(reader io.ReadCloser, tarPath string) (io.ReadCloser, error)

ReaderFromTar returns a io.ReadCloser for the Path within a tar file.

func UntarToDirectory

func UntarToDirectory(reader io.Reader, dst string) error

UntarToDirectory writes the contents of the given tar reader to the given destination. Note: this is meant to handle archives for images (not image contents) thus intentionally does not handle links or any kinds of special files.

func WalkSquashFS

func WalkSquashFS(r io.ReaderAt, fn SquashFSVisitor) error

WalkSquashFS walks the file tree within the SquashFS filesystem read from r, calling fn for each file or directory in the tree, including root.

func WalkSquashFSFromReader

func WalkSquashFSFromReader(r io.Reader, fn SquashFSVisitor) error

WalkSquashFSFromReader walks the file tree within the SquashFS filesystem read from r, calling fn for each file or directory in the tree, including root. Callers should use WalkSquashFS where possible, as this function is considerably less efficient.

Types

type ErrFileNotFound

type ErrFileNotFound struct {
	Path string
}

ErrFileNotFound returned from ReaderFromTar if a file is not found in the given archive.

func (*ErrFileNotFound) Error

func (e *ErrFileNotFound) Error() string

type ID

type ID uint64

ID is used for file tree manipulation to uniquely identify tree nodes.

type IDSet

type IDSet map[ID]struct{}

func NewIDSet

func NewIDSet(is ...ID) IDSet

func (IDSet) Add

func (s IDSet) Add(ids ...ID)

func (IDSet) Clear

func (s IDSet) Clear()

func (IDSet) Contains

func (s IDSet) Contains(i ID) bool

func (IDSet) ContainsAny

func (s IDSet) ContainsAny(ids ...ID) bool

func (IDSet) List

func (s IDSet) List() []ID

func (IDSet) Merge

func (s IDSet) Merge(other IDSet)

func (IDSet) Remove

func (s IDSet) Remove(ids ...ID)

func (IDSet) Size

func (s IDSet) Size() int

func (IDSet) Sorted

func (s IDSet) Sorted() []ID

type IDs

type IDs []ID

func (IDs) Len

func (ids IDs) Len() int

func (IDs) Less

func (ids IDs) Less(i, j int) bool

func (IDs) Swap

func (ids IDs) Swap(i, j int)

type LazyReadCloser

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

LazyReadCloser is a "lazy" read closer, allocating a file descriptor for the given path only upon the first Read() call.

func NewLazyReadCloser

func NewLazyReadCloser(path string) *LazyReadCloser

NewLazyReadCloser creates a new LazyReadCloser for the given path.

func (*LazyReadCloser) Close

func (d *LazyReadCloser) Close() error

Close implements the io.Closer interface for the previously loaded path / opened file.

func (*LazyReadCloser) Read

func (d *LazyReadCloser) Read(b []byte) (n int, err error)

Read implements the io.Reader interface for the previously loaded path, opening the file upon the first invocation.

func (*LazyReadCloser) ReadAt

func (d *LazyReadCloser) ReadAt(p []byte, off int64) (n int, err error)

func (*LazyReadCloser) Seek

func (d *LazyReadCloser) Seek(offset int64, whence int) (int64, error)

type ManualInfo

type ManualInfo struct {
	NameValue    string
	SizeValue    int64
	ModeValue    fs.FileMode
	ModTimeValue time.Time
	SysValue     any
}

func (ManualInfo) IsDir

func (m ManualInfo) IsDir() bool

func (ManualInfo) ModTime

func (m ManualInfo) ModTime() time.Time

func (ManualInfo) Mode

func (m ManualInfo) Mode() fs.FileMode

func (ManualInfo) Name

func (m ManualInfo) Name() string

func (ManualInfo) Size

func (m ManualInfo) Size() int64

func (ManualInfo) Sys

func (m ManualInfo) Sys() any

type Metadata

type Metadata struct {
	fs.FileInfo

	// Path is the absolute path representation to the file
	Path string
	// LinkDestination is populated only for hardlinks / symlinks, can be an absolute or relative
	LinkDestination string
	UserID          int
	GroupID         int
	Type            Type
	MIMEType        string
}

Metadata represents all file metadata of interest.

func MetadataFromTar

func MetadataFromTar(reader io.ReadCloser, tarPath string) (Metadata, error)

MetadataFromTar returns the tar metadata from the header info.

func NewMetadata

func NewMetadata(header tar.Header, content io.Reader) Metadata

func NewMetadataFromPath

func NewMetadataFromPath(path string, info os.FileInfo) Metadata

func NewMetadataFromSquashFSFile

func NewMetadataFromSquashFSFile(path string, f *squashfs.File) (Metadata, error)

NewMetadataFromSquashFSFile populates Metadata for the entry at path, with details from f.

func (Metadata) Equal

func (m Metadata) Equal(other Metadata) bool

type Opener

type Opener func() io.ReadCloser

type Path

type Path string

Path represents a file path

func (Path) AllPaths

func (p Path) AllPaths() []Path

AllPaths returns all constituent paths of the current path + the current path itself (e.g. /home/wagoodman/file.txt -> /, /home, /home/wagoodman, /home/wagoodman/file.txt )

func (Path) Basename

func (p Path) Basename() string

Basename of the path (i.e. filename)

func (Path) ConstituentPaths

func (p Path) ConstituentPaths() []Path

ConstituentPaths returns all constituent paths for the current path (not including the current path itself) (e.g. /home/wagoodman/file.txt -> /, /home, /home/wagoodman )

func (Path) IsAbsolutePath

func (p Path) IsAbsolutePath() bool

func (Path) IsDirWhiteout

func (p Path) IsDirWhiteout() bool

IsDirWhiteout indicates if the path has a basename is a opaque whiteout (which means all parent directory contents should be ignored during squashing)

func (Path) IsWhiteout

func (p Path) IsWhiteout() bool

IsWhiteout indicates if the file basename has a whiteout prefix (which means that the file should be removed during squashing)

func (Path) Normalize

func (p Path) Normalize() Path

Normalize returns the cleaned file path representation (trimmed of spaces and resolve relative notations)

func (Path) ParentPath

func (p Path) ParentPath() (Path, error)

ParentPath returns a path object to the current files parent directory (or errors out if there is no parent)

func (Path) UnWhiteoutPath

func (p Path) UnWhiteoutPath() (Path, error)

UnWhiteoutPath is a representation of the current path with no whiteout prefixes

type PathCountSet

type PathCountSet map[Path]int

func NewPathCountSet

func NewPathCountSet(is ...Path) PathCountSet

func (PathCountSet) Add

func (s PathCountSet) Add(ids ...Path)

func (PathCountSet) Contains

func (s PathCountSet) Contains(i Path) bool

func (PathCountSet) Remove

func (s PathCountSet) Remove(ids ...Path)

type PathSet

type PathSet map[Path]struct{}

func NewPathSet

func NewPathSet(is ...Path) PathSet

func (PathSet) Add

func (s PathSet) Add(ids ...Path)

func (PathSet) Clear

func (s PathSet) Clear()

func (PathSet) Contains

func (s PathSet) Contains(i Path) bool

func (PathSet) ContainsAny

func (s PathSet) ContainsAny(ids ...Path) bool

func (PathSet) List

func (s PathSet) List() []Path

func (PathSet) Merge

func (s PathSet) Merge(other PathSet)

func (PathSet) Remove

func (s PathSet) Remove(ids ...Path)

func (PathSet) Size

func (s PathSet) Size() int

func (PathSet) Sorted

func (s PathSet) Sorted() []Path

type PathStack

type PathStack []Path

func (*PathStack) Pop

func (s *PathStack) Pop() Path

func (*PathStack) Push

func (s *PathStack) Push(n Path)

func (*PathStack) Size

func (s *PathStack) Size() int

type Paths

type Paths []Path

func (Paths) Len

func (p Paths) Len() int

func (Paths) Less

func (p Paths) Less(i, j int) bool

func (Paths) Swap

func (p Paths) Swap(i, j int)

type Reference

type Reference struct {
	RealPath Path // file path with NO symlinks or hardlinks in constituent paths
	// contains filtered or unexported fields
}

Reference represents a unique file. This is useful when path is not good enough (i.e. you have the same file path for two files in two different container image layers, and you need to be able to distinguish them apart)

func NewFileReference

func NewFileReference(path Path) *Reference

NewFileReference creates a new unique file reference for the given path.

func (*Reference) ID

func (f *Reference) ID() ID

ID returns the unique ID for this file reference.

func (*Reference) String

func (f *Reference) String() string

String returns a string representation of the path with a unique ID.

type ReferenceSet

type ReferenceSet map[ID]struct{}

ReferenceSet is a set of file references

func NewFileReferenceSet

func NewFileReferenceSet() ReferenceSet

NewFileReferenceSet creates a new ReferenceSet instance.

func (ReferenceSet) Add

func (s ReferenceSet) Add(ref Reference)

Add the ID of the given file reference to the set.

func (ReferenceSet) Contains

func (s ReferenceSet) Contains(ref Reference) bool

Contains indicates if the given file reference ID is already contained in this set.

func (ReferenceSet) Remove

func (s ReferenceSet) Remove(ref Reference)

Remove the ID of the given file reference from the set.

type References

type References []*Reference

References is a slice of file references (useful for attaching sorting-related methods)

func (References) Equal

func (f References) Equal(other References) bool

func (References) Len

func (f References) Len() int

func (References) Less

func (f References) Less(idx1, idx2 int) bool

func (References) Swap

func (f References) Swap(idx1, idx2 int)

type Resolution

type Resolution struct {
	RequestPath Path
	*Reference
	// LinkResolutions represents the traversal through the filesystem to access to current reference, including all symlink and hardlink resolution.
	// note: today this only shows resolutions via the basename of the request path, but in the future it may show all resolutions.
	LinkResolutions []Resolution
}

Resolution represents the fetching of a possibly non-existent file via a request path.

func NewResolution

func NewResolution(path Path, ref *Reference, leafs []Resolution) *Resolution

NewResolution create a new Resolution for the given request path, showing the resolved reference (or nil if it does not exist), and the link resolution of the basename of the request path transitively.

func (*Resolution) AllPaths

func (f *Resolution) AllPaths() []Path

func (*Resolution) AllRequestPaths

func (f *Resolution) AllRequestPaths() []Path

func (*Resolution) HasReference

func (f *Resolution) HasReference() bool

func (*Resolution) References

func (f *Resolution) References() []Reference

References represents the traversal through the filesystem to access to current reference, including all symlink and hardlink resolution.

func (*Resolution) RequestResolutionPath

func (f *Resolution) RequestResolutionPath() []Path

RequestResolutionPath represents the traversal through the filesystem to access to current reference, including all symlink and hardlink resolution.

type Resolutions

type Resolutions []Resolution

func (Resolutions) Len

func (f Resolutions) Len() int

func (Resolutions) Less

func (f Resolutions) Less(i, j int) bool

func (Resolutions) Swap

func (f Resolutions) Swap(i, j int)

type SquashFSVisitor

type SquashFSVisitor func(fsys fs.FS, path string, d fs.DirEntry) error

SquashFSVisitor is the type of the function called by WalkSquashFS to visit each file or directory.

The path argument contains the full path, and d is the corresponding fs.DirEntry.

The error result returned by the function controls how WalkSquashFS continues. If the function returns the special value fs.SkipDir, WalkSquashFS skips the current directory (path if d.IsDir() is true, otherwise path's parent directory). Otherwise, if the function returns a non- nil error, WalkSquashFS stops entirely and returns that error.

type TarFileEntry

type TarFileEntry struct {
	Sequence int64
	Header   tar.Header
	Reader   io.Reader
}

TarFileEntry represents the header, contents, and list position of an entry within a tar file.

type TarFileVisitor

type TarFileVisitor func(TarFileEntry) error

TarFileVisitor is a visitor function meant to be used in conjunction with the IterateTar.

type TarIndex

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

TarIndex is a tar reader capable of O(1) fetching of entry contents after the first read.

func NewTarIndex

func NewTarIndex(tarFilePath string, onIndex TarIndexVisitor) (*TarIndex, error)

NewTarIndex creates a new TarIndex that is already indexed.

func (*TarIndex) EntriesByName

func (t *TarIndex) EntriesByName(name string) ([]TarFileEntry, error)

EntriesByName fetches all TarFileEntries for the given tar header name.

type TarIndexEntry

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

func (*TarIndexEntry) Open

func (t *TarIndexEntry) Open() io.ReadCloser

func (*TarIndexEntry) ToTarFileEntry

func (t *TarIndexEntry) ToTarFileEntry() TarFileEntry

type TarIndexVisitor

type TarIndexVisitor func(TarIndexEntry) error

type TempDirGenerator

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

func NewTempDirGenerator

func NewTempDirGenerator(name string) *TempDirGenerator

func (*TempDirGenerator) Cleanup

func (t *TempDirGenerator) Cleanup() error

Cleanup deletes all temp dirs created by this generator and any child generator.

func (*TempDirGenerator) NewDirectory

func (t *TempDirGenerator) NewDirectory(name ...string) (string, error)

NewDirectory creates a new temp dir within the generators prefix temp dir.

func (*TempDirGenerator) NewGenerator

func (t *TempDirGenerator) NewGenerator() *TempDirGenerator

NewGenerator creates a child generator capable of making sibling temp directories.

type Type

type Type int
const (
	TypeRegular Type = iota
	TypeHardLink
	TypeSymLink
	TypeCharacterDevice
	TypeBlockDevice
	TypeDirectory
	TypeFIFO
	TypeSocket
	TypeIrregular
)

func AllTypes

func AllTypes() []Type

func TypeFromMode

func TypeFromMode(mode os.FileMode) Type

func TypeFromTarType

func TypeFromTarType(ty byte) Type

func (Type) String

func (t Type) String() string

Jump to

Keyboard shortcuts

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