forked from TrueCloudLab/rclone
core: fix data race in walk
This was detected by the race detector when the client of Walk() sorted entries.
This commit is contained in:
parent
9876ba53f8
commit
5250fcdf08
1 changed files with 12 additions and 11 deletions
23
fs/walk.go
23
fs/walk.go
|
@ -117,9 +117,20 @@ func walk(f Fs, path string, includeAll bool, maxLevel int, fn WalkFunc, listDir
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
entries, err := listDir(f, includeAll, job.remote)
|
entries, err := listDir(f, includeAll, job.remote)
|
||||||
|
var jobs []listJob
|
||||||
|
if err == nil && job.depth != 0 {
|
||||||
|
entries.ForDir(func(dir *Dir) {
|
||||||
|
// Recurse for the directory
|
||||||
|
jobs = append(jobs, listJob{
|
||||||
|
remote: dir.Remote(),
|
||||||
|
depth: job.depth - 1,
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
mu.Lock()
|
mu.Lock()
|
||||||
err = fn(job.remote, entries, err)
|
err = fn(job.remote, entries, err)
|
||||||
mu.Unlock()
|
mu.Unlock()
|
||||||
|
// NB once we have passed entries to fn we mustn't touch it again
|
||||||
if err != nil && err != ErrorSkipDir {
|
if err != nil && err != ErrorSkipDir {
|
||||||
traversing.Done()
|
traversing.Done()
|
||||||
Stats.Error()
|
Stats.Error()
|
||||||
|
@ -132,17 +143,7 @@ func walk(f Fs, path string, includeAll bool, maxLevel int, fn WalkFunc, listDir
|
||||||
}
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
var jobs []listJob
|
if err == nil && len(jobs) > 0 {
|
||||||
if job.depth != 0 && err == nil {
|
|
||||||
entries.ForDir(func(dir *Dir) {
|
|
||||||
// Recurse for the directory
|
|
||||||
jobs = append(jobs, listJob{
|
|
||||||
remote: dir.Remote(),
|
|
||||||
depth: job.depth - 1,
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
|
||||||
if len(jobs) > 0 {
|
|
||||||
traversing.Add(len(jobs))
|
traversing.Add(len(jobs))
|
||||||
go func() {
|
go func() {
|
||||||
// Now we have traversed this directory, send these
|
// Now we have traversed this directory, send these
|
||||||
|
|
Loading…
Reference in a new issue