Documentation ¶
Index ¶
- Variables
- type Builder
- type Copier
- type DepthFirstPathWalker
- type FileNodeVisitor
- type FileTree
- func (t *FileTree) AddDir(realPath file.Path) (*file.Reference, error)
- func (t *FileTree) AddFile(realPath file.Path) (*file.Reference, error)
- func (t *FileTree) AddHardLink(realPath file.Path, linkPath file.Path) (*file.Reference, error)
- func (t *FileTree) AddSymLink(realPath file.Path, linkPath file.Path) (*file.Reference, error)
- func (t *FileTree) AllFiles(types ...file.Type) []file.Reference
- func (t *FileTree) AllRealPaths() []file.Path
- func (t *FileTree) Copy() (ReadWriter, error)
- func (t *FileTree) Equal(other *FileTree) bool
- func (t *FileTree) File(path file.Path, options ...LinkResolutionOption) (bool, *file.Resolution, error)
- func (t *FileTree) FilesByGlob(query string, options ...LinkResolutionOption) ([]file.Resolution, error)
- func (t *FileTree) HasPath(path file.Path, options ...LinkResolutionOption) bool
- func (t *FileTree) ListPaths(dir file.Path) ([]file.Path, error)
- func (t *FileTree) Merge(upper Reader) error
- func (t *FileTree) PathDiff(other *FileTree) (extra, missing []file.Path)
- func (t *FileTree) RemoveChildPaths(path file.Path) error
- func (t *FileTree) RemovePath(path file.Path) error
- func (t *FileTree) TreeReader() tree.Reader
- func (t *FileTree) Walk(fn func(path file.Path, f filenode.FileNode) error, conditions *WalkConditions) error
- type Index
- type IndexEntry
- type IndexReader
- type IndexWriter
- type LinkResolutionOption
- type PathReader
- type ReadWriter
- type Reader
- type Searcher
- type UnionFileTree
- type WalkConditions
- type Walker
- type Writer
Constants ¶
This section is empty.
Variables ¶
var ErrLinkCycleDetected = errors.New("cycle during symlink resolution")
var ErrLinkResolutionDepth = errors.New("maximum link resolution stack depth exceeded")
var ErrMaxTraversalDepth = errors.New("max allowable directory traversal depth reached (maybe a link cycle?)")
var ErrRemovingRoot = errors.New("cannot remove the root path (`/`) from the FileTree")
Functions ¶
This section is empty.
Types ¶
type Builder ¶
type Builder struct {
// contains filtered or unexported fields
}
Builder is a helper for building a filetree and accompanying index in a coordinated fashion.
func NewBuilder ¶
func NewBuilder(tree Writer, index IndexWriter) *Builder
type Copier ¶
type Copier interface {
Copy() (ReadWriter, error)
}
type DepthFirstPathWalker ¶
type DepthFirstPathWalker struct {
// contains filtered or unexported fields
}
DepthFirstPathWalker implements stateful depth-first Tree traversal.
func NewDepthFirstPathWalker ¶
func NewDepthFirstPathWalker(tree *FileTree, visitor FileNodeVisitor, conditions *WalkConditions) *DepthFirstPathWalker
func (*DepthFirstPathWalker) WalkAll ¶
func (w *DepthFirstPathWalker) WalkAll() error
type FileTree ¶
type FileTree struct {
// contains filtered or unexported fields
}
FileTree represents a file/directory Tree
func NewFileTree ¶
func NewFileTree() *FileTree
NewFileTree creates a new FileTree instance. Deprecated: use New() instead.
func (*FileTree) AddDir ¶
AddDir adds a new path representing a DIRECTORY to the Tree. It also adds any ancestors of the path that are not already present in the Tree. The resulting file.Reference of the new (leaf) addition is returned. Note: NO symlink or hardlink resolution is performed on the given path --which implies that the given path MUST be a real path (have no links in constituent paths)
func (*FileTree) AddFile ¶
AddFile adds a new path representing a REGULAR file to the Tree. It also adds any ancestors of the path that are not already present in the Tree. The resulting file.Reference of the new (leaf) addition is returned. Note: NO symlink or hardlink resolution is performed on the given path --which implies that the given path MUST be a real path (have no links in constituent paths)
func (*FileTree) AddHardLink ¶
AddHardLink adds a new path to the Tree that represents a HARDLINK. A new file.Reference with a absolute link path captured and returned. Note: NO symlink or hardlink resolution is performed on the given path --which implies that the given path MUST be a real path (have no links in constituent paths)
func (*FileTree) AddSymLink ¶
AddSymLink adds a new path to the Tree that represents a SYMLINK. A new file.Reference with a absolute or relative link path captured and returned. Note: NO symlink or hardlink resolution is performed on the given path --which implies that the given path MUST be a real path (have no links in constituent paths)
func (*FileTree) AllFiles ¶
AllFiles returns all files within the FileTree (defaults to regular files only, but you can provide one or more allow types).
func (*FileTree) AllRealPaths ¶
func (*FileTree) Copy ¶
func (t *FileTree) Copy() (ReadWriter, error)
Copy returns a Copy of the current FileTree.
func (*FileTree) File ¶
func (t *FileTree) File(path file.Path, options ...LinkResolutionOption) (bool, *file.Resolution, error)
File fetches a file.Reference for the given path. Returns nil if the path does not exist in the FileTree.
func (*FileTree) FilesByGlob ¶
func (t *FileTree) FilesByGlob(query string, options ...LinkResolutionOption) ([]file.Resolution, error)
FilesByGlob fetches zero to many file.References for the given glob pattern (considers symlinks).
func (*FileTree) HasPath ¶
func (t *FileTree) HasPath(path file.Path, options ...LinkResolutionOption) bool
HasPath indicates is the given path is in the file Tree (with optional link resolution options).
func (*FileTree) Merge ¶
Merge takes the given Tree and combines it with the current Tree, preferring files in the other Tree if there are path conflicts. This is the basis function for squashing (where the current Tree is the bottom Tree and the given Tree is the top Tree).
func (*FileTree) PathDiff ¶
PathDiff shows the path differences between two trees (useful for testing)
func (*FileTree) RemoveChildPaths ¶
RemoveChildPaths deletes all children of the given path (not including the given path). Note: if the given path basename is a symlink, then the symlink is followed before resolving children. If the path does not exist, this is a nop.
func (*FileTree) RemovePath ¶
RemovePath deletes the file.Reference from the FileTree by the given path. If the basename of the given path is a symlink then the symlink is removed (not the destination of the symlink). If the path does not exist, this is a nop.
func (*FileTree) TreeReader ¶
TreeReader returns a tree.Reader useful for Tree traversal.
type Index ¶
type Index interface { IndexReader IndexWriter }
type IndexEntry ¶
IndexEntry represents all stored metadata for a single file reference.
type IndexReader ¶
type IndexReader interface { Exists(f file.Reference) bool Get(f file.Reference) (IndexEntry, error) GetByMIMEType(mTypes ...string) ([]IndexEntry, error) GetByFileType(fTypes ...file.Type) ([]IndexEntry, error) GetByExtension(extensions ...string) ([]IndexEntry, error) GetByBasename(basenames ...string) ([]IndexEntry, error) GetByBasenameGlob(globs ...string) ([]IndexEntry, error) Basenames() []string }
type LinkResolutionOption ¶
type LinkResolutionOption int
LinkResolutionOption is a single link resolution rule.
const ( // FollowBasenameLinks deals with link resolution for the basename of a given path (not ancestors). FollowBasenameLinks LinkResolutionOption // DoNotFollowDeadBasenameLinks deals with a special case in link resolution: when a basename resolution results in // a dead link. This option ensures that the last link file that resolved is returned (which exists) instead of // the non-existing path. This is useful when the caller wants to do custom link resolution (e.g. for container // images: the link is dead in this layer squash, but does it resolve in a higher layer?). DoNotFollowDeadBasenameLinks )
type PathReader ¶
type PathReader interface { File(path file.Path, options ...LinkResolutionOption) (bool, *file.Resolution, error) FilesByGlob(query string, options ...LinkResolutionOption) ([]file.Resolution, error) AllRealPaths() []file.Path ListPaths(dir file.Path) ([]file.Path, error) HasPath(path file.Path, options ...LinkResolutionOption) bool }
type ReadWriter ¶
type Searcher ¶
type Searcher interface { SearchByPath(path string, options ...LinkResolutionOption) (*file.Resolution, error) SearchByGlob(patterns string, options ...LinkResolutionOption) ([]file.Resolution, error) SearchByMIMEType(mimeTypes ...string) ([]file.Resolution, error) }
Searcher is a facade for searching a file tree with optional indexing support.
func NewSearchContext ¶
func NewSearchContext(tree Reader, index IndexReader) Searcher
type UnionFileTree ¶
type UnionFileTree struct {
// contains filtered or unexported fields
}
func NewUnionFileTree ¶
func NewUnionFileTree() *UnionFileTree
func (*UnionFileTree) PushTree ¶
func (u *UnionFileTree) PushTree(t ReadWriter)
func (*UnionFileTree) Squash ¶
func (u *UnionFileTree) Squash() (ReadWriter, error)
type WalkConditions ¶
type WalkConditions struct { // Return true when the walker should stop traversing (before visiting current Node) ShouldTerminate func(file.Path, filenode.FileNode) bool // Whether we should visit the current Node. Note: this will continue down the same traversal // path, only "skipping" over a single Node (but still potentially visiting children later) // Return true to visit the current Node. ShouldVisit func(file.Path, filenode.FileNode) bool // Whether we should consider children of this Node to be included in the traversal path. // Return true to traverse children of this Node. ShouldContinueBranch func(file.Path, filenode.FileNode) bool LinkOptions []LinkResolutionOption }
type Writer ¶
type Writer interface { AddFile(realPath file.Path) (*file.Reference, error) AddSymLink(realPath file.Path, linkPath file.Path) (*file.Reference, error) AddHardLink(realPath file.Path, linkPath file.Path) (*file.Reference, error) AddDir(realPath file.Path) (*file.Reference, error) RemovePath(path file.Path) error Merge(upper Reader) error }