From 459cc70a50a61f20b336586678695cae207815c0 Mon Sep 17 00:00:00 2001 From: albertony <12441419+albertony@users.noreply.github.com> Date: Sat, 14 Nov 2020 00:37:54 +0100 Subject: [PATCH] vfs: fix invalid cache path on windows when using :backend: as remote The initial ':' is included in the ad-hoc remote name, but is illegal character in Windows path. Replacing it with '^', which is legal in filesystems but illegal in regular remote names, so name conflict is avoided. Fixes #4544 --- vfs/vfscache/cache.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/vfs/vfscache/cache.go b/vfs/vfscache/cache.go index bd7be51a3..2d1950ab0 100644 --- a/vfs/vfscache/cache.go +++ b/vfs/vfscache/cache.go @@ -74,21 +74,26 @@ type AddVirtualFn func(remote string, size int64, isDir bool) error // This starts background goroutines which can be cancelled with the // context passed in. func New(ctx context.Context, fremote fs.Fs, opt *vfscommon.Options, avFn AddVirtualFn) (*Cache, error) { + fName := fremote.Name() fRoot := filepath.FromSlash(fremote.Root()) if runtime.GOOS == "windows" { if strings.HasPrefix(fRoot, `\\?`) { fRoot = fRoot[3:] } fRoot = strings.Replace(fRoot, ":", "", -1) + // Replace leading ':' if remote was created on the fly as ":backend:/path" as it is illegal in Windows + if fName[0] == ':' { + fName = "^" + fName[1:] + } } cacheDir := config.CacheDir cacheDir, err := filepath.Abs(cacheDir) if err != nil { return nil, errors.Wrap(err, "failed to make --cache-dir absolute") } - root := file.UNCPath(filepath.Join(cacheDir, "vfs", fremote.Name(), fRoot)) + root := file.UNCPath(filepath.Join(cacheDir, "vfs", fName, fRoot)) fs.Debugf(nil, "vfs cache: root is %q", root) - metaRoot := file.UNCPath(filepath.Join(cacheDir, "vfsMeta", fremote.Name(), fRoot)) + metaRoot := file.UNCPath(filepath.Join(cacheDir, "vfsMeta", fName, fRoot)) fs.Debugf(nil, "vfs cache: metadata root is %q", root) fcache, err := fscache.Get(ctx, root)