in src/scip-lib/scanner/scan.go [232:300]
func (is *IndexScannerImpl) ScanIndexFolder(path string, parallel bool) error {
entries, err := os.ReadDir(path)
if err != nil {
return errors.Join(fmt.Errorf("failed to read directory"), err)
}
var wg sync.WaitGroup
errChan := make(chan error, len(entries))
processFile := func(filePath string) {
defer wg.Done()
// Skip non-SCIP files
if filepath.Ext(filePath) != ".scip" {
return
}
if err := is.ScanIndexFile(filePath); err != nil {
errChan <- err
}
}
if parallel {
maxWorkers := runtime.NumCPU()
if is.MaxConcurrency > 0 {
maxWorkers = is.MaxConcurrency
}
sem := make(chan struct{}, maxWorkers)
for _, entry := range entries {
if entry.IsDir() {
continue
}
wg.Add(1)
fullPath := filepath.Join(path, entry.Name())
sem <- struct{}{}
go func(path string) {
processFile(path)
<-sem
}(fullPath)
}
} else {
for _, entry := range entries {
if entry.IsDir() {
continue
}
wg.Add(1)
fullPath := filepath.Join(path, entry.Name())
processFile(fullPath)
}
}
wg.Wait()
close(errChan)
var errs []error
for err := range errChan {
errs = append(errs, err)
}
if len(errs) > 0 {
errStrings := make([]string, len(errs))
for i, err := range errs {
errStrings[i] = err.Error()
}
return errors.New(strings.Join(errStrings, "\n"))
}
return nil
}