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

fs/cache: fix locking

Nick Craig-Wood6a2a075c1400
diff --git a/fs/cache/cache.go b/fs/cache/cache.go
index 569209834..65a1fd52e 100644
--- a/fs/cache/cache.go
+++ b/fs/cache/cache.go
@@ -27,12 +27,10 @@ type cacheEntry struct {
// Get gets a fs.Fs named fsString either from the cache or creates it afresh
func Get(fsString string) (f fs.Fs, err error) {
fsCacheMu.Lock()
- defer fsCacheMu.Unlock()
entry, ok := fsCache[fsString]
if !ok {
fsCacheMu.Unlock() // Unlock in case Get is called recursively
f, err = fsNewFs(fsString)
- fsCacheMu.Lock()
if err != nil && err != fs.ErrorIsFile {
return f, err
}
@@ -41,8 +39,10 @@ func Get(fsString string) (f fs.Fs, err error) {
fsString: fsString,
err: err,
}
+ fsCacheMu.Lock()
fsCache[fsString] = entry
}
+ defer fsCacheMu.Unlock()
entry.lastUsed = time.Now()
if !expireRunning {
time.AfterFunc(cacheExpireInterval, cacheExpire)