mirror of
https://github.com/rclone/rclone.git
synced 2024-11-25 09:41:44 +08:00
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
This commit is contained in:
parent
58d82a5c73
commit
d0f8b4f479
16
fs/cache/cache.go
vendored
16
fs/cache/cache.go
vendored
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user