From 843d684568bb93a099f5efe00dbb0045f01d55c2 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Fri, 6 Nov 2020 16:44:05 +0000 Subject: [PATCH] vfs: fix vfs/refresh calls with fs= parameter Before this change rclone gave an error when the fs parameter was provided. This change removes the fs parameter from the parameters once it has been read which avoids the error. See: https://forum.rclone.org/t/precaching-with-vfs-refresh-fails-with-an-error-when-having-multiple-cloud-drives/20267 --- vfs/rc.go | 3 +++ vfs/rc_test.go | 7 +++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/vfs/rc.go b/vfs/rc.go index 2fde29d1c..fd9c01e46 100644 --- a/vfs/rc.go +++ b/vfs/rc.go @@ -23,6 +23,8 @@ must be supplied.` // // If "fs" is not set and there is one and only one VFS in the active // cache then it returns it. This is for backwards compatibility. +// +// This deletes the "fs" parameter from in if it is valid func getVFS(in rc.Params) (vfs *VFS, err error) { fsString, err := in.GetString("fs") if rc.IsErrParamNotFound(err) { @@ -46,6 +48,7 @@ func getVFS(in rc.Params) (vfs *VFS, err error) { } else if len(activeVFS) > 1 { return nil, errors.Errorf("more than one VFS active with name %q", fsString) } + delete(in, "fs") // delete the fs parameter return activeVFS[0], nil } diff --git a/vfs/rc_test.go b/vfs/rc_test.go index 0e31ef0a9..096ce5768 100644 --- a/vfs/rc_test.go +++ b/vfs/rc_test.go @@ -57,6 +57,7 @@ func TestRcGetVFS(t *testing.T) { assert.Contains(t, err.Error(), "more than one VFS active - need") assert.Nil(t, vfs) + inPresent = rc.Params{"fs": fs.ConfigString(r.Fremote)} vfs, err = getVFS(inPresent) require.Error(t, err) assert.Contains(t, err.Error(), "more than one VFS active with name") @@ -67,7 +68,8 @@ func TestRcForget(t *testing.T) { r, vfs, cleanup, call := rcNewRun(t, "vfs/forget") defer cleanup() _, _ = r, vfs - out, err := call.Fn(context.Background(), nil) + in := rc.Params{"fs": fs.ConfigString(r.Fremote)} + out, err := call.Fn(context.Background(), in) require.NoError(t, err) assert.Equal(t, rc.Params{ "forgotten": []string{}, @@ -79,7 +81,8 @@ func TestRcRefresh(t *testing.T) { r, vfs, cleanup, call := rcNewRun(t, "vfs/refresh") defer cleanup() _, _ = r, vfs - out, err := call.Fn(context.Background(), nil) + in := rc.Params{"fs": fs.ConfigString(r.Fremote)} + out, err := call.Fn(context.Background(), in) require.NoError(t, err) assert.Equal(t, rc.Params{ "result": map[string]string{