Documentation
¶
Overview ¶
Package stride provides high-performance filesystem traversal with advanced filtering and monitoring capabilities.
This package contains the implementation of the `find` command, which allows users to search for files in a given directory with advanced filtering capabilities.
The `find` command supports various options for filtering files based on name, path, size, modification time, and more. It also provides functionality to execute commands for each matched file or format the output using templates.
Package stride provides high-performance filesystem traversal with advanced filtering and monitoring capabilities.
This package contains the implementation of the `stride` command, which is a high-performance file walking utility that extends the standard `filepath.Walk` functionality with concurrency, filtering, and monitoring capabilities.
Index ¶
- Constants
- func CompileRegexMap(patterns map[string]string) (map[string]*regexp.Regexp, error)
- func Find(ctx context.Context, root string, opts FindOptions, handler FindHandler) error
- func FindWithExec(ctx context.Context, root string, opts FindOptions, cmdTemplate string) error
- func FindWithFormat(ctx context.Context, root string, opts FindOptions, formatTemplate string) error
- func Walk(root string, walkFn filepath.WalkFunc) error
- func WalkLimit(ctx context.Context, root string, walkFn filepath.WalkFunc, limit int) error
- func WalkLimitWithFilter(ctx context.Context, root string, walkFn filepath.WalkFunc, limit int, ...) error
- func WalkLimitWithOptions(ctx context.Context, root string, walkFn filepath.WalkFunc, opts WalkOptions) error
- func WalkLimitWithProgress(ctx context.Context, root string, walkFn filepath.WalkFunc, limit int, ...) error
- func WalkWithAdvancedOptions(root string, walkFn AdvancedWalkFunc, options WalkOptions) error
- func WalkWithOptions(root string, walkFn WalkFunc, options WalkOptions) error
- type AdvancedWalkFunc
- type ErrorHandling
- type ErrorHandlingMode
- type FilterOptions
- type FindHandler
- type FindMessage
- type FindOptions
- type FindResult
- type LogLevel
- type MemoryLimit
- type MemoryLimitOptions
- type MiddlewareFunc
- type ProgressFn
- type Stats
- type SymlinkHandling
- type WalkFunc
- type WalkOptions
Constants ¶
const DefaultConcurrentWalks int = 100
DefaultConcurrentWalks defines the default number of concurrent workers when no specific limit is provided.
Variables ¶
This section is empty.
Functions ¶
func CompileRegexMap ¶
CompileRegexMap compiles a map of key-value regex patterns
func Find ¶
func Find(ctx context.Context, root string, opts FindOptions, handler FindHandler) error
Find searches for files matching the given criteria
func FindWithExec ¶
FindWithExec searches for files and executes a command for each match
func FindWithFormat ¶
func FindWithFormat(ctx context.Context, root string, opts FindOptions, formatTemplate string) error
FindWithFormat searches for files and formats output according to a template
func Walk ¶
Walk traverses a directory tree using the default concurrency limit. It's a convenience wrapper around WalkLimit.
func WalkLimit ¶
WalkLimit traverses a directory tree with a specified concurrency limit. It distributes work across a pool of goroutines while respecting context cancellation. Directories are processed synchronously so that a SkipDir result prevents descending.
func WalkLimitWithFilter ¶
func WalkLimitWithFilter(ctx context.Context, root string, walkFn filepath.WalkFunc, limit int, filter FilterOptions) error
WalkLimitWithFilter adds file filtering capabilities to the walk operation.
func WalkLimitWithOptions ¶
func WalkLimitWithOptions(ctx context.Context, root string, walkFn filepath.WalkFunc, opts WalkOptions) error
WalkLimitWithOptions provides the most flexible configuration, combining error handling, filtering, progress reporting, and optional custom logger/symlink handling.
func WalkLimitWithProgress ¶
func WalkLimitWithProgress(ctx context.Context, root string, walkFn filepath.WalkFunc, limit int, progressFn ProgressFn) error
WalkLimitWithProgress adds progress monitoring to the walk operation.
func WalkWithAdvancedOptions ¶
func WalkWithAdvancedOptions(root string, walkFn AdvancedWalkFunc, options WalkOptions) error
WalkWithAdvancedOptions traverses the file tree rooted at root, calling the user-provided advanced walkFn for each file or directory in the tree, including root, with access to traversal statistics.
func WalkWithOptions ¶
func WalkWithOptions(root string, walkFn WalkFunc, options WalkOptions) error
WalkWithOptions traverses the file tree rooted at root, calling the user-provided walkFn for each file or directory in the tree, including root, with the enhanced context-aware API.
Types ¶
type AdvancedWalkFunc ¶
AdvancedWalkFunc includes statistics for each callback.
type ErrorHandling ¶
type ErrorHandling int
ErrorHandling defines how errors are handled during traversal.
const ( ErrorHandlingContinue ErrorHandling = iota // Continue on errors ErrorHandlingStop // Stop on first error ErrorHandlingSkip // Skip problematic files/dirs )
type ErrorHandlingMode ¶
type ErrorHandlingMode string
ErrorHandlingMode defines how errors are handled during traversal.
const ( ContinueOnError ErrorHandlingMode = "continue" StopOnError ErrorHandlingMode = "stop" SkipOnError ErrorHandlingMode = "skip" )
type FilterOptions ¶
type FilterOptions struct {
MinSize int64 // Minimum file size in bytes
MaxSize int64 // Maximum file size in bytes
Pattern string // Glob pattern for matching files
ExcludeDir []string // Directory patterns to exclude
IncludeTypes []string // File extensions to include (e.g. ".txt", ".go")
FileTypes []string // File types to include (file, dir, symlink)
ExcludePattern []string // Patterns to exclude files
ModifiedAfter time.Time // Only include files modified after
ModifiedBefore time.Time // Only include files modified before
AccessedAfter time.Time // Include files accessed after this time
AccessedBefore time.Time // Include files accessed before this time
CreatedAfter time.Time // Include files created after this time
CreatedBefore time.Time // Include files created before this time
MinPermissions os.FileMode // Minimum file permissions (e.g. 0644)
MaxPermissions os.FileMode // Maximum file permissions (e.g. 0755)
ExactPermissions os.FileMode // Exact file permissions to match
UseExactPermissions bool // Whether to use exact permissions matching
OwnerUID int // Filter by owner UID
OwnerGID int // Filter by group GID
OwnerName string // Filter by owner username
GroupName string // Filter by group name
MinDepth int // Minimum traversal depth
MaxDepth int // Maximum traversal depth
IncludeEmptyFiles bool // Include only empty files
IncludeEmptyDirs bool // Include only empty directories
}
FilterOptions defines criteria for including/excluding files and directories.
type FindHandler ¶
type FindHandler func(ctx context.Context, result FindResult) error
FindHandler is a function that processes each found file
type FindMessage ¶
type FindMessage struct {
Path string // Full path to the file
Name string // Base name of the file
Dir string // Directory containing the file
Size int64 // Size in bytes
Time time.Time // Modification time
IsDir bool // Whether the entry is a directory
Metadata map[string]string // File metadata
Tags map[string]string // File tags
VersionID string // Version identifier (if applicable)
}
FindMessage holds information about a file found during traversal
type FindOptions ¶
type FindOptions struct {
// Pattern matching options
NamePattern string // Match by file name (supports wildcards)
PathPattern string // Match by path (supports wildcards)
IgnorePattern string // Skip paths matching this pattern
RegexPattern *regexp.Regexp // Match by regular expression
// Time-based filtering
OlderThan time.Duration // Files older than this duration
NewerThan time.Duration // Files newer than this duration
// Size-based filtering
LargerSize int64 // Files larger than this size (bytes)
SmallerSize int64 // Files smaller than this size (bytes)
// Metadata and tag filtering
MatchMeta map[string]*regexp.Regexp // Metadata key-value patterns to match
MatchTags map[string]*regexp.Regexp // Tag key-value patterns to match
// Execution options
ExecCmd string // Command to execute for each match
PrintFormat string // Format string for output
// Traversal options
MaxDepth uint // Maximum directory depth to traverse
FollowSymlinks bool // Whether to follow symbolic links
IncludeHidden bool // Whether to include hidden files
WithVersions bool // Whether to include file versions
// Watch options
Watch bool // Whether to watch for changes
WatchEvents []string // Events to watch for (create, modify, delete)
}
FindOptions defines the criteria for finding files
type FindResult ¶
type FindResult struct {
Message FindMessage
Error error
}
FindResult represents a file that matched the find criteria
type MemoryLimit ¶
type MemoryLimit struct {
SoftLimit int64 // Pause processing when reached
HardLimit int64 // Stop processing when reached
}
MemoryLimit sets memory usage boundaries for the traversal. Not implemented in this example.
type MemoryLimitOptions ¶
MemoryLimitOptions sets memory usage boundaries for the traversal.
type MiddlewareFunc ¶
MiddlewareFunc defines a middleware function for extensibility.
type ProgressFn ¶
type ProgressFn func(stats Stats)
ProgressFn is called periodically with traversal statistics. Implementations must be thread-safe as this may be called concurrently.
type Stats ¶
type Stats struct {
FilesProcessed int64 // Number of files processed
DirsProcessed int64 // Number of directories processed
EmptyDirs int64 // Number of empty directories
BytesProcessed int64 // Total bytes processed
ErrorCount int64 // Number of errors encountered
ElapsedTime time.Duration // Total time elapsed
AvgFileSize int64 // Average file size in bytes
SpeedMBPerSec float64 // Processing speed in MB/s
}
Stats holds traversal statistics that are updated atomically during the walk.
type SymlinkHandling ¶
type SymlinkHandling int
SymlinkHandling defines how symbolic links are processed.
const ( SymlinkFollow SymlinkHandling = iota // Follow symbolic links SymlinkIgnore // Ignore symbolic links SymlinkReport // Report links but don't follow )
type WalkOptions ¶
type WalkOptions struct {
// Core options
Context context.Context // Context for cancellation and deadlines
ErrorHandling ErrorHandling // Legacy error handling mode
ErrorHandlingMode ErrorHandlingMode // String-based error handling mode
Filter FilterOptions // File filtering options
// Progress monitoring
Progress ProgressFn // Legacy progress function
ProgressCallback func(stats Stats) // Enhanced progress callback
// Logging and debug
Logger *zap.Logger // Structured logger
LogLevel LogLevel // Logging verbosity level
DryRun bool // Simulate operations without executing
// Performance tuning
BufferSize int // Size of internal buffers
NumWorkers int // Legacy worker count
WorkerCount int // Enhanced worker count
// Special handling
SymlinkHandling SymlinkHandling // How to handle symbolic links
MemoryLimit MemoryLimit // Legacy memory limits
MemoryLimits MemoryLimitOptions // Enhanced memory limits
// Extensibility
Middleware []MiddlewareFunc // Middleware functions for customization
}
WalkOptions provides comprehensive configuration for the walk operation.