mirror of
https://github.com/rclone/rclone.git
synced 2025-02-22 21:41:35 +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:
parent
628530362a
commit
6a2a075c14
4
fs/cache/cache.go
vendored
4
fs/cache/cache.go
vendored
@ -27,12 +27,10 @@ type cacheEntry struct {
|
|||||||
// Get gets a fs.Fs named fsString either from the cache or creates it afresh
|
// Get gets a fs.Fs named fsString either from the cache or creates it afresh
|
||||||
func Get(fsString string) (f fs.Fs, err error) {
|
func Get(fsString string) (f fs.Fs, err error) {
|
||||||
fsCacheMu.Lock()
|
fsCacheMu.Lock()
|
||||||
defer fsCacheMu.Unlock()
|
|
||||||
entry, ok := fsCache[fsString]
|
entry, ok := fsCache[fsString]
|
||||||
if !ok {
|
if !ok {
|
||||||
fsCacheMu.Unlock() // Unlock in case Get is called recursively
|
fsCacheMu.Unlock() // Unlock in case Get is called recursively
|
||||||
f, err = fsNewFs(fsString)
|
f, err = fsNewFs(fsString)
|
||||||
fsCacheMu.Lock()
|
|
||||||
if err != nil && err != fs.ErrorIsFile {
|
if err != nil && err != fs.ErrorIsFile {
|
||||||
return f, err
|
return f, err
|
||||||
}
|
}
|
||||||
@ -41,8 +39,10 @@ func Get(fsString string) (f fs.Fs, err error) {
|
|||||||
fsString: fsString,
|
fsString: fsString,
|
||||||
err: err,
|
err: err,
|
||||||
}
|
}
|
||||||
|
fsCacheMu.Lock()
|
||||||
fsCache[fsString] = entry
|
fsCache[fsString] = entry
|
||||||
}
|
}
|
||||||
|
defer fsCacheMu.Unlock()
|
||||||
entry.lastUsed = time.Now()
|
entry.lastUsed = time.Now()
|
||||||
if !expireRunning {
|
if !expireRunning {
|
||||||
time.AfterFunc(cacheExpireInterval, cacheExpire)
|
time.AfterFunc(cacheExpireInterval, cacheExpire)
|
||||||
|
Loading…
Reference in New Issue
Block a user