Documentation ¶
Index ¶
- Variables
- type Filter
- type Stats
- type Walk
- func (walk *Walk) HasFinished() bool
- func (walk *Walk) InitSync()
- func (walk *Walk) Run() (err error)
- func (walk *Walk) SetBatchSize(batchSize int)
- func (walk *Walk) SetBufferSize(bufferSize int)
- func (walk *Walk) SetConcurrency(concurrency int)
- func (walk *Walk) SetFilter(filter Filter)
- func (walk *Walk) SetGlobalTimeoutDuration(timeoutDuration time.Duration)
- func (walk *Walk) Stats() Stats
- func (walk *Walk) Stop()
- type WalkFunc
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrSkipDirectory can be returned by the visitor if a directory to skip // walking its contents. ErrSkipDirectory = errors.New("skip directory") )
Functions ¶
This section is empty.
Types ¶
type Filter ¶
type Filter struct { IncludePaths []string ExcludePaths []string IncludeFilenames []string ExcludeFilenames []string IsCaseInsensitive bool }
Filter define the parameters that can be provided by the user to control the walk.
type Stats ¶
type Stats struct { // JobsDispatchedToNewWorker is the number of workers that were started to // process a job. JobsDispatchedToNewWorker int // JobsDispatchedToIdleWorker is the number of jobs that were dispatched to // an available, idle worker rather than starting a new one. JobsDispatchedToIdleWorker int // FilesVisited is the number of files that were visited. FilesVisited int // DirectoriesVisited is the number of directories that were visited. DirectoriesVisited int // EntryBatchesProcessed is the number of batches that directory entries // were parceled into while processing. EntryBatchesProcessed int // IdleWorkerTime is the duration of all between-job time spent by workers. // Only includes time between jobs and time between last job and timeout // (leading to shutdown). Does not include time between the last job and a // closed channel being detected (which is not true idleness). IdleWorkerTime time.Duration // DirectoriesIgnored is the number of directories that were signaled to be // skipped using `ErrSkipDirectory`. DirectoriesIgnored int // PathFilterIncludes is the number of path include hits or exclude misses // if at least one filter rule was provided. PathFilterIncludes int // PathFilterExcludes is the number of path include misses or exclude hits // if at least one filter rule was provided. PathFilterExcludes int // FileFilterIncludes is the number of file include hits or exclude misses // if at least one filter rule was provided. FileFilterIncludes int // FileFilterExcludes is the number of file include misses or exclude hits // if at least one filter rule was provided. FileFilterExcludes int }
Stats describes all stats collected by the walking process.
type Walk ¶
type Walk struct {
// contains filtered or unexported fields
}
Walk knows how to traverse a tree in parallel.
func (*Walk) HasFinished ¶
HasFinished returns whether all entries have been visited and processed.
func (*Walk) InitSync ¶
func (walk *Walk) InitSync()
InitSync sets-up the synchronization state. This is isolated as a separate step to support testing.
func (*Walk) Run ¶
Run forks workers to process the tree. All workers will have quit by the time we return.
Example ¶
// Stage test directory. fileCount := 20 tempPath, _ := pwtesting.FillFlatTempPath(fileCount, nil) // Walk defer func() { os.RemoveAll(tempPath) }() walkFunc := func(parentPath string, info os.FileInfo) (err error) { // Do your business. return nil } walk := NewWalk(tempPath, walkFunc) err := walk.Run() log.PanicIf(err)
Output:
func (*Walk) SetBatchSize ¶
SetBatchSize sets an alternative size for the parcels of directory entries dispatched into jobs.
func (*Walk) SetBufferSize ¶
SetBufferSize sets an alternative size for the job channel.
func (*Walk) SetConcurrency ¶
SetConcurrency sets an alternative maximum number of workers.
func (*Walk) SetFilter ¶
SetFilter sets filtering parameters for the next call to Run(). Behavior is undefined if this is changed *during* a call to `Run()`. The filters will be sorted automatically.
func (*Walk) SetGlobalTimeoutDuration ¶
SetGlobalTimeoutDuration sets a non-default duration, after which if no activity has happened than we should consider ourselves dead-locked.