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

vfs: pin the Fs in use in the Fs cache

Nick Craig-Wood70db13e6e8aa
diff --git a/vfs/vfs.go b/vfs/vfs.go
index 82e6a7efc..9e0eaa59b 100644
--- a/vfs/vfs.go
+++ b/vfs/vfs.go
@@ -34,6 +34,7 @@ import (
"time"
"github.com/rclone/rclone/fs"
+ "github.com/rclone/rclone/fs/cache"
"github.com/rclone/rclone/fs/log"
"github.com/rclone/rclone/vfs/vfscache"
"github.com/rclone/rclone/vfs/vfscommon"
@@ -204,6 +205,11 @@ func New(f fs.Fs, opt *vfscommon.Options) *VFS {
// add the remote control
vfs.addRC()
+
+ // Pin the Fs into the cache so that when we use cache.NewFs
+ // with the same remote string we get this one. The Pin is
+ // removed by Shutdown
+ cache.Pin(f)
return vfs
}
@@ -233,6 +239,8 @@ func (vfs *VFS) SetCacheMode(cacheMode vfscommon.CacheMode) {
// Shutdown stops any background go-routines
func (vfs *VFS) Shutdown() {
+ // Unpin the Fs from the cache
+ cache.Unpin(vfs.f)
if vfs.cancel != nil {
vfs.cancel()
vfs.cancel = nil