Solve the race condition when recursively reading files, hopefully
This commit is contained in:
13
util.go
13
util.go
@@ -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
|
||||||
initial.Do(func() {
|
if done {
|
||||||
// Parallelism is very difficult...
|
initial.Do(func() {
|
||||||
time.Sleep(250 * time.Millisecond)
|
wg.Done()
|
||||||
wg.Done()
|
})
|
||||||
})
|
}
|
||||||
}(directory)
|
}(directory)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
Reference in New Issue
Block a user