Documentation
¶
Overview ¶
Package files discovers in-scope files and safely resolves indexed paths.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNotIndexed is returned when a path was not part of a scan's file index. ErrNotIndexed = errors.New("path is not indexed") // ErrPathEscape is returned when resolving a path would leave the scan root. ErrPathEscape = errors.New("path escapes scan root") )
Functions ¶
func ResolveFile ¶ added in v0.1.6
ResolveFile returns the absolute path of the regular file at the slash-separated path rel below root, after evaluating symlinks. It rejects absolute paths and paths that leave root, before or after evaluation, with ErrPathEscape. Unlike Index.Resolve, any file below root resolves; callers decide which paths may be read.
Types ¶
type Entry ¶
type Entry struct {
Name string `json:"name"`
Path string `json:"path"`
IsDir bool `json:"isDir"`
Children []Entry `json:"children,omitempty"`
}
Entry is a directory or supported file in a scan tree. Path is slash-separated and relative to the scan root; the root entry has an empty Path.
type IgnoreRules ¶ added in v0.1.6
type IgnoreRules struct {
// contains filtered or unexported fields
}
IgnoreRules answers git ignore questions for paths below one root. It reads the sources git uses (see rootIgnoreRules), loading each directory's .gitignore on first use. It is not safe for concurrent use.
func NewIgnoreRules ¶ added in v0.1.6
func NewIgnoreRules(root string) *IgnoreRules
NewIgnoreRules returns the ignore rules for the absolute, symlink-evaluated directory root.
type Index ¶
type Index struct {
Tree Entry `json:"tree"`
Files []string `json:"files"`
Warnings []Warning `json:"-"`
// contains filtered or unexported fields
}
Index is the deterministic result of a scan. Files contains the paths of all supported files in tree traversal order. Warnings contains recoverable errors encountered below the root and is intentionally omitted from JSON output.
func Scan ¶
Scan builds an index rooted at root. The root directory is depth zero, so a maxDepth of zero includes supported files directly within root. Negative maxDepth values scan without a depth limit. Directory names in excluded are matched by base name at every scanned level. .git entries of any type are never indexed.
Symlinks are not included. Failure to open or inspect the root is fatal; failures below it are recorded in Index.Warnings and the rest of the scan is returned.
func (*Index) Ignored ¶ added in v0.1.6
Ignored reports whether an indexed file is excluded by gitignore rules: the root repository's core.excludesFile and info/exclude, including for linked worktrees, and the .gitignore files from the root down. Ignored files stay browsable; content search and code navigation skip them.
type NameFilter ¶ added in v0.1.6
type NameFilter struct {
// contains filtered or unexported fields
}
NameFilter selects files by case-insensitive base-name globs in path.Match syntax. It knows no file formats; every matching file is in scope.
func AllNames ¶ added in v0.1.6
func AllNames() NameFilter
AllNames is the default filter, equivalent to the single pattern "*".
func NewNameFilter ¶ added in v0.1.6
func NewNameFilter(patterns []string) (NameFilter, error)
NewNameFilter validates patterns. Empty patterns, malformed globs, and patterns containing "/" (which can never match a base name) are rejected.
func (NameFilter) Match ¶ added in v0.1.6
func (f NameFilter) Match(name string) bool
Match reports whether the base name of name matches any pattern.
func (NameFilter) Patterns ¶ added in v0.1.6
func (f NameFilter) Patterns() []string
Patterns returns the validated patterns as given.
type Warning ¶
Warning describes an entry that could not be inspected during a scan. Path is slash-separated and relative to the scan root.
func WalkUnignored ¶ added in v0.1.6
func WalkUnignored(ctx context.Context, root string, rules *IgnoreRules, visit func(rel string, entry fs.DirEntry) error) ([]Warning, error)
WalkUnignored calls visit with the slash-separated root-relative path of every regular file and symlink below root that rules do not ignore, in directory order. Symlinks are reported, never followed. Ignored directories, .git entries, and nested repositories (directories other than root holding a .git entry) are pruned. No depth, filename, or exclusion scope applies.
root must be absolute and symlink-evaluated. Failure to read root, a visit error, or ctx ending stops the walk with that error; unreadable directories below root are returned as warnings.