Solve the race condition when recursively reading files, hopefully

This commit is contained in:
2024-07-01 20:56:16 +02:00
parent 0a627ae9ca
commit e022a838ba

View File

@@ -75,6 +75,7 @@ func GetSyncFilesRecursively(input string, output chan string, status chan error
var wg sync.WaitGroup var wg sync.WaitGroup
var initial sync.Once var initial sync.Once
var done bool
wg.Add(1) wg.Add(1)
directories := make(chan string, 100000) directories := make(chan string, 100000)
workerPool := make(chan struct{}, 4000) workerPool := make(chan struct{}, 4000)
@@ -117,12 +118,12 @@ func GetSyncFilesRecursively(input string, output chan string, status chan error
} }
} }
// log.Printf("Done reading directory %s", directory) // log.Printf("Done reading directory %s", directory)
done = len(directories) == 0
if done {
initial.Do(func() { initial.Do(func() {
// Parallelism is very difficult...
time.Sleep(250 * time.Millisecond)
wg.Done() wg.Done()
}) })
}
}(directory) }(directory)
} }
}() }()