Skip to content

fix(engine): register nested dir-merge as per-directory rule, not eager merge - #5902

Merged
oferchen merged 1 commit into
masterfrom
fix/uts-dd-exclude-1-dir-merge-nested
Jun 17, 2026
Merged

oferchen merged 1 commit into
masterfrom
fix/uts-dd-exclude-1-dir-merge-nested

Conversation

@oferchen

Copy link
Copy Markdown
Owner

Summary

UTS-DD-exclude.1 (#4526). A per-directory merge file containing dir-merge
or : short-form was treated like a plain merge: oc-rsync eagerly loaded
the referenced filter file from the enclosing file's parent directory. The
upstream behavior (exclude.c:1419-1428) is to register the referenced
filename as a NEW per-directory rule that gets looked up in each
subsequently entered subdirectory.

Concrete divergence reproduced from the upstream testsuite exclude-lsh
fixture: bar/.filt contains dir-merge .filt2 and the per-subdir rules
live at bar/down/to/.filt2, bar/down/to/foo/.filt2,
bar/down/to/bar/.filt2. The eager load looked for bar/.filt2, which
does not exist; the per-dir rule was never enforced, and oc-rsync
over-deleted files such as bar/down/to/bar/baz/file5.deep that the
per-dir - *.deep rule should have protected.

  • Split parser AST: merge/. keep Merge (eager); dir-merge/per-dir/:
    emit a new DirMerge variant carrying the bare filename.
  • Load: DirMergeEntries now collects nested per-dir registrations in
    nested_dir_merges instead of recursing eagerly.
  • Runtime: CopyContext maintains a per-directory stack of
    DynamicDirMergeFrames scoped by DirectoryFilterGuard. On
    enter_directory_for_path, inherited active rules are resolved against
    the current directory, segments and markers are collected, and any
    freshly-registered dir-merge rules become active for subdirectories.
  • Evaluation: dynamic top-of-stack segments fire before the static program,
    giving child-directory rules first-match priority over inherited parent
    rules per exclude.c:check_filter().

Test plan

  • Unit tests in crates/engine/src/local_copy/dir_merge/parse/ confirm
    parse_dir_merge_directive and the : short form both emit
    ParsedFilterDirective::DirMerge.
  • Integration test
    nested_dir_merge_registers_per_directory_rule in
    crates/engine/src/local_copy/tests/filters_runtime.rs builds a
    source tree with bar/.filt containing dir-merge .filt2 and
    bar/baz/.filt2 containing - *.deep, then asserts
    bar/baz/file5.deep is excluded from the transfer while
    bar/baz/keep.txt is copied.
  • cargo fmt --all clean.
  • CI: fmt+clippy, nextest (stable), Windows, macOS, Linux musl.

Refs upstream-src/rsync-3.4.4/exclude.c:1419-1428,
testsuite/exclude-lsh.test.

…er merge

When a per-directory merge file contained a `dir-merge` or `:` short-form
directive, oc-rsync eagerly loaded the referenced file from the enclosing
file's parent directory instead of registering a new per-directory merge
rule for subsequent subdirectory traversal. This diverged from upstream
exclude.c:1419-1428 and caused over-deletion in fixtures like the
upstream testsuite's exclude-lsh, where `bar/.filt` declares
`dir-merge .filt2` but the actual `.filt2` files live in subdirectories
such as `bar/down/to/`. The eager load failed silently and the per-dir
rule was never enforced inside those subdirectories.

Split the parsed AST so `merge`/`.` keeps the eager-load semantics in a
`Merge` variant while `dir-merge`/`per-dir`/`:` produces a new `DirMerge`
variant that carries only the bare filename. Loading a per-directory
merge file now accumulates these nested directives into
`DirMergeEntries.nested_dir_merges`. The CopyContext maintains a
per-directory stack of `DynamicDirMergeFrame`s, inherited via
`DirectoryFilterGuard`, that record the active per-directory rules and
the segments / markers loaded for each visited subdirectory. Filter
evaluation applies the dynamic top-of-stack segments before the static
program so child-directory rules override inherited parent rules with
first-match-wins semantics, matching upstream check_filter().

Adds a parse-side unit test confirming both forms emit `DirMerge` and an
integration test mirroring the exclude-lsh fixture: a source tree with
`bar/.filt` declaring `dir-merge .filt2` plus `bar/baz/.filt2` with
`- *.deep` correctly excludes `bar/baz/file5.deep` from the transfer.
@oferchen
oferchen force-pushed the fix/uts-dd-exclude-1-dir-merge-nested branch from 8873ac1 to 19969a3 Compare June 17, 2026 19:34
@oferchen
oferchen merged commit fdecd46 into master Jun 17, 2026
@github-actions github-actions Bot added the bug Something isn't working label Jun 17, 2026
oferchen added a commit that referenced this pull request Jun 17, 2026
Two unrelated breaks landed on master after #5899 and #5902 and now block every PR:

1. `core::client::remote::ssh_transfer` still called `flags::build_wire_format_rules` with one argument after #5899 added a `delete_excluded: bool` parameter (`embedded_ssh_transfer.rs` was updated; the two call sites in `ssh_transfer.rs` were missed). Pass `config.delete_excluded()` to match the wire-format contract.

2. `engine::local_copy::context_impl::transfer` used `Vec::extend(other.drain(..))` instead of `Vec::append(&mut other)` after #5902, which trips `clippy::extend-with-drain` under `-D warnings`. Switch to `append`.

These are minimal mechanical fixes; no behaviour change.
oferchen added a commit that referenced this pull request Jun 17, 2026
* fix(engine,core): unblock master CI after #5899 + #5902 regressions

PR #5902 introduced a `clippy::extend-with-drain` lint violation in the
nested dir-merge wiring at transfer.rs:187. PR #5899 widened
`build_wire_format_rules` to take a `delete_excluded: bool` parameter
but missed the SSH push/pull call sites in ssh_transfer.rs (E0061).

Both fail the master fmt+clippy and Build cells, blocking every open PR.

- engine/.../transfer.rs: replace `extend(.drain(..))` with `append(&mut)`.
- core/.../ssh_transfer.rs: pass `config.delete_excluded()` at both call sites.

* fix(core): wire delete_excluded through async_ssh_transport build_*_server_config

* fix(tests): clippy assertions-on-constants + manual-contains lints

- transfer test: wrap compile-time invariants in `const _: () = assert!(...)`
- cli verbose test: use `lines.contains(&"only.txt")` over iter().any()

* fix(tests): convert OsString args to String for find_flag_string helper
@oferchen
oferchen deleted the fix/uts-dd-exclude-1-dir-merge-nested branch June 18, 2026 03:32
oferchen added a commit that referenced this pull request Aug 24, 2026
…er merge (#5902)

When a per-directory merge file contained a `dir-merge` or `:` short-form
directive, oc-rsync eagerly loaded the referenced file from the enclosing
file's parent directory instead of registering a new per-directory merge
rule for subsequent subdirectory traversal. This diverged from upstream
exclude.c:1419-1428 and caused over-deletion in fixtures like the
upstream testsuite's exclude-lsh, where `bar/.filt` declares
`dir-merge .filt2` but the actual `.filt2` files live in subdirectories
such as `bar/down/to/`. The eager load failed silently and the per-dir
rule was never enforced inside those subdirectories.

Split the parsed AST so `merge`/`.` keeps the eager-load semantics in a
`Merge` variant while `dir-merge`/`per-dir`/`:` produces a new `DirMerge`
variant that carries only the bare filename. Loading a per-directory
merge file now accumulates these nested directives into
`DirMergeEntries.nested_dir_merges`. The CopyContext maintains a
per-directory stack of `DynamicDirMergeFrame`s, inherited via
`DirectoryFilterGuard`, that record the active per-directory rules and
the segments / markers loaded for each visited subdirectory. Filter
evaluation applies the dynamic top-of-stack segments before the static
program so child-directory rules override inherited parent rules with
first-match-wins semantics, matching upstream check_filter().

Adds a parse-side unit test confirming both forms emit `DirMerge` and an
integration test mirroring the exclude-lsh fixture: a source tree with
`bar/.filt` declaring `dir-merge .filt2` plus `bar/baz/.filt2` with
`- *.deep` correctly excludes `bar/baz/file5.deep` from the transfer.
oferchen added a commit that referenced this pull request Aug 24, 2026
* fix(engine,core): unblock master CI after #5899 + #5902 regressions

PR #5902 introduced a `clippy::extend-with-drain` lint violation in the
nested dir-merge wiring at transfer.rs:187. PR #5899 widened
`build_wire_format_rules` to take a `delete_excluded: bool` parameter
but missed the SSH push/pull call sites in ssh_transfer.rs (E0061).

Both fail the master fmt+clippy and Build cells, blocking every open PR.

- engine/.../transfer.rs: replace `extend(.drain(..))` with `append(&mut)`.
- core/.../ssh_transfer.rs: pass `config.delete_excluded()` at both call sites.

* fix(core): wire delete_excluded through async_ssh_transport build_*_server_config

* fix(tests): clippy assertions-on-constants + manual-contains lints

- transfer test: wrap compile-time invariants in `const _: () = assert!(...)`
- cli verbose test: use `lines.contains(&"only.txt")` over iter().any()

* fix(tests): convert OsString args to String for find_flag_string helper
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