From e4ece15e6802f606e3a0a88efc36ab4fbb628135 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Wed, 9 Dec 2020 22:36:38 +0000 Subject: [PATCH] vfs: make cache dir absolute before using it to fix path too long errors If --cache-dir is passed in as a relative path, then rclone will not be able to turn it into a UNC path under Windows, which means that file names longer than 260 chars will fail when stored in the cache. This patch makes the --cache-dir path absolute before using it. See: https://forum.rclone.org/t/handling-of-long-paths-on-windows-260-characters/20913 --- 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 5eecf5ed2..f24fa3a75 100644 --- a/vfs/vfscache/cache.go +++ b/vfs/vfscache/cache.go @@ -80,9 +80,14 @@ func New(ctx context.Context, fremote fs.Fs, opt *vfscommon.Options, avFn AddVir } fRoot = strings.Replace(fRoot, ":", "", -1) } - root := file.UNCPath(filepath.Join(config.CacheDir, "vfs", fremote.Name(), fRoot)) + 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)) fs.Debugf(nil, "vfs cache: root is %q", root) - metaRoot := file.UNCPath(filepath.Join(config.CacheDir, "vfsMeta", fremote.Name(), fRoot)) + metaRoot := file.UNCPath(filepath.Join(cacheDir, "vfsMeta", fremote.Name(), fRoot)) fs.Debugf(nil, "vfs cache: metadata root is %q", root) fcache, err := fscache.Get(root)