Compare commits

...

2 Commits

Author SHA1 Message Date
Seednode 9b6d9464e6 Replace microsecond delay with another sync.WaitGroup 2024-01-09 17:36:25 -06:00
Seednode 6074b7e546 Re-add microsecond delay to walkPath() invocations 2024-01-09 17:17:26 -06:00
2 changed files with 56 additions and 42 deletions

View File

@ -240,9 +240,9 @@ func hasSupportedFiles(path string, formats types.Types) (bool, error) {
} }
} }
func walkPath(path string, fileChannel chan<- string, wg0 *sync.WaitGroup, stats *scanStats, limit chan struct{}, formats types.Types, errorChannel chan<- error) { func walkPath(path string, fileChannel chan<- string, wg1 *sync.WaitGroup, stats *scanStats, limit chan struct{}, formats types.Types, errorChannel chan<- error) {
defer func() { defer func() {
wg0.Done() wg1.Done()
}() }()
limit <- struct{}{} limit <- struct{}{}
@ -283,24 +283,21 @@ func walkPath(path string, fileChannel chan<- string, wg0 *sync.WaitGroup, stats
stats.directoriesMatched <- 1 stats.directoriesMatched <- 1
} }
var wg1 sync.WaitGroup var wg2 sync.WaitGroup
wg1.Add(1)
go func() {
defer wg1.Done()
for _, node := range nodes { for _, node := range nodes {
wg1.Add(1) wg2.Add(1)
go func(node fs.DirEntry) { go func(node fs.DirEntry) {
defer wg1.Done() defer wg2.Done()
fullPath := filepath.Join(path, node.Name()) fullPath := filepath.Join(path, node.Name())
switch { switch {
case node.IsDir() && Recursive: case node.IsDir() && Recursive:
wg0.Add(1) wg1.Add(1)
walkPath(fullPath, fileChannel, wg0, stats, limit, formats, errorChannel) walkPath(fullPath, fileChannel, wg1, stats, limit, formats, errorChannel)
case !node.IsDir() && !skipFiles: case !node.IsDir() && !skipFiles:
path, err := normalizePath(fullPath) path, err := normalizePath(fullPath)
if err != nil { if err != nil {
@ -323,9 +320,8 @@ func walkPath(path string, fileChannel chan<- string, wg0 *sync.WaitGroup, stats
} }
}(node) }(node)
} }
}()
wg1.Wait() wg2.Wait()
} }
func scanPaths(paths []string, sort string, index *fileIndex, formats types.Types, errorChannel chan<- error) []string { func scanPaths(paths []string, sort string, index *fileIndex, formats types.Types, errorChannel chan<- error) []string {
@ -346,7 +342,11 @@ func scanPaths(paths []string, sort string, index *fileIndex, formats types.Type
var list []string var list []string
var wg0 sync.WaitGroup
wg0.Add(1)
go func() { go func() {
defer wg0.Done()
for { for {
select { select {
case path := <-fileChannel: case path := <-fileChannel:
@ -357,7 +357,10 @@ func scanPaths(paths []string, sort string, index *fileIndex, formats types.Type
} }
}() }()
wg0.Add(1)
go func() { go func() {
defer wg0.Done()
for { for {
select { select {
case stat := <-stats.filesMatched: case stat := <-stats.filesMatched:
@ -368,7 +371,10 @@ func scanPaths(paths []string, sort string, index *fileIndex, formats types.Type
} }
}() }()
wg0.Add(1)
go func() { go func() {
defer wg0.Done()
for { for {
select { select {
case stat := <-stats.filesSkipped: case stat := <-stats.filesSkipped:
@ -379,7 +385,10 @@ func scanPaths(paths []string, sort string, index *fileIndex, formats types.Type
} }
}() }()
wg0.Add(1)
go func() { go func() {
defer wg0.Done()
for { for {
select { select {
case stat := <-stats.directoriesMatched: case stat := <-stats.directoriesMatched:
@ -390,7 +399,10 @@ func scanPaths(paths []string, sort string, index *fileIndex, formats types.Type
} }
}() }()
wg0.Add(1)
go func() { go func() {
defer wg0.Done()
for { for {
select { select {
case stat := <-stats.directoriesSkipped: case stat := <-stats.directoriesSkipped:
@ -403,20 +415,22 @@ func scanPaths(paths []string, sort string, index *fileIndex, formats types.Type
limit := make(chan struct{}, Concurrency) limit := make(chan struct{}, Concurrency)
var wg0 sync.WaitGroup var wg1 sync.WaitGroup
for i := 0; i < len(paths); i++ { for i := 0; i < len(paths); i++ {
wg0.Add(1) wg1.Add(1)
go func(i int) { go func(i int) {
walkPath(paths[i], fileChannel, &wg0, stats, limit, formats, errorChannel) walkPath(paths[i], fileChannel, &wg1, stats, limit, formats, errorChannel)
}(i) }(i)
} }
wg0.Wait() wg1.Wait()
close(done) close(done)
wg0.Wait()
if Verbose { if Verbose {
fmt.Printf("%s | INDEX: Selected %d/%d files across %d/%d directories in %s\n", fmt.Printf("%s | INDEX: Selected %d/%d files across %d/%d directories in %s\n",
time.Now().Format(logDate), time.Now().Format(logDate),

View File

@ -17,7 +17,7 @@ import (
const ( const (
AllowedCharacters string = `^[A-z0-9.\-_]+$` AllowedCharacters string = `^[A-z0-9.\-_]+$`
ReleaseVersion string = "5.0.0" ReleaseVersion string = "5.0.2"
) )
var ( var (