diff options
Diffstat (limited to 'pkg/index')
| -rw-r--r-- | pkg/index/index.go | 18 | ||||
| -rw-r--r-- | pkg/index/index_test.go | 2 |
2 files changed, 13 insertions, 7 deletions
diff --git a/pkg/index/index.go b/pkg/index/index.go index 4db1eb4..cfa4138 100644 --- a/pkg/index/index.go +++ b/pkg/index/index.go @@ -7,6 +7,7 @@ import ( "io" "log/slog" "os" + "path" "regexp" "slices" "strings" @@ -38,6 +39,7 @@ type ParseOpts struct { ParseLinks bool IgnoreDateError bool IgnoreMetaError bool + IgnoreHidden bool } type InfoPath struct { @@ -195,16 +197,20 @@ func (doc Document) Equal(other Document) bool { return true } -func visit(file InfoPath, visitQueue chan<- InfoPath, filterQueue chan<- InfoPath, wg *sync.WaitGroup) { +func visit(file InfoPath, visitQueue chan<- InfoPath, filterQueue chan<- InfoPath, ignoreHidden bool, wg *sync.WaitGroup) { // TODO: check if symlink, and handle appropriately // TODO: extract error out of function + if ignoreHidden && path.Base(file.Path)[0] == '.' { + wg.Done() + return + } + if file.Info.IsDir() { entries, err := os.ReadDir(file.Path) if err != nil { panic(err) } - wg.Add(len(entries)) for _, entry := range entries { entryInfo, err := entry.Info() @@ -223,13 +229,13 @@ func visit(file InfoPath, visitQueue chan<- InfoPath, filterQueue chan<- InfoPat wg.Done() } -func workerTraverse(wg *sync.WaitGroup, visitQueue chan InfoPath, filterQueue chan<- InfoPath) { +func workerTraverse(wg *sync.WaitGroup, ignoreHidden bool, visitQueue chan InfoPath, filterQueue chan<- InfoPath) { for work := range visitQueue { - visit(work, visitQueue, filterQueue, wg) + visit(work, visitQueue, filterQueue, ignoreHidden, wg) } } -func (idx Index) Traverse(numWorkers uint) []string { +func (idx Index) Traverse(numWorkers uint, ignoreHidden bool) []string { if numWorkers <= 1 { panic(fmt.Sprint("Invalid number of workers: ", numWorkers)) } @@ -247,7 +253,7 @@ func (idx Index) Traverse(numWorkers uint) []string { // start workers for range numWorkers { - go workerTraverse(activeJobs, jobs, filterQueue) + go workerTraverse(activeJobs, ignoreHidden, jobs, filterQueue) } // init send diff --git a/pkg/index/index_test.go b/pkg/index/index_test.go index 69600c2..4242ce1 100644 --- a/pkg/index/index_test.go +++ b/pkg/index/index_test.go @@ -80,7 +80,7 @@ func TestIndex_Traverse(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { idx := tt.indexCase(t) - got := idx.Traverse(tt.numWorkers) + got := idx.Traverse(tt.numWorkers, true) slices.Sort(got) slices.Sort(tt.want) |
