Documentation ¶
Index ¶
- Constants
- Variables
- func IterateTar(reader io.Reader, visitor TarFileVisitor) error
- func MIMEType(reader io.Reader) string
- func ReaderFromTar(reader io.ReadCloser, tarPath string) (io.ReadCloser, error)
- func UntarToDirectory(reader io.Reader, dst string) error
- func WalkSquashFS(sqfsPath string, fn SquashFSVisitor) error
- type ErrFileNotFound
- type ID
- type IDSet
- type IDs
- type LazyReadCloser
- type ManualInfo
- type Metadata
- type Opener
- type Path
- func (p Path) AllPaths() []Path
- func (p Path) Basename() string
- func (p Path) ConstituentPaths() []Path
- func (p Path) IsAbsolutePath() bool
- func (p Path) IsDirWhiteout() bool
- func (p Path) IsWhiteout() bool
- func (p Path) Normalize() Path
- func (p Path) ParentPath() (Path, error)
- func (p Path) UnWhiteoutPath() (Path, error)
- type PathCountSet
- type PathSet
- func (s PathSet) Add(ids ...Path)
- func (s PathSet) Clear()
- func (s PathSet) Contains(i Path) bool
- func (s PathSet) ContainsAny(ids ...Path) bool
- func (s PathSet) List() []Path
- func (s PathSet) Merge(other PathSet)
- func (s PathSet) Remove(ids ...Path)
- func (s PathSet) Size() int
- func (s PathSet) Sorted() []Path
- type PathStack
- type Paths
- type Reference
- type ReferenceSet
- type References
- type Resolution
- type Resolutions
- type SquashFSVisitor
- type TarFileEntry
- type TarFileVisitor
- type TarIndex
- type TarIndexEntry
- type TarIndexVisitor
- type TempDirGenerator
- type Type
Constants ¶
const ( WhiteoutPrefix = ".wh." OpaqueWhiteout = WhiteoutPrefix + WhiteoutPrefix + ".opq" DirSeparator = "/" )
const ( KB = 1 << (10 * iota) MB GB )
Variables ¶
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 ¶
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 ¶
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(sqfsPath string, fn SquashFSVisitor) error
WalkSquashFS walks the file tree within the SquashFS filesystem at sqfsPath, calling fn for each file or directory in the tree, including root.
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 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.
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 NewMetadataFromSquashFSFile ¶
NewMetadataFromSquashFSFile populates Metadata for the entry at path, with details from f.
type Opener ¶
type Opener func() (io.ReadCloser, error)
type Path ¶
type Path string
Path represents a file path
func (Path) AllPaths ¶
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) ConstituentPaths ¶
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 (Path) IsDirWhiteout ¶
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 ¶
IsWhiteout indicates if the file basename has a whiteout prefix (which means that the file should be removed during squashing)
func (Path) Normalize ¶
Normalize returns the cleaned file path representation (trimmed of spaces and resolve relative notations)
func (Path) ParentPath ¶
ParentPath returns a path object to the current files parent directory (or errors out if there is no parent)
func (Path) UnWhiteoutPath ¶
UnWhiteoutPath is a representation of the current path with no whiteout prefixes
type PathCountSet ¶
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 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 ¶
NewFileReference creates a new unique file reference for the given path.
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 ¶
SquashFSVisitor is the type of the function called by WalkSquashFS to visit each file or directory.
The sqfsPath argument contains the path to the SquashFS filesystem that was passed to WalkSquashFS. The filePath argument contains the full path of the file or directory within the SquashFS filesystem.
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 (filePath if d.IsDir() is true, otherwise filePath's parent directory). Otherwise, if the function returns a non-nil error, WalkSquashFS stops entirely and returns that error.
type TarFileEntry ¶
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.