Skip to content

fix(filters): suppress descendants for dir-only wildcard exclude patterns - #5880

Merged
oferchen merged 1 commit into
masterfrom
fix/uts-dd-exclude-dir-only-wildcard-descendants
Jun 17, 2026
Merged

oferchen merged 1 commit into
masterfrom
fix/uts-dd-exclude-dir-only-wildcard-descendants

Conversation

@oferchen

Copy link
Copy Markdown
Owner

Summary

  • Wildcard directory-only patterns (e.g. foo/*/, **/node_modules/) no longer synthesize pattern/** descendant matchers, matching upstream rsync's exclude.c:rule_matches() line 938-939 which returns "no match" for non-directory entries when the rule carries FILTRULE_DIRECTORY.
  • Resolves the upstream exclude / exclude-lsh testsuite failure on the --exclude-from + --delete-during sub-transfer where single-path filter queries diverged from upstream semantics (UTS-DD-exclude.3, docs(engine): replace forbidden TODO in cleanup.rs #4528).
  • Three integration tests previously encoded the legacy descendant behaviour and have been updated to mirror upstream FILTRULE_DIRECTORY semantics.

Root cause

For a pattern like - foo/*/, the compiled rule used to generate a foo/*/** descendant matcher that fired on any file under any subdirectory of foo/. 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:

  • matches the directory entry directly (per-directory walk-time decision), and
  • returns "no match" for a non-directory entry (line 938-939 in 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-driven chain.allows() was already correct via FilterSet::allows_during_traversal's descendant-skip path; this fix aligns the single-path FilterSet::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 the nested_directory_pattern, nested_directory_patterns, and complex_nested_patterns integration tests with upstream FILTRULE_DIRECTORY semantics. 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-features reports 1330 tests pass.

Test plan

  • cargo fmt --all -- --check
  • cargo nextest run -p filters --all-features (1330 passed)
  • cargo nextest run -p transfer --all-features (no new failures; the pre-existing empty_file_checksum_verification_sha1 failure is unrelated to filters)
  • CI runs the full workspace nextest, Windows / macOS / musl matrices, and the upstream-testsuite interop validation. Confirm exclude and exclude-lsh move from FAIL to PASS.

…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
oferchen force-pushed the fix/uts-dd-exclude-dir-only-wildcard-descendants branch from a0c625e to cabb972 Compare June 17, 2026 16:21
@oferchen
oferchen merged commit b9719aa into master Jun 17, 2026
3 of 5 checks passed
@github-actions github-actions Bot added the bug Something isn't working label Jun 17, 2026
@oferchen
oferchen deleted the fix/uts-dd-exclude-dir-only-wildcard-descendants branch June 17, 2026 18:46
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.
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant