From eb5a95e7de1e6b05307bcbf020965c0c5330f009 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20M=C3=B6ller?= Date: Sat, 8 Sep 2018 13:02:19 +0200 Subject: [PATCH] crypt: 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". --- backend/crypt/crypt.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/backend/crypt/crypt.go b/backend/crypt/crypt.go index a5c6cccd5..1feded4ee 100644 --- a/backend/crypt/crypt.go +++ b/backend/crypt/crypt.go @@ -130,16 +130,20 @@ 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) + } // Look for a file first - remotePath := path.Join(remote, cipher.EncryptFileName(rpath)) - wrappedFs, err := fs.NewFs(remotePath) + remotePath := path.Join(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 = path.Join(remote, cipher.EncryptDirName(rpath)) - wrappedFs, err = fs.NewFs(remotePath) + remotePath = path.Join(wPath, cipher.EncryptDirName(rpath)) + wrappedFs, err = wInfo.NewFs(wName, remotePath, wConfig) } if err != fs.ErrorIsFile && err != nil { - return nil, errors.Wrapf(err, "failed to make remote %q to wrap", remotePath) + return nil, errors.Wrapf(err, "failed to make remote %s:%q to wrap", wName, remotePath) } f := &Fs{ Fs: wrappedFs,