Repository navigation
Conversation
globToDirGlobs gave up on a glob whose brace group contained / or **
and returned /**, so every directory matched. A filter such as
--include '/a/{b,c/**}' then scanned the whole remote instead of just
the directories the glob can match.
Expand the brace groups into their alternatives and take the union of
their directory globs. Nested braces and {{ regexp }} sections are
still too hard and keep the previous behaviour - fixes rclone#3250
Verified on master (
|
|
@CAOShurong Thanks for the thorough review and catch! I've pushed a commit (b86bf8f) adding a guard against {{\ and }}\ at the start of \expandBraces, along with unit tests covering unmatched brace globs in \globToDirGlobs. It now gracefully falls back to /**\ without recursion. |
|
Thanks for verifying it against master and running the filter suites. Appreciate the detailed check. |
|
Thanks for working on this, and sorry for the slow reply. There's an earlier PR for the same issue, #9645, and we're going to go with that one. I ran both against the same set of filters, and this PR has a few problems that #9645 doesn't:
So I'm going to close this one. Thanks again for the contribution. Reviews and testing on #9645 would be very welcome. |
What is the purpose of this change?
Fixes #3250 — a filter whose brace group contains
/or**produced a directory rule matching every directory, so rclone walked the whole remote.Using the reproduction from the issue:
Before:
After:
Root cause
globToDirGlobsbails out viatooHardRewhen a brace group contains/or**, returning/**. As noted in the issue, this case was punted on when the code was written.The alternatives inside a brace group are a disjunction, so the directory globs for the whole glob are just the union of the directory globs of each alternative.
expandBracesexpands the groups (/a/{b,c/**}→/a/b,/a/c/**), and the existing splitting logic then runs over each brace-free result, with the results deduplicated in order.Constructs that genuinely can't be expanded — nested braces and
{{ regexp }}sections — still return/**exactly as before. Expansion is combinatorial across groups, so it is capped bymaxBraceExpansionsand falls back to the old behaviour if a glob would exceed it.File filter rules are untouched: only the derived directory rules change, so this narrows which directories are traversed and never changes which files match.
Was the change discussed in an issue or in the forum before?
#3250, which is labelled
good first issue/help wanted. Note the maintainer's comment there offers two options ("That should produce a warning I suppose, or I should fix it") — this PR implements the fix; happy to switch to just warning instead if that is preferred.Checklist
docs/content/changelog.mdif appropriate. (n/a — bugfix, changelog is generated from commit messages)Testing
TestGlobToDirGlobsgains cases for the reported glob and for/and**inside groups, including multiple groups in one glob. The two existing cases that asserted the/**fallback fora/{a,a*b,a**c}/d/and/a/{a,a*b,a/c,d}/d/now assert the expanded directory globs; the nested-brace and{{ regexp }}cases still assert/**../fs/filter/,./fs/list/and./fs/march/all pass, andgofmt/go vetare clean. Also verified end to end against a local tree that the directories which cannot contain a match are no longer descended into.