mirror of
https://github.com/rclone/rclone.git
synced 2026-01-04 17:43:50 +00:00
vfs: Only make the VFS cache if --vfs-cache-mode > Off
This stops the cache cleaner running unnecessarily and saves resources. This also helps with issue #2227 which was caused by a second mount deleting objects in the first mounts cache.
This commit is contained in:
31
vfs/vfs.go
31
vfs/vfs.go
@@ -224,21 +224,31 @@ func New(f fs.Fs, opt *Options) *VFS {
|
||||
}
|
||||
}
|
||||
|
||||
// Create the cache
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
vfs.cancel = cancel
|
||||
cache, err := newCache(ctx, f, &vfs.Opt) // FIXME pass on context or get from Opt?
|
||||
if err != nil {
|
||||
// FIXME
|
||||
panic(fmt.Sprintf("failed to create local cache: %v", err))
|
||||
}
|
||||
vfs.cache = cache
|
||||
vfs.SetCacheMode(vfs.Opt.CacheMode)
|
||||
|
||||
// add the remote control
|
||||
vfs.addRC()
|
||||
return vfs
|
||||
}
|
||||
|
||||
// SetCacheMode change the cache mode
|
||||
func (vfs *VFS) SetCacheMode(cacheMode CacheMode) {
|
||||
vfs.Shutdown()
|
||||
vfs.cache = nil
|
||||
if vfs.Opt.CacheMode > CacheModeOff {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
cache, err := newCache(ctx, vfs.f, &vfs.Opt) // FIXME pass on context or get from Opt?
|
||||
if err != nil {
|
||||
fs.Errorf(nil, "Failed to create vfs cache - disabling: %v", err)
|
||||
vfs.Opt.CacheMode = CacheModeOff
|
||||
cancel()
|
||||
return
|
||||
}
|
||||
vfs.cancel = cancel
|
||||
vfs.cache = cache
|
||||
}
|
||||
}
|
||||
|
||||
// Shutdown stops any background go-routines
|
||||
func (vfs *VFS) Shutdown() {
|
||||
if vfs.cancel != nil {
|
||||
@@ -249,6 +259,9 @@ func (vfs *VFS) Shutdown() {
|
||||
|
||||
// CleanUp deletes the contents of the on disk cache
|
||||
func (vfs *VFS) CleanUp() error {
|
||||
if vfs.Opt.CacheMode == CacheModeOff {
|
||||
return nil
|
||||
}
|
||||
return vfs.cache.cleanUp()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user