Rework filewalk function yet again

This commit is contained in:
Seednode 2023-10-05 16:33:23 -05:00
parent 3e6ad89ea4
commit 9d789cb439
2 changed files with 42 additions and 22 deletions

View File

@ -326,16 +326,16 @@ func scanPaths(paths []string, sort string, index *fileIndex, formats types.Type
var list []string var list []string
var filesMatched int = 0 var filesMatched int
var filesSkipped int = 0 var filesSkipped int
var directoriesMatched int = 0 var directoriesMatched int
var directoriesSkipped int = 0 var directoriesSkipped int
var wg sync.WaitGroup var wg sync.WaitGroup
fileChannel := make(chan string) fileChannel := make(chan string)
errorChannel := make(chan error) errorChannel := make(chan error)
done := make(chan bool, 1) done := make(chan bool)
statsChannels := &scanStatsChannels{ statsChannels := &scanStatsChannels{
filesMatched: make(chan int), filesMatched: make(chan int),
@ -345,32 +345,57 @@ func scanPaths(paths []string, sort string, index *fileIndex, formats types.Type
} }
go func() { go func() {
for path := range fileChannel { for {
list = append(list, path) select {
case path := <-fileChannel:
list = append(list, path)
case <-done:
return
}
} }
}() }()
go func() { go func() {
for stat := range statsChannels.filesMatched { for {
filesMatched += stat select {
case stat := <-statsChannels.filesMatched:
filesMatched += stat
case <-done:
return
}
} }
}() }()
go func() { go func() {
for stat := range statsChannels.filesSkipped { for {
filesSkipped += stat select {
case stat := <-statsChannels.filesSkipped:
filesSkipped += stat
case <-done:
return
}
} }
}() }()
go func() { go func() {
for stat := range statsChannels.directoriesMatched { for {
directoriesMatched += stat select {
case stat := <-statsChannels.directoriesMatched:
directoriesMatched += stat
case <-done:
return
}
} }
}() }()
go func() { go func() {
for stat := range statsChannels.directoriesSkipped { for {
directoriesSkipped += stat select {
case stat := <-statsChannels.directoriesSkipped:
directoriesSkipped += stat
case <-done:
return
}
} }
}() }()
@ -394,12 +419,7 @@ func scanPaths(paths []string, sort string, index *fileIndex, formats types.Type
go func() { go func() {
wg.Wait() wg.Wait()
done <- true close(done)
close(statsChannels.filesMatched)
close(statsChannels.filesSkipped)
close(statsChannels.directoriesMatched)
close(statsChannels.directoriesSkipped)
}() }()
Poll: Poll:

View File

@ -12,7 +12,7 @@ import (
) )
const ( const (
ReleaseVersion string = "2.7.1" ReleaseVersion string = "2.7.2"
) )
var ( var (