From e022a838bae6d56122854f718fe9c464e10b6d25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Majdand=C5=BEi=C4=87?= Date: Mon, 1 Jul 2024 20:56:16 +0200 Subject: [PATCH] Solve the race condition when recursively reading files, hopefully --- util.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/util.go b/util.go index f237f8b..83570e2 100644 --- a/util.go +++ b/util.go @@ -75,6 +75,7 @@ func GetSyncFilesRecursively(input string, output chan string, status chan error var wg sync.WaitGroup var initial sync.Once + var done bool wg.Add(1) directories := make(chan string, 100000) 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) - - initial.Do(func() { - // Parallelism is very difficult... - time.Sleep(250 * time.Millisecond) - wg.Done() - }) + done = len(directories) == 0 + if done { + initial.Do(func() { + wg.Done() + }) + } }(directory) } }()