walker

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 14, 2026 License: MPL-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package walker walks a directory tree yielding file paths that pass ignore rules (.gitignore and .caignore) and include/exclude glob filters from config.Config.

Walker.Walk returns an iter.Seq2 iterator so callers process files one at a time without holding the full list in memory. Context cancellation stops the walk early. walker imports only config; it knows nothing about chunking, embedding, or storage.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option func(*Walker)

Option configures a Walker at construction time.

func WithFileFilter

func WithFileFilter(fn func(string) bool) Option

WithFileFilter attaches a path predicate to the Walker. fn receives the file path relative to the walker root and must return true for the file to be yielded. A nil fn (or omitting this option) preserves the existing behaviour: all paths that pass gitignore and include/exclude rules are yielded.

type Walker

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

Walker walks a directory tree, yielding file paths that pass all configured filters.

func New

func New(root string, cfg *config.Config, opts ...Option) (*Walker, error)

New creates a Walker rooted at root using filter configuration from cfg. The caller should call Close when done to release the underlying file descriptor.

func (*Walker) Close

func (w *Walker) Close() error

Close releases the os.Root file descriptor.

func (*Walker) FS

func (w *Walker) FS() fs.FS

FS returns an fs.FS scoped to the walker's root directory. The returned FS prevents path traversal via symlinks or ../ escapes.

func (*Walker) IsIgnored

func (w *Walker) IsIgnored(absPath string) bool

IsIgnored reports whether the absolute path should be ignored based on gitignore rules. Safe for concurrent use — builds a local ignore stack without locking ignoreMu.

func (*Walker) Match

func (w *Walker) Match(absPath string) bool

Match reports whether the file at the given absolute path would be yielded by Walk. Safe for concurrent use — builds a local ignore stack without locking ignoreMu.

func (*Walker) Root

func (w *Walker) Root() string

Root returns the absolute path of the walker's root directory.

func (*Walker) Walk

func (w *Walker) Walk(ctx context.Context) iter.Seq2[string, error]

Walk yields absolute file paths that satisfy the include/exclude patterns and gitignore rules. Stops early if ctx is cancelled.

Jump to

Keyboard shortcuts

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