diff options
| author | JP Appel <jeanpierre.appel01@gmail.com> | 2025-07-22 15:41:03 -0400 |
|---|---|---|
| committer | JP Appel <jeanpierre.appel01@gmail.com> | 2025-07-22 15:41:03 -0400 |
| commit | 344c6526a8d6f490fc7628ddc7d2dd06ed1a07c1 (patch) | |
| tree | 342878ff5d77b557533d6e5473e1d8f6e79ac6e9 /pkg/index | |
| parent | faf35ef54885bc48b897508ce3cb40b868ff505b (diff) | |
Separate program entry point from commands
Diffstat (limited to 'pkg/index')
| -rw-r--r-- | pkg/index/filters.go | 4 | ||||
| -rw-r--r-- | pkg/index/index.go | 9 |
2 files changed, 8 insertions, 5 deletions
diff --git a/pkg/index/filters.go b/pkg/index/filters.go index 920d5df..bd9df54 100644 --- a/pkg/index/filters.go +++ b/pkg/index/filters.go @@ -50,10 +50,10 @@ func ParseFilter(s string) (DocFilter, error) { } return NewMaxFilesizeFilter(size), nil case "ExcludeName", "ExcludeFilename": - // FIXME: support escaped commas + // TODO: support escaped commas return NewExcludeFilenameFilter(strings.Split(param, ",")), nil case "IncludeName", "IncludeFilename": - // FIXME: support escaped commas + // TODO: support escaped commas return NewIncludeFilenameFilter(strings.Split(param, ",")), nil case "ExcludeParent": return NewExcludeParentFilter(param), nil diff --git a/pkg/index/index.go b/pkg/index/index.go index cfa4138..50f642e 100644 --- a/pkg/index/index.go +++ b/pkg/index/index.go @@ -12,6 +12,7 @@ import ( "slices" "strings" "sync" + "sync/atomic" "time" "github.com/goccy/go-yaml" @@ -383,21 +384,23 @@ func ParseDoc(path string, opts ParseOpts) (*Document, error) { return doc, nil } -func ParseDocs(paths []string, numWorkers uint, opts ParseOpts) map[string]*Document { +func ParseDocs(paths []string, numWorkers uint, opts ParseOpts) (map[string]*Document, uint64) { jobs := make(chan string, numWorkers) results := make(chan *Document, numWorkers) docs := make(map[string]*Document, len(paths)) wg := &sync.WaitGroup{} + errCnt := &atomic.Uint64{} wg.Add(int(numWorkers)) for range numWorkers { go func(jobs <-chan string, results chan<- *Document, wg *sync.WaitGroup) { for path := range jobs { doc, err := ParseDoc(path, opts) if err != nil { - slog.Error("Error occured while parsing file", + slog.Warn("Error occured while parsing file", slog.String("path", path), slog.String("err", err.Error()), ) + errCnt.Add(1) continue } @@ -423,7 +426,7 @@ func ParseDocs(paths []string, numWorkers uint, opts ParseOpts) map[string]*Docu docs[doc.Path] = doc } - return docs + return docs, errCnt.Load() } func init() { |
