You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Brace filter alternatives containing path separators or recursive wildcards currently fall back to a catch-all directory rule, so a filter such as /a/{b,c/**} traverses unrelated directories.
This change expands only brace groups that can affect directory depth (/ or **) before deriving directory globs, deduplicates the resulting rules, and leaves ordinary filename alternatives unchanged. Nested braces, raw regex sections, and opaque escaped or character-class path patterns retain the existing conservative all-directory fallback.
Focused tests cover the generated directory rules and the end-to-end include/exclude behavior.
gofmt -d fs/filter/glob.go fs/filter/glob_test.go fs/filter/filter_test.go produced no diff.
go test ./fs/filter -count=1 passed.
go build passed on Windows.
A real rclone.exe lsf -R --files-only --include '/a/{b,c/**}' reproduction listed only a/b and a/c/deep/keep.txt; the unrelated directory was pruned.
Broad RCLONE_CONFIG=/notfound go test ./... -count=1 verification was split after a connector transport interruption. All observed packages passed except the unrelated Windows baseline failure in backend/sftp, where TestSSHExternalWaitMultipleCalls invokes an external echo executable that is absent from C:\Program Files\Eclipse Adoptium\jdk-21.0.11.10-hotspot\bin;C:\Program Files\Eclipse Adoptium\jdk-25.0.2.10-hotspot\bin;C:\Program Files\Common Files\Oracle\Java\javapath;C:\Windows\SYSTEM32;C:\Windows;C:\Windows\SYSTEM32\WBEM;C:\Windows\SYSTEM32\WINDOWSPOWERSHELL\V1.0\;C:\Windows\SYSTEM32\OPENSSH\;C:\Program Files\nodejs\;C:\Program Files\CMake\bin;C:\Program Files\Go\bin;C:\ProgramData\chocolatey\bin;C:\ProgramData\chocolatey\lib\mpvio.install\tools;C:\Program Files\Git\cmd;C:\Program Files\RedHat\Podman\;%LOCALAPPDATA%\Android\Sdk\platform-tools;%LOCALAPPDATA%\Android\Sdk\cmdline-tools\latest\bin;C:\Program Files\GitHub CLI\;C:\Users\raidsh\.local\bin;C:\Users\raidsh\AppData\Local\Microsoft\WindowsApps;C:\Users\raidsh\AppData\Local\Programs\Microsoft VS Code\bin;C:\Users\raidsh\.lmstudio\bin;C:\Users\raidsh\AppData\Local\Microsoft\WinGet\Packages\charmbracelet.crush_Microsoft.Winget.Source_8wekyb3d8bbwe\crush_0.1.11_Windows_x86_64;C:\Users\raidsh\AppData\Roaming\npm;C:\Users\raidsh\AppData\Local\Microsoft\WinGet\Links;C:\Users\raidsh\AppData\Local\Programs\VSCodium\bin;C:\Users\raidsh\AppData\Local\Microsoft\WinGet\Packages\yt-dlp.FFmpeg_Microsoft.Winget.Source_8wekyb3d8bbwe\ffmpeg-N-120424-g03b9180fe3-win64-gpl/bin;C:\Users\raidsh\go\bin;C:\Users\raidsh\AppData\Local\Android\Sdk\platform-tools;C:\Users\raidsh\AppData\Local\Microsoft\WinGet\Packages\Genymobile.scrcpy_Microsoft.Winget.Source_8wekyb3d8bbwe\scrcpy-win64-v4.0. The detached non-backend remainder completed, but its aggregate exit code could not be recovered after the transport session expired.
git diff --check passed.
Checklist
This change is trivial OR it has been discussed and agreed in the linked issue.
I have read the contribution guidelines.
(If I used AI tools to help write this code) I have read and understood the AI-assisted contributions guidance, and I have tested and take ownership of this change myself.
I have added tests for all changes in this PR if appropriate.
I have added documentation for the changes if appropriate (no user-facing documentation change is required).
Thanks for this, and sorry for the slow review. I compared it with #9778, which tried to fix the same issue, and yours is the one we'll go with. It handles [...] classes and escapes inside {} groups correctly, and falling back to all directories when a class or escape could hide a / or ** is the right call.
One thing needs fixing before merge. expandPathBraceGlobs has no limit on how many globs it produces, and every path group doubles the count. Repeating {a,b/} 20 times in one glob gives 1,048,576 directory rules and takes about 3.4s, and a slightly longer --include will run out of memory. Could you cap the expansion at something small (say 64 globs) and above that fall back to /** with the same Infof message? A test for the fallback would be good too.
Smaller things:
braceContainsOpaquePathPattern, braceContainsPathPattern, splitBraceOptions, skipGlobClass and globToDirGlobsSingle need a one-line doc comment each.
In expandPathBraceGlobs the inner for loop can be expanded = append(expanded, suffixExpansions...).
The commit author name is "p1". Could you set your git user.name and amend the commit so the changelog credits you properly?
Thanks for the review! All addressed. I amended the single commit (now authored as Giridhar):
expandPathBraceGlobs is capped at maxPathBraceGlobs = 64. It bails out as soon as the running count goes over the cap, so it stops early instead of building the full set. Above the cap globToDirGlobs falls back to /** with the same Infof message.
TestGlobToDirGlobsExpansionLimit checks that 6 path groups still expand to exactly 64 globs, and that 7, 20 and 100 groups fall back to /**. The 100-group case finishes instantly.
Added doc comments to the five helpers. The expandPathBraceGlobs comment was sitting above the wrong function, so I moved it back.
The inner loop is now append(expanded, suffixExpansions...).
go test ./fs/filter/ and go vet pass.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this change do?
Brace filter alternatives containing path separators or recursive wildcards currently fall back to a catch-all directory rule, so a filter such as
/a/{b,c/**}traverses unrelated directories.This change expands only brace groups that can affect directory depth (
/or**) before deriving directory globs, deduplicates the resulting rules, and leaves ordinary filename alternatives unchanged. Nested braces, raw regex sections, and opaque escaped or character-class path patterns retain the existing conservative all-directory fallback.Focused tests cover the generated directory rules and the end-to-end include/exclude behavior.
Linked issue
Fixes #3250
For new or changed backends
Not applicable.
Testing
gofmt -d fs/filter/glob.go fs/filter/glob_test.go fs/filter/filter_test.goproduced no diff.go test ./fs/filter -count=1passed.go buildpassed on Windows.rclone.exe lsf -R --files-only --include '/a/{b,c/**}'reproduction listed onlya/banda/c/deep/keep.txt; the unrelated directory was pruned.RCLONE_CONFIG=/notfound go test ./... -count=1verification was split after a connector transport interruption. All observed packages passed except the unrelated Windows baseline failure inbackend/sftp, whereTestSSHExternalWaitMultipleCallsinvokes an externalechoexecutable that is absent fromC:\Program Files\Eclipse Adoptium\jdk-21.0.11.10-hotspot\bin;C:\Program Files\Eclipse Adoptium\jdk-25.0.2.10-hotspot\bin;C:\Program Files\Common Files\Oracle\Java\javapath;C:\Windows\SYSTEM32;C:\Windows;C:\Windows\SYSTEM32\WBEM;C:\Windows\SYSTEM32\WINDOWSPOWERSHELL\V1.0\;C:\Windows\SYSTEM32\OPENSSH\;C:\Program Files\nodejs\;C:\Program Files\CMake\bin;C:\Program Files\Go\bin;C:\ProgramData\chocolatey\bin;C:\ProgramData\chocolatey\lib\mpvio.install\tools;C:\Program Files\Git\cmd;C:\Program Files\RedHat\Podman\;%LOCALAPPDATA%\Android\Sdk\platform-tools;%LOCALAPPDATA%\Android\Sdk\cmdline-tools\latest\bin;C:\Program Files\GitHub CLI\;C:\Users\raidsh\.local\bin;C:\Users\raidsh\AppData\Local\Microsoft\WindowsApps;C:\Users\raidsh\AppData\Local\Programs\Microsoft VS Code\bin;C:\Users\raidsh\.lmstudio\bin;C:\Users\raidsh\AppData\Local\Microsoft\WinGet\Packages\charmbracelet.crush_Microsoft.Winget.Source_8wekyb3d8bbwe\crush_0.1.11_Windows_x86_64;C:\Users\raidsh\AppData\Roaming\npm;C:\Users\raidsh\AppData\Local\Microsoft\WinGet\Links;C:\Users\raidsh\AppData\Local\Programs\VSCodium\bin;C:\Users\raidsh\AppData\Local\Microsoft\WinGet\Packages\yt-dlp.FFmpeg_Microsoft.Winget.Source_8wekyb3d8bbwe\ffmpeg-N-120424-g03b9180fe3-win64-gpl/bin;C:\Users\raidsh\go\bin;C:\Users\raidsh\AppData\Local\Android\Sdk\platform-tools;C:\Users\raidsh\AppData\Local\Microsoft\WinGet\Packages\Genymobile.scrcpy_Microsoft.Winget.Source_8wekyb3d8bbwe\scrcpy-win64-v4.0. The detached non-backend remainder completed, but its aggregate exit code could not be recovered after the transport session expired.git diff --checkpassed.Checklist