From 6c38bddf3e053e0fd56c837d1a4c983ef7fe2ba7 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Tue, 6 Aug 2019 22:21:19 +0100 Subject: [PATCH] walk: fix listing with filters listing whole remote Prior to this fix, a request such as rclone lsf -R --include "/dir/**" remote: Would use ListR which is very inefficient as it lists the whole remote for one directory. This changes it to use recursive walking if the filters imply any directory filtering. So `--include *.jpg` and `--exclude *.jpg` will still use ListR wheras `--include "/dir/**` will not. --- fs/walk/walk.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fs/walk/walk.go b/fs/walk/walk.go index bf61a819a..a424e3a33 100644 --- a/fs/walk/walk.go +++ b/fs/walk/walk.go @@ -51,7 +51,7 @@ type Func func(path string, entries fs.DirEntries, err error) error // // Parent directories are always listed before their children // -// This is implemented by WalkR if Config.UseUseListR is true +// This is implemented by WalkR if Config.UseListR is true // and f supports it and level > 1, or WalkN otherwise. // // If --files-from and --no-traverse is set then a DirTree will be @@ -146,7 +146,7 @@ func ListR(ctx context.Context, f fs.Fs, path string, includeAll bool, maxLevel filter.Active.HaveFilesFrom() || // ...using --files-from maxLevel >= 0 || // ...using bounded recursion len(filter.Active.Opt.ExcludeFile) > 0 || // ...using --exclude-file - filter.Active.BoundedRecursion() { // ...filters imply bounded recursion + filter.Active.UsesDirectoryFilters() { // ...using any directory filters return listRwalk(ctx, f, path, includeAll, maxLevel, listType, fn) } return listR(ctx, f, path, includeAll, listType, fn, doListR, listType.Dirs() && f.Features().BucketBased)