filesystem

package
v1.0.21 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2026 License: MIT Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package filesystem resolves paths and enforces filesystem allowlists.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MatchGlob added in v0.7.0

func MatchGlob(pattern, rel string) bool

MatchGlob reports whether the slash-separated path rel matches pattern. "*" and "?" stay within one path segment and "**" spans segments. A pattern without a slash matches the base name at any depth.

func ResolvePath

func ResolvePath(raw, baseDir string) (string, error)

ResolvePath resolves a user-supplied path against baseDir (for relative paths), expands special prefixes, and resolves any existing symlink ancestors.

func WalkFiles added in v0.7.0

func WalkFiles(root string, respectGitignore bool, fn func(rel string, d fs.DirEntry) error) error

WalkFiles walks the regular files under root in lexical order, calling fn with each file's slash-separated path relative to root. The .git directory is always skipped, and .gitignore rules are honored when respectGitignore is set.

Types

type ExpandedRule added in v0.7.0

type ExpandedRule struct {
	Pattern string
	Dir     string
	Negated bool
}

ExpandedRule is an allowlist rule with its pattern expanded to an absolute path, and Dir the directory its globs sit under.

func ExpandRules added in v0.7.0

func ExpandRules(patterns []string, baseDir string) ([]ExpandedRule, error)

ExpandRules expands each of the ordered rules the way NewPolicy does, to pass them on to another enforcer such as a CLI session's own permission rules. Patterns keep their case and the OS's separators.

type IgnoreMatcher added in v0.7.0

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

IgnoreMatcher evaluates .gitignore rules collected from a directory tree.

func (*IgnoreMatcher) AddGitignore added in v0.7.0

func (m *IgnoreMatcher) AddGitignore(dir, relDir string) error

AddGitignore loads the .gitignore file in dir, whose slash-separated path relative to the walk root is relDir ("" for the root itself). A missing file is not an error.

func (*IgnoreMatcher) AddPattern added in v0.7.0

func (m *IgnoreMatcher) AddPattern(relDir, line string)

AddPattern adds a single gitignore pattern line scoped to relDir.

func (*IgnoreMatcher) Ignored added in v0.7.0

func (m *IgnoreMatcher) Ignored(rel string, isDir bool) bool

Ignored reports whether the slash-separated path rel, relative to the walk root, is ignored. The last matching rule wins, as in git.

type Policy

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

Policy evaluates ordered allow/deny filesystem rules.

func NewPolicy

func NewPolicy(patterns []string, baseDir string) (*Policy, error)

NewPolicy compiles the provided ordered rules. Relative paths are resolved relative to baseDir.

func PolicyFromAgent

func PolicyFromAgent(cfg *config.AgentConfig, agentDir string) (*Policy, error)

PolicyFromAgent creates a path policy from an agent config. Relative paths in the allowlist are resolved relative to agentDir.

func (*Policy) Allows

func (p *Policy) Allows(resolvedPath string) bool

Allows reports whether the resolved path is allowed by the ordered rule set.

func (*Policy) Decide added in v0.7.0

func (p *Policy) Decide(resolvedPath string) (bool, string)

Decide reports whether the resolved path is allowed and the rule that decided it, as written: the last rule that matches. The rule is empty when none matches.

func (*Policy) MayAllowWithin added in v0.7.0

func (p *Policy) MayAllowWithin(resolvedDir string) bool

MayAllowWithin reports whether the policy could allow dir itself or any path beneath it, so a search rooted at dir is worth running.

Jump to

Keyboard shortcuts

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