From 70db13e6e8aa710d8343e291988c7077b3b7d9c3 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Fri, 1 May 2020 12:53:31 +0100 Subject: [PATCH] vfs: pin the Fs in use in the Fs cache This means we can reliably look up the Fs from the cache when using `backend/command`. --- vfs/vfs.go | 8 ++++++++ 1 file changed, 8 insertions(+) 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