From f6ee0795ac5e09946cbf1608b0b50fd28011325e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20M=C3=B6ller?= Date: Sat, 8 Sep 2018 14:52:24 +0200 Subject: [PATCH] cache: preserve leading / in wrapped remote path When combining the remote value and the root path, preserve the absence or presence of the / at the beginning of the wrapped remote path. e.g. a remote "cloud:" and root path "dir" becomes "cloud:dir" instead of "cloud:/dir". Fixes #2553 --- backend/cache/cache.go | 11 ++++++++--- docs/content/cache.md | 13 +++++++++++++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/backend/cache/cache.go b/backend/cache/cache.go index 1ae3fefe0..f9e4d8899 100644 --- a/backend/cache/cache.go +++ b/backend/cache/cache.go @@ -263,10 +263,15 @@ func NewFs(name, rootPath string, m configmap.Mapper) (fs.Fs, error) { return nil, errors.Wrapf(err, "failed to clean root path %q", rootPath) } - remotePath := path.Join(opt.Remote, rpath) - wrappedFs, wrapErr := fs.NewFs(remotePath) + 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 := path.Join(wPath, rootPath) + wrappedFs, wrapErr := wInfo.NewFs(wName, remotePath, wConfig) if wrapErr != nil && wrapErr != fs.ErrorIsFile { - return nil, errors.Wrapf(wrapErr, "failed to make remote %q to wrap", remotePath) + return nil, errors.Wrapf(wrapErr, "failed to make remote %s:%s to wrap", wName, remotePath) } var fsErr error fs.Debugf(name, "wrapped %v:%v at root %v", wrappedFs.Name(), wrappedFs.Root(), rpath) diff --git a/docs/content/cache.md b/docs/content/cache.md index 2696e10dc..8e9fef8cb 100644 --- a/docs/content/cache.md +++ b/docs/content/cache.md @@ -243,6 +243,19 @@ which makes it think we're downloading the full file instead of small chunks. Organizing the remotes in this order yelds better results: **cloud remote** -> **cache** -> **crypt** +#### absolute remote paths #### + +`cache` can not differentiate between relative and absolute paths for the wrapped remote. +Any path given in the `remote` config setting and on the command line will be passed to +the wrapped remote as is, but for storing the chunks on disk the path will be made +relative by removing any leading `/` character. + +This behavior is irrelevant for most backend types, but there are backends where a leading `/` +changes the effective directory, e.g. in the `sftp` backend paths starting with a `/` are +relative to the root of the SSH server and paths without are relative to the user home directory. +As a result `sftp:bin` and `sftp:/bin` will share the same cache folder, even if they represent +a different directory on the SSH server. + ### Cache and Remote Control (--rc) ### Cache supports the new `--rc` mode in rclone and can be remote controlled through the following end points: By default, the listener is disabled if you do not add the flag.