find

package
v0.0.0-...-7447bd4 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package find provides filename and path matching for finder mode.

Index

Constants

View Source
const TypeDir = TypeDirectory

TypeDir is an alias for TypeDirectory.

View Source
const TypeLink = TypeSymlink

TypeLink is an alias for TypeSymlink.

Variables

This section is empty.

Functions

func NormalizePath

func NormalizePath(name string) string

NormalizePath converts path separators to slash and cleans a path for matching. It preserves an absolute path's leading slash.

Types

type Config

type Config struct {
	// Matcher controls basename or full-path matching.
	Matcher MatcherConfig
	// Types selects result kinds. Multiple values are ORed; an empty list keeps
	// all kinds.
	Types []Type
	// Extensions selects file extensions without a leading dot. Multiple values
	// are ORed; an empty list keeps all extensions.
	Extensions []string
	// MinSize is an inclusive lower bound. Zero disables the lower bound.
	MinSize int64
	// MaxSize is an inclusive upper bound when MaxSizeSet is true. This separate
	// bit allows an explicit zero-byte limit.
	MaxSize int64
	// MaxSizeSet enables MaxSize.
	MaxSizeSet bool
	// Walk controls traversal, including hidden entries, symlinks, and depth.
	Walk walk.Config
	// Ignore controls hidden and ignore-file behavior during traversal.
	Ignore ignore.Config
	// OmitInfo leaves Result.Info nil and avoids resolving regular-file
	// metadata. It cannot be combined with size filters.
	OmitInfo bool
	// FS selects the filesystem used by the high-level finder API. Nil uses the
	// local operating-system filesystem.
	FS fs.FS
}

Config holds finder matching, metadata filtering, and traversal settings. Traversal settings are passed to walk.Walker by the high-level finder API; NewFilter uses the matching and metadata fields only.

func (Config) IgnoreConfig

func (c Config) IgnoreConfig() ignore.Config

IgnoreConfig returns the ignore and hidden-entry settings for traversal.

func (Config) WalkerConfig

func (c Config) WalkerConfig() walk.Config

WalkerConfig returns the traversal settings required by finder mode. Entries that cannot satisfy the configured type or extension filters are not emitted, while matching directory and symlink entries remain available.

type Filter

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

Filter applies finder matching and metadata predicates to walk entries.

func NewFilter

func NewFilter(cfg Config) (*Filter, error)

NewFilter validates cfg and compiles its matching and metadata predicates.

func (*Filter) Match

func (f *Filter) Match(entry walk.Entry) bool

Match reports whether entry satisfies every configured finder predicate, matching the entry's display path.

func (*Filter) MatchPath

func (f *Filter) MatchPath(entry walk.Entry, matchPath string) bool

MatchPath reports whether entry satisfies every configured finder predicate, matching matchPath instead of the entry's display path. Find uses this to match full paths relative to each supplied root while preserving result output paths.

type Matcher

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

Matcher matches finder paths without reading their contents.

A Matcher is immutable after construction and may be shared by concurrent callers.

func NewMatcher

func NewMatcher(cfg MatcherConfig) (*Matcher, error)

NewMatcher compiles a finder matcher from cfg.

func (*Matcher) Match

func (m *Matcher) Match(name string) bool

Match reports whether name matches the configured finder pattern. name may use either slash or backslash separators; matching normalizes both to slash separators first.

type MatcherConfig

type MatcherConfig struct {
	// Pattern is matched against a basename by default. An empty pattern
	// matches every path.
	Pattern string
	// Glob treats Pattern as a glob expression instead of a regular expression.
	Glob bool
	// FixedStrings treats Pattern as a literal substring.
	FixedStrings bool
	// IgnoreCase enables Unicode-aware case-insensitive matching.
	IgnoreCase bool
	// FullPath matches the normalized path passed to Match instead of its
	// basename. The caller supplies the path relative to its search root.
	FullPath bool
}

MatcherConfig controls how a finder pattern is compiled.

type Result

type Result struct {
	// Path is the stable display path of the matched entry.
	Path string
	// Info is the metadata snapshot used by filters. It is nil when the
	// finder is configured with Config.OmitInfo.
	Info fs.FileInfo
	// Kind identifies whether the result is a file or directory.
	Kind walk.EntryKind
	// Symlink reports whether Path itself is a symbolic link.
	Symlink bool
	// Depth is relative to the supplied traversal root.
	Depth int
}

Result is the public, metadata-only representation of a finder match.

func NewResult

func NewResult(entry walk.Entry) Result

NewResult converts a walker entry into a public finder result.

type Type

type Type uint8

Type identifies a finder result kind.

const (
	// TypeFile selects regular file entries, excluding symlink entries.
	TypeFile Type = iota
	// TypeDirectory selects directory entries, excluding symlink entries.
	TypeDirectory
	// TypeSymlink selects entries whose path is a symbolic link.
	TypeSymlink
)

Jump to

Keyboard shortcuts

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