Documentation
¶
Overview ¶
Package tree provides immutable, confined in-memory filesystems and private construction overlays. It depends only on the standard library.
Index ¶
- Variables
- type Builder
- func (b *Builder) AddFile(name string, data []byte, mode fs.FileMode) error
- func (b *Builder) AddSymlink(name, target string) error
- func (b *Builder) Build() (*Tree, error)
- func (t *Builder) Lstat(name string) (fs.FileInfo, error)
- func (b *Builder) Mount(name string, input fs.FS) error
- func (t *Builder) Open(name string) (fs.File, error)
- func (t *Builder) ReadDir(name string) ([]fs.DirEntry, error)
- func (t *Builder) ReadFile(name string) ([]byte, error)
- func (t *Builder) ReadLink(name string) (string, error)
- func (b *Builder) RemoveAll(name string) error
- func (t *Builder) Resolve(name string) (string, error)
- func (t *Builder) Stat(name string) (fs.FileInfo, error)
- func (t *Builder) WalkRaw(name string, fn fs.WalkDirFunc) error
- type Tree
- func (t *Tree) Lstat(name string) (fs.FileInfo, error)
- func (t *Tree) Open(name string) (fs.File, error)
- func (t *Tree) ReadDir(name string) ([]fs.DirEntry, error)
- func (t *Tree) ReadFile(name string) ([]byte, error)
- func (t *Tree) ReadLink(name string) (string, error)
- func (t *Tree) Resolve(name string) (string, error)
- func (t *Tree) Stat(name string) (fs.FileInfo, error)
- func (t *Tree) WalkRaw(name string, fn fs.WalkDirFunc) error
Constants ¶
This section is empty.
Variables ¶
var ErrConflict = errors.New("file/directory conflict")
ErrConflict identifies incompatible node kinds at a construction path.
var ErrEscape = errors.New("path escapes tree")
ErrEscape identifies a path or link target outside the tree. All absolute link targets are escapes, including host paths that point inside an input root; input loaders must translate those targets before construction if permitted.
var ErrLoop = errors.New("too many symlinks")
ErrLoop identifies resolution exceeding eight symlink traversals.
var ErrSealed = errors.New("builder is sealed")
ErrSealed identifies an operation on a builder whose ownership was transferred.
Functions ¶
This section is empty.
Types ¶
type Builder ¶
type Builder struct {
// contains filtered or unexported fields
}
Builder owns mutable construction state and must not be copied or shared between renders or source producers. Reads can memoize lower metadata.
func NewBuilder ¶
NewBuilder creates a private overlay over lower, or an empty source builder when lower is nil. Only upper directory indexes and inserted bytes are copied.
func (*Builder) AddFile ¶
AddFile copies data once. Duplicate files are last-wins; directories and symlinks are conflicts until removed explicitly.
func (*Builder) AddSymlink ¶
AddSymlink stores a lexical target, including dangling, absolute and escaping targets. Follow operations enforce confinement; raw scans do not follow links.
func (*Builder) Mount ¶
Mount replaces a directory's indexed subtree with immutable content without copying bytes. Mounted inputs MUST remain read-only for the resulting tree lifetime.
func (*Builder) ReadDir ¶
ReadDir returns caller-owned entries sorted by name, following a link root.
func (*Builder) RemoveAll ¶
RemoveAll masks a subtree without mutating the lower tree. Recreated nodes never expose lower descendants of that subtree.
func (*Builder) Resolve ¶
Resolve follows links before subsequent parent components and returns a canonical slash path. Unlike the io/fs methods, it accepts unclean relative paths. Links stay confined to the tree.
type Tree ¶
type Tree struct {
// contains filtered or unexported fields
}
Tree is a sealed filesystem. An immutable lower permits concurrent readers without synchronization. Lower filesystems MUST remain read-only for the tree lifetime. Public slices are copies.
func (*Tree) Resolve ¶
Resolve follows links before subsequent parent components and returns a canonical slash path. Unlike the io/fs methods, it accepts unclean relative paths. Links stay confined to the tree.