file

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2026 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Overview

Package file confines file tools to a root and applies a caller-supplied write policy.

Index

Constants

This section is empty.

Variables

View Source
var ErrGitDir = errors.New("refusing to touch anything inside a .git directory")

ErrGitDir refuses a change inside a repository's own metadata.

View Source
var ErrOutsideRoot = errors.New("path is outside the root")

ErrOutsideRoot is a path resolving to somewhere the root does not reach.

View Source
var ErrReadOnly = errors.New("the filesystem is read-only")

ErrReadOnly is what a call that would change something gets while writing is withheld.

Functions

func InGitDir

func InGitDir(name string) bool

InGitDir reports whether a path contains a .git component.

func RefuseGitDir

func RefuseGitDir(name string) error

RefuseGitDir returns ErrGitDir for paths containing a .git component.

Types

type Root

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

Root is a directory the tools are confined to, and a rule about what may be changed within it.

func New

func New(root *os.Root, refuse func(name string) error) *Root

New builds a Root over an open directory. refuse is checked before each change.

func (*Root) FS

func (self *Root) FS() fs.FS

FS is the tree as a filesystem, for walking and reading.

func (*Root) MkdirAll

func (self *Root) MkdirAll(name string, perm os.FileMode) error

MkdirAll makes a directory and every parent it needs, where the rule allows it.

func (*Root) Mount

func (self *Root) Mount(path string, root *Root)

Mount adds a tree at an absolute path.

func (*Root) Name

func (self *Root) Name() string

Name is the directory the tools are confined to.

func (*Root) Open

func (self *Root) Open(name string) (*os.File, error)

Open opens a file or a directory for reading.

func (*Root) ReadFile

func (self *Root) ReadFile(name string) ([]byte, error)

ReadFile reads a whole file.

func (*Root) RefuseWrite

func (self *Root) RefuseWrite(name string) error

RefuseWrite returns the current refusal for a path.

func (*Root) Resolve

func (self *Root) Resolve(path string) (*Root, string, error)

Resolve finds the tree and local name for a path.

func (*Root) Stat

func (self *Root) Stat(name string) (os.FileInfo, error)

Stat is what is known about a file without opening it.

func (*Root) WriteFile

func (self *Root) WriteFile(name string, data []byte, perm os.FileMode) error

WriteFile writes a whole file, where the rule allows it.

Jump to

Keyboard shortcuts

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