Skip to content

fix(filters): scope ! clear-rules to local merge context - #5905

Merged
oferchen merged 1 commit into
masterfrom
fix/uts-dd-exclude-2-bang-scope-isolation
Jun 18, 2026
Merged

oferchen merged 1 commit into
masterfrom
fix/uts-dd-exclude-2-bang-scope-isolation

Conversation

@oferchen

Copy link
Copy Markdown
Owner

Summary

A `!` (FILTRULE_CLEAR_LIST) rule inside a merged filter file currently flattens its rules into the parent rule stream, so the `!` clears the caller's preceding rules in addition to the merge file's own rules. Upstream rsync scopes the clear to the local section of the rule list - inherited parent-scope rules survive.

This patch resolves `Clear` rules at the merge-expansion boundary so a `!` inside a merge file only retires the rules accumulated within that file's scope. Inline `!` in the top-level rule stream still clears the global list, matching upstream behaviour at CLI scope where there is no inherited section.

Upstream reference

`target/interop/upstream-src/rsync-3.4.4/exclude.c`:

  • `pop_filter_list()` lines 574-590 - frees only the local section of the rule list, leaving inherited rules in place.
  • `parse_filter_str()` lines 1393-1402 - `FILTRULE_CLEAR_LIST` calls `pop_filter_list(listp)` then sets `listp->head = NULL`, removing only the local-scope rules between `head` and `tail`.

Implementation

  • `crates/filters/src/merge/read.rs` - add `scope_local_clear` and apply it inside `read_rules_recursive_impl` when expanding a nested `. FILE` directive.
  • `crates/filters/src/set.rs` - apply `scope_local_clear` to the rules returned by each Merge expansion in `expand_merge_rules`.
  • `crates/filters/src/merge/mod.rs` - re-export `scope_local_clear` to the `set.rs` call site.

Test plan

  • `cargo fmt --all` clean
  • Unit test: `!` inline in CLI args clears all prior rules (top-level scope).
  • Unit test: `!` at top of a single merge file does not clear parent CLI rules.
  • Unit test: `!` in a nested merge file clears only the nested scope (outer merge rules and parent CLI rules survive).
  • Unit test: UTS-DD-exclude.2 fixture - parent CLI `- /a`, merge file `! + /b` produces a final chain with both `- /a` and `+ /b` active.
  • Unit test: side-restricted clear does not regress baseline behaviour.

Resolves UTS-DD-exclude.2 (#4527).

@github-actions github-actions Bot added the bug Something isn't working label Jun 17, 2026
@oferchen
oferchen force-pushed the fix/uts-dd-exclude-2-bang-scope-isolation branch 2 times, most recently from 68e7d37 to 8e68613 Compare June 18, 2026 01:24
A `!` (FILTRULE_CLEAR_LIST) rule inside a merged filter file now clears
only rules accumulated from that file, mirroring upstream
exclude.c:pop_filter_list() (rsync-3.4.4 exclude.c:574-590), which
truncates the local section of the rule list while leaving inherited
parent-scope rules in place. Previously, expanding a merge file via
FilterSet::from_rules_with_merge_expansion flattened the merge file's
rules into the parent stream, causing a `!` from the file to also drop
the caller's preceding rules.

Add a `scope_local_clear` helper at the merge module boundary and apply
it at both expansion sites (read_rules_recursive_impl when expanding a
nested `. FILE` and expand_merge_rules at the outer call). Inline `!` in
the top-level rule stream still clears the global list, matching
upstream's behaviour at CLI scope where there is no inherited section.

Tests cover CLI-inline clear, single-file merge clear, two-level nested
merge clear, and the parent-survives fixture from UTS-DD-exclude.2.
@oferchen
oferchen force-pushed the fix/uts-dd-exclude-2-bang-scope-isolation branch from b68be56 to e8ae145 Compare June 18, 2026 04:13
@oferchen
oferchen merged commit bb9580c into master Jun 18, 2026
1 of 3 checks passed
@oferchen
oferchen deleted the fix/uts-dd-exclude-2-bang-scope-isolation branch June 18, 2026 04:16
oferchen added a commit that referenced this pull request Aug 24, 2026
A `!` (FILTRULE_CLEAR_LIST) rule inside a merged filter file now clears
only rules accumulated from that file, mirroring upstream
exclude.c:pop_filter_list() (rsync-3.4.4 exclude.c:574-590), which
truncates the local section of the rule list while leaving inherited
parent-scope rules in place. Previously, expanding a merge file via
FilterSet::from_rules_with_merge_expansion flattened the merge file's
rules into the parent stream, causing a `!` from the file to also drop
the caller's preceding rules.

Add a `scope_local_clear` helper at the merge module boundary and apply
it at both expansion sites (read_rules_recursive_impl when expanding a
nested `. FILE` and expand_merge_rules at the outer call). Inline `!` in
the top-level rule stream still clears the global list, matching
upstream's behaviour at CLI scope where there is no inherited section.

Tests cover CLI-inline clear, single-file merge clear, two-level nested
merge clear, and the parent-survives fixture from UTS-DD-exclude.2.
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