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

alias,cache,chunker,crypt: make any created backends be cached to fix rc problems

Nick Craig-Wood0d066bdf468b
diff --git a/backend/alias/alias.go b/backend/alias/alias.go
index f708ca265..873320e98 100644
--- a/backend/alias/alias.go
+++ b/backend/alias/alias.go
@@ -5,6 +5,7 @@ import (
"strings"
"github.com/rclone/rclone/fs"
+ "github.com/rclone/rclone/fs/cache"
"github.com/rclone/rclone/fs/config/configmap"
"github.com/rclone/rclone/fs/config/configstruct"
"github.com/rclone/rclone/fs/fspath"
@@ -46,9 +47,5 @@ func NewFs(name, root string, m configmap.Mapper) (fs.Fs, error) {
if strings.HasPrefix(opt.Remote, name+":") {
return nil, errors.New("can't point alias remote at itself - check the value of the remote setting")
}
- fsInfo, configName, fsPath, config, err := fs.ConfigFs(opt.Remote)
- if err != nil {
- return nil, err
- }
- return fsInfo.NewFs(configName, fspath.JoinRootPath(fsPath, root), config)
+ return cache.Get(fspath.JoinRootPath(opt.Remote, root))
}
diff --git a/backend/cache/cache.go b/backend/cache/cache.go
index 08fd83034..13d1143e9 100644
--- a/backend/cache/cache.go
+++ b/backend/cache/cache.go
@@ -361,15 +361,10 @@ func NewFs(name, rootPath string, m configmap.Mapper) (fs.Fs, error) {
return nil, errors.Wrapf(err, "failed to clean root path %q", rootPath)
}
- wInfo, wName, wPath, wConfig, err := fs.ConfigFs(opt.Remote)
- if err != nil {
- return nil, errors.Wrapf(err, "failed to parse remote %q to wrap", opt.Remote)
- }
-
- remotePath := fspath.JoinRootPath(wPath, rootPath)
- wrappedFs, wrapErr := wInfo.NewFs(wName, remotePath, wConfig)
+ remotePath := fspath.JoinRootPath(opt.Remote, rootPath)
+ wrappedFs, wrapErr := cache.Get(remotePath)
if wrapErr != nil && wrapErr != fs.ErrorIsFile {
- return nil, errors.Wrapf(wrapErr, "failed to make remote %s:%s to wrap", wName, remotePath)
+ return nil, errors.Wrapf(wrapErr, "failed to make remote %q to wrap", remotePath)
}
var fsErr error
fs.Debugf(name, "wrapped %v:%v at root %v", wrappedFs.Name(), wrappedFs.Root(), rpath)
diff --git a/backend/chunker/chunker.go b/backend/chunker/chunker.go
index 74bebacef..8032bb6e4 100644
--- a/backend/chunker/chunker.go
+++ b/backend/chunker/chunker.go
@@ -24,6 +24,7 @@ import (
"github.com/pkg/errors"
"github.com/rclone/rclone/fs"
"github.com/rclone/rclone/fs/accounting"
+ "github.com/rclone/rclone/fs/cache"
"github.com/rclone/rclone/fs/config/configmap"
"github.com/rclone/rclone/fs/config/configstruct"
"github.com/rclone/rclone/fs/fspath"
@@ -238,15 +239,18 @@ func NewFs(name, rpath string, m configmap.Mapper) (fs.Fs, error) {
return nil, errors.New("can't point remote at itself - check the value of the remote setting")
}
- baseInfo, baseName, basePath, baseConfig, err := fs.ConfigFs(remote)
+ baseName, basePath, err := fspath.Parse(remote)
if err != nil {
return nil, errors.Wrapf(err, "failed to parse remote %q to wrap", remote)
}
+ if baseName != "" {
+ baseName += ":"
+ }
// Look for a file first
remotePath := fspath.JoinRootPath(basePath, rpath)
- baseFs, err := baseInfo.NewFs(baseName, remotePath, baseConfig)
+ baseFs, err := cache.Get(baseName + remotePath)
if err != fs.ErrorIsFile && err != nil {
- return nil, errors.Wrapf(err, "failed to make remote %s:%q to wrap", baseName, remotePath)
+ return nil, errors.Wrapf(err, "failed to make remote %q to wrap", baseName+remotePath)
}
if !operations.CanServerSideMove(baseFs) {
return nil, errors.New("can't use chunker on a backend which doesn't support server side move or copy")
@@ -271,7 +275,7 @@ func NewFs(name, rpath string, m configmap.Mapper) (fs.Fs, error) {
// (yet can't satisfy fstest.CheckListing, will ignore)
if err == nil && !f.useMeta && strings.Contains(rpath, "/") {
firstChunkPath := f.makeChunkName(remotePath, 0, "", "")
- _, testErr := baseInfo.NewFs(baseName, firstChunkPath, baseConfig)
+ _, testErr := cache.Get(baseName + firstChunkPath)
if testErr == fs.ErrorIsFile {
err = testErr
}
diff --git a/backend/crypt/crypt.go b/backend/crypt/crypt.go
index 9d2ad946b..b8f27f840 100644
--- a/backend/crypt/crypt.go
+++ b/backend/crypt/crypt.go
@@ -12,6 +12,7 @@ import (
"github.com/pkg/errors"
"github.com/rclone/rclone/fs"
"github.com/rclone/rclone/fs/accounting"
+ "github.com/rclone/rclone/fs/cache"
"github.com/rclone/rclone/fs/config/configmap"
"github.com/rclone/rclone/fs/config/configstruct"
"github.com/rclone/rclone/fs/config/obscure"
@@ -158,24 +159,25 @@ func NewFs(name, rpath string, m configmap.Mapper) (fs.Fs, error) {
if strings.HasPrefix(remote, name+":") {
return nil, errors.New("can't point crypt remote at itself - check the value of the remote setting")
}
- wInfo, wName, wPath, wConfig, err := fs.ConfigFs(remote)
- if err != nil {
- return nil, errors.Wrapf(err, "failed to parse remote %q to wrap", remote)
- }
// Make sure to remove trailing . reffering to the current dir
if path.Base(rpath) == "." {
rpath = strings.TrimSuffix(rpath, ".")
}
// Look for a file first
- remotePath := fspath.JoinRootPath(wPath, cipher.EncryptFileName(rpath))
- wrappedFs, err := wInfo.NewFs(wName, remotePath, wConfig)
- // if that didn't produce a file, look for a directory
- if err != fs.ErrorIsFile {
- remotePath = fspath.JoinRootPath(wPath, cipher.EncryptDirName(rpath))
- wrappedFs, err = wInfo.NewFs(wName, remotePath, wConfig)
+ var wrappedFs fs.Fs
+ if rpath == "" {
+ wrappedFs, err = cache.Get(remote)
+ } else {
+ remotePath := fspath.JoinRootPath(remote, cipher.EncryptFileName(rpath))
+ wrappedFs, err = cache.Get(remotePath)
+ // if that didn't produce a file, look for a directory
+ if err != fs.ErrorIsFile {
+ remotePath = fspath.JoinRootPath(remote, cipher.EncryptDirName(rpath))
+ wrappedFs, err = cache.Get(remotePath)
+ }
}
if err != fs.ErrorIsFile && err != nil {
- return nil, errors.Wrapf(err, "failed to make remote %s:%q to wrap", wName, remotePath)
+ return nil, errors.Wrapf(err, "failed to make remote %q to wrap", remote)
}
f := &Fs{
Fs: wrappedFs,