Repository navigation
fix(filters): suppress descendants for dir-only wildcard exclude patterns - #5880
Merged
oferchen merged 1 commit intoJun 17, 2026
Merged
Conversation
…erns Wildcard directory-only patterns (e.g. `foo/*/`, `**/node_modules/`) must not synthesize `pattern/**` descendant matchers. Upstream rsync's `exclude.c:rule_matches()` returns "no match" (line 938-939) when the rule carries `FILTRULE_DIRECTORY` and the candidate is not itself a directory; the file is included by default and the sender's walk handles descent pruning by never entering the matched directory. Pre-baking `foo/*/**` overreaches because the wildcard's per-directory match set is decided at walk time, so a later include rule like `+ foo/s?b/` could no longer keep its directory's children when the synthetic descendant from the exclude steals precedence on a per-entry query. Without this guard, the upstream `exclude` and `exclude-lsh` testsuite cases fail on the `--exclude-from + --delete-during` sub-transfer because single-path filter queries (receiver deletion path, single-path API) report excluded files that upstream rsync includes by default. The sender's traversal-driven `chain.allows()` was already correct via `allows_during_traversal`'s descendant-skip path; this fix aligns the single-path `set.allows()` API with upstream semantics so receiver queries no longer diverge. Three integration tests previously encoded the legacy descendant behaviour and have been updated to mirror upstream's `FILTRULE_DIRECTORY` semantics. The compiled-level `exclude_directory_only_has_descendant_matchers` test is replaced with two focused variants: one verifying that literal directory excludes still produce descendants, and a new guard ensuring wildcard directory-only patterns do not.
oferchen
force-pushed
the
fix/uts-dd-exclude-dir-only-wildcard-descendants
branch
from
June 17, 2026 16:21
a0c625e to
cabb972
Compare
This was referenced Jun 17, 2026
oferchen
added a commit
that referenced
this pull request
Jun 17, 2026
Refactor the descendant-suppression gate in `CompiledRule::new` so the directory-only unanchored wildcard case (`foo/*/`, `**/node_modules/`) is named explicitly rather than hidden inside the broader `has_glob_wildcard && (slash_anchored || directory_only)` condition. The new predicate `is_directory_only_unanchored_wildcard` is greppable, self-documenting, and pinned by dedicated wire-byte parity tests so a future refactor cannot silently re-introduce the synthetic `foo/*/**` descendant that upstream `exclude.c:rule_matches()` never emits (FILTRULE_DIRECTORY, line 938-939). Add wire-byte parity tests on the compiled-rule level that assert the exact direct- and descendant-matcher sets for `foo/*/`, `**/node_modules/`, and the negative literal `cache/` case, plus a new integration test that pins the upstream `exclude` / `exclude-lsh` exclude-from fixture so the sibling include `+ foo/s?b/` continues to keep `foo/sub/file1` instead of being stolen by `- foo/*/`. Regression for UTS-DD-exclude.3 - the test surfaced as "Only in to: new" and "Only in to/foo: down" over-deletion in CI before PR #5880 landed; this change keeps the existing fix and locks the gate down behind an explicit predicate plus wire-byte assertions.
oferchen
added a commit
that referenced
this pull request
Jun 18, 2026
Refactor the descendant-suppression gate in `CompiledRule::new` so the directory-only unanchored wildcard case (`foo/*/`, `**/node_modules/`) is named explicitly rather than hidden inside the broader `has_glob_wildcard && (slash_anchored || directory_only)` condition. The new predicate `is_directory_only_unanchored_wildcard` is greppable, self-documenting, and pinned by dedicated wire-byte parity tests so a future refactor cannot silently re-introduce the synthetic `foo/*/**` descendant that upstream `exclude.c:rule_matches()` never emits (FILTRULE_DIRECTORY, line 938-939). Add wire-byte parity tests on the compiled-rule level that assert the exact direct- and descendant-matcher sets for `foo/*/`, `**/node_modules/`, and the negative literal `cache/` case, plus a new integration test that pins the upstream `exclude` / `exclude-lsh` exclude-from fixture so the sibling include `+ foo/s?b/` continues to keep `foo/sub/file1` instead of being stolen by `- foo/*/`. Regression for UTS-DD-exclude.3 - the test surfaced as "Only in to: new" and "Only in to/foo: down" over-deletion in CI before PR #5880 landed; this change keeps the existing fix and locks the gate down behind an explicit predicate plus wire-byte assertions.
2 of 4 tasks
oferchen
added a commit
that referenced
this pull request
Aug 24, 2026
…erns (#5880) Wildcard directory-only patterns (e.g. `foo/*/`, `**/node_modules/`) must not synthesize `pattern/**` descendant matchers. Upstream rsync's `exclude.c:rule_matches()` returns "no match" (line 938-939) when the rule carries `FILTRULE_DIRECTORY` and the candidate is not itself a directory; the file is included by default and the sender's walk handles descent pruning by never entering the matched directory. Pre-baking `foo/*/**` overreaches because the wildcard's per-directory match set is decided at walk time, so a later include rule like `+ foo/s?b/` could no longer keep its directory's children when the synthetic descendant from the exclude steals precedence on a per-entry query. Without this guard, the upstream `exclude` and `exclude-lsh` testsuite cases fail on the `--exclude-from + --delete-during` sub-transfer because single-path filter queries (receiver deletion path, single-path API) report excluded files that upstream rsync includes by default. The sender's traversal-driven `chain.allows()` was already correct via `allows_during_traversal`'s descendant-skip path; this fix aligns the single-path `set.allows()` API with upstream semantics so receiver queries no longer diverge. Three integration tests previously encoded the legacy descendant behaviour and have been updated to mirror upstream's `FILTRULE_DIRECTORY` semantics. The compiled-level `exclude_directory_only_has_descendant_matchers` test is replaced with two focused variants: one verifying that literal directory excludes still produce descendants, and a new guard ensuring wildcard directory-only patterns do not.
oferchen
added a commit
that referenced
this pull request
Aug 24, 2026
Refactor the descendant-suppression gate in `CompiledRule::new` so the directory-only unanchored wildcard case (`foo/*/`, `**/node_modules/`) is named explicitly rather than hidden inside the broader `has_glob_wildcard && (slash_anchored || directory_only)` condition. The new predicate `is_directory_only_unanchored_wildcard` is greppable, self-documenting, and pinned by dedicated wire-byte parity tests so a future refactor cannot silently re-introduce the synthetic `foo/*/**` descendant that upstream `exclude.c:rule_matches()` never emits (FILTRULE_DIRECTORY, line 938-939). Add wire-byte parity tests on the compiled-rule level that assert the exact direct- and descendant-matcher sets for `foo/*/`, `**/node_modules/`, and the negative literal `cache/` case, plus a new integration test that pins the upstream `exclude` / `exclude-lsh` exclude-from fixture so the sibling include `+ foo/s?b/` continues to keep `foo/sub/file1` instead of being stolen by `- foo/*/`. Regression for UTS-DD-exclude.3 - the test surfaced as "Only in to: new" and "Only in to/foo: down" over-deletion in CI before PR #5880 landed; this change keeps the existing fix and locks the gate down behind an explicit predicate plus wire-byte assertions.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
foo/*/,**/node_modules/) no longer synthesizepattern/**descendant matchers, matching upstream rsync'sexclude.c:rule_matches()line 938-939 which returns "no match" for non-directory entries when the rule carriesFILTRULE_DIRECTORY.exclude/exclude-lshtestsuite failure on the--exclude-from + --delete-duringsub-transfer where single-path filter queries diverged from upstream semantics (UTS-DD-exclude.3, docs(engine): replace forbidden TODO in cleanup.rs #4528).FILTRULE_DIRECTORYsemantics.Root cause
For a pattern like
- foo/*/, the compiled rule used to generate afoo/*/**descendant matcher that fired on any file under any subdirectory offoo/. Upstream rsync has no descendant matching at all; instead, it relies on the sender's walk skipping descent into excluded directories. A directory-only wildcard rule:exclude.c).The synthetic
foo/*/**descendant therefore over-matched whenever a later include rule like+ foo/s?b/was supposed to keep a sub-directory's children. The traversal-drivenchain.allows()was already correct viaFilterSet::allows_during_traversal's descendant-skip path; this fix aligns the single-pathFilterSet::allows()API (used by the receiver deletion path and other non-traversal consumers) with upstream semantics.Changes
crates/filters/src/compiled/mod.rs: extend the descendant-suppression predicate to cover directory-only wildcard patterns; add a focused regression test (dir_only_wildcard_exclude_has_no_descendant_matchers) covering*/,foo/*/,foo/s?b/,bar/[a-z]*/, and**/node_modules/.crates/filters/tests/pattern_matching.rs,crates/filters/tests/glob_patterns.rs,crates/filters/tests/edge_cases.rs: align thenested_directory_pattern,nested_directory_patterns, andcomplex_nested_patternsintegration tests with upstreamFILTRULE_DIRECTORYsemantics. Literal directory excludes (e.g.cache/,node_modules/) still produce descendant matchers; only wildcard directory-only patterns are affected.Files compile, format, and
cargo nextest run -p filters --all-featuresreports 1330 tests pass.Test plan
cargo fmt --all -- --checkcargo nextest run -p filters --all-features(1330 passed)cargo nextest run -p transfer --all-features(no new failures; the pre-existingempty_file_checksum_verification_sha1failure is unrelated to filters)excludeandexclude-lshmove from FAIL to PASS.