1
mirror of https://github.com/rclone/rclone synced 2024-12-17 06:25:56 +01:00

fs/cache: fix locking

This was causing `fatal error: sync: unlock of unlocked mutex` if a
panic ocurred in fsNewFs.
This commit is contained in:
Nick Craig-Wood 2019-06-19 10:43:26 +01:00
parent 628530362a
commit 6a2a075c14

4
fs/cache/cache.go vendored
View File

@ -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)