From d0f8b4f479856ac4ea23c60527514d5bade6a4ff Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Tue, 30 Mar 2021 17:47:44 +0100 Subject: [PATCH] fs/cache: fix recreation of backends after they have expired Before this change, on the first attempt to create a backend we used a non-canonicalized string. When the backend expired the second attempt to create it would use the canonicalized string (because it was in the remap cache) which would fail because it was now `name{XXXX}:` This change makes sure that whenever we create a backend we always use the non-canonicalized string. See: https://forum.rclone.org/t/connection-string-inconsistencies-on-beta/23171 --- fs/cache/cache.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/fs/cache/cache.go b/fs/cache/cache.go index 77d99fbec..f59561888 100644 --- a/fs/cache/cache.go +++ b/fs/cache/cache.go @@ -56,10 +56,10 @@ func addMapping(fsString, canonicalName string) { // it afresh with the create function func GetFn(ctx context.Context, fsString string, create func(ctx context.Context, fsString string) (fs.Fs, error)) (f fs.Fs, err error) { createOnFirstUse() - fsString = Canonicalize(fsString) + canonicalFsString := Canonicalize(fsString) created := false - value, err := c.Get(fsString, func(fsString string) (f interface{}, ok bool, err error) { - f, err = create(ctx, fsString) + value, err := c.Get(canonicalFsString, func(canonicalFsString string) (f interface{}, ok bool, err error) { + f, err = create(ctx, fsString) // always create the backend with the original non-canonicalised string ok = err == nil || err == fs.ErrorIsFile created = ok return f, ok, err @@ -71,19 +71,19 @@ func GetFn(ctx context.Context, fsString string, create func(ctx context.Context // Check we stored the Fs at the canonical name if created { canonicalName := fs.ConfigString(f) - if canonicalName != fsString { + if canonicalName != canonicalFsString { // Note that if err == fs.ErrorIsFile at this moment // then we can't rename the remote as it will have the // wrong error status, we need to add a new one. if err == nil { - fs.Debugf(nil, "fs cache: renaming cache item %q to be canonical %q", fsString, canonicalName) - value, found := c.Rename(fsString, canonicalName) + fs.Debugf(nil, "fs cache: renaming cache item %q to be canonical %q", canonicalFsString, canonicalName) + value, found := c.Rename(canonicalFsString, canonicalName) if found { f = value.(fs.Fs) } - addMapping(fsString, canonicalName) + addMapping(canonicalFsString, canonicalName) } else { - fs.Debugf(nil, "fs cache: adding new entry for parent of %q, %q", fsString, canonicalName) + fs.Debugf(nil, "fs cache: adding new entry for parent of %q, %q", canonicalFsString, canonicalName) Put(canonicalName, f) } }