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

fs/cache: fix recreation of backends after they have expired

Nick Craig-Woodd0f8b4f47985
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)
}
}