Skip to content

"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files

mountlib: fix race condition in cache clear

Nick Craig-Wood2cae0177387e
diff --git a/cmd/mountlib/dir.go b/cmd/mountlib/dir.go
index 214082241..d8ea6ae74 100644
--- a/cmd/mountlib/dir.go
+++ b/cmd/mountlib/dir.go
@@ -96,6 +96,8 @@ func (d *Dir) ForgetPath(relativePath string) {
// children first. It will not apply the function to parent
// nodes, regardless of the given path.
func (d *Dir) walk(absPath string, fun func(*Dir)) {
+ d.mu.Lock()
+ defer d.mu.Unlock()
if d.items != nil {
for _, entry := range d.items {
if dir, ok := entry.Node.(*Dir); ok {
@@ -105,8 +107,6 @@ func (d *Dir) walk(absPath string, fun func(*Dir)) {
}
if d.path == absPath || absPath == "" || strings.HasPrefix(d.path, absPath+"/") {
- d.mu.Lock()
- defer d.mu.Unlock()
fun(d)
}
}