Rename scanStatsChannel => scanStats, add workaround for occasionally missing single file when indexing

This commit is contained in:
Seednode 2024-01-05 07:29:16 -06:00
parent 89637c12b2
commit ccff56d28d
2 changed files with 16 additions and 11 deletions

View File

@ -28,7 +28,7 @@ type regexes struct {
filename *regexp.Regexp filename *regexp.Regexp
} }
type scanStatsChannels struct { type scanStats struct {
filesMatched chan int filesMatched chan int
filesSkipped chan int filesSkipped chan int
directoriesMatched chan int directoriesMatched chan int
@ -42,12 +42,12 @@ func humanReadableSize(bytes int) string {
if BinaryPrefix { if BinaryPrefix {
unit = 1024 unit = 1024
suffix = "iB"
prefixes = "KMGTPE" prefixes = "KMGTPE"
suffix = "iB"
} else { } else {
unit = 1000 unit = 1000
suffix = "B"
prefixes = "kMGTPE" prefixes = "kMGTPE"
suffix = "B"
} }
if bytes < unit { if bytes < unit {
@ -235,7 +235,7 @@ func hasSupportedFiles(path string, formats types.Types) (bool, error) {
} }
} }
func walkPath(path string, fileChannel chan<- string, stats *scanStatsChannels, limit chan struct{}, formats types.Types) error { func walkPath(path string, fileChannel chan<- string, stats *scanStats, limit chan struct{}, formats types.Types) error {
limit <- struct{}{} limit <- struct{}{}
defer func() { defer func() {
@ -349,7 +349,7 @@ func scanPaths(paths []string, sort string, index *fileIndex, formats types.Type
errorChannel := make(chan error) errorChannel := make(chan error)
done := make(chan bool) done := make(chan bool)
statsChannels := &scanStatsChannels{ stats := &scanStats{
filesMatched: make(chan int), filesMatched: make(chan int),
filesSkipped: make(chan int), filesSkipped: make(chan int),
directoriesMatched: make(chan int), directoriesMatched: make(chan int),
@ -372,7 +372,7 @@ func scanPaths(paths []string, sort string, index *fileIndex, formats types.Type
go func() { go func() {
for { for {
select { select {
case stat := <-statsChannels.filesMatched: case stat := <-stats.filesMatched:
filesMatched += stat filesMatched += stat
case <-done: case <-done:
return return
@ -383,7 +383,7 @@ func scanPaths(paths []string, sort string, index *fileIndex, formats types.Type
go func() { go func() {
for { for {
select { select {
case stat := <-statsChannels.filesSkipped: case stat := <-stats.filesSkipped:
filesSkipped += stat filesSkipped += stat
case <-done: case <-done:
return return
@ -394,7 +394,7 @@ func scanPaths(paths []string, sort string, index *fileIndex, formats types.Type
go func() { go func() {
for { for {
select { select {
case stat := <-statsChannels.directoriesMatched: case stat := <-stats.directoriesMatched:
directoriesMatched += stat directoriesMatched += stat
case <-done: case <-done:
return return
@ -405,7 +405,7 @@ func scanPaths(paths []string, sort string, index *fileIndex, formats types.Type
go func() { go func() {
for { for {
select { select {
case stat := <-statsChannels.directoriesSkipped: case stat := <-stats.directoriesSkipped:
directoriesSkipped += stat directoriesSkipped += stat
case <-done: case <-done:
return return
@ -425,7 +425,7 @@ func scanPaths(paths []string, sort string, index *fileIndex, formats types.Type
wg.Done() wg.Done()
}() }()
err := walkPath(paths[i], fileChannel, statsChannels, limit, formats) err := walkPath(paths[i], fileChannel, stats, limit, formats)
if err != nil { if err != nil {
errorChannel <- err errorChannel <- err
@ -438,6 +438,11 @@ func scanPaths(paths []string, sort string, index *fileIndex, formats types.Type
go func() { go func() {
wg.Wait() wg.Wait()
// Without this delay, occasionally a single file is missed when indexing,
// presumably due to a timing issue with closing the done channel.
// Pending a proper fix.
time.Sleep((100 * time.Millisecond))
close(done) close(done)
}() }()

View File

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