mirror of
https://github.com/rclone/rclone.git
synced 2024-11-22 09:32:29 +08:00
vfs: create cache.opens and use it in place of cache.get to avoid potential race
This commit is contained in:
parent
724120d2f3
commit
88d830c7b7
14
vfs/cache.go
14
vfs/cache.go
|
@ -161,6 +161,20 @@ func (c *cache) _get(isFile bool, name string) (item *cacheItem, found bool) {
|
|||
return item, found
|
||||
}
|
||||
|
||||
// opens returns the number of opens that are on the file
|
||||
//
|
||||
// name should be a remote path not an osPath
|
||||
func (c *cache) opens(name string) int {
|
||||
name = clean(name)
|
||||
c.itemMu.Lock()
|
||||
defer c.itemMu.Unlock()
|
||||
item := c.item[name]
|
||||
if item == nil {
|
||||
return 0
|
||||
}
|
||||
return item.opens
|
||||
}
|
||||
|
||||
// get gets name from the cache or creates a new one
|
||||
//
|
||||
// name should be a remote path not an osPath
|
||||
|
|
|
@ -431,8 +431,8 @@ func (f *File) Open(flags int) (fd Handle, err error) {
|
|||
|
||||
// Open the correct sort of handle
|
||||
CacheMode := f.d.vfs.Opt.CacheMode
|
||||
CacheItem := f.d.vfs.cache.get(f.Path())
|
||||
if CacheMode >= CacheModeMinimal && CacheItem.opens > 0 {
|
||||
opens := f.d.vfs.cache.opens(f.Path())
|
||||
if CacheMode >= CacheModeMinimal && opens > 0 {
|
||||
fd, err = f.openRW(flags)
|
||||
} else if read && write {
|
||||
if CacheMode >= CacheModeMinimal {
|
||||
|
|
Loading…
Reference in New Issue
Block a user