Skip to content

fix(cli): four upstream parity fixes in option and filter handling - #7313

Merged
oferchen merged 5 commits into
masterfrom
fix/cli-parity-four
Aug 14, 2026
Merged

oferchen merged 5 commits into
masterfrom
fix/cli-parity-four

Conversation

@oferchen

Copy link
Copy Markdown
Owner

Four independent CLI-layer parity fixes, split out of a larger daemon branch because none of them touch daemon code. Each commit carries its own upstream citation, measurement table and non-vacuity note; this body is the index.

1. fix(client): send upstream's daemon-auth username, not rsync/USERNAME

Upstream's client picks the daemon-auth user as USER -> LOGNAME -> "nobody". oc used USER -> USERNAME -> "rsync", so a login where only LOGNAME is set authenticated under the wrong name, and the fallback name differed from upstream's on every platform.

2. fix(cli): let --block-size reach the shared size parser

--block-size was gated to bare integers at the argv layer, so --block-size=1K was rejected before the shared suffix parser it is supposed to use ever ran. Upstream accepts the full size grammar here. The gate was the only thing making the shared parser unreachable from this option.

3. fix(cli): resolve an empty size value to 0, per option

An empty size value (--max-size=) is exactly =0 on upstream, not "fall back to the default" - measured on 3.5.0, --max-size= excludes every non-empty file on both implementations. Applied per option at the four sites that share upstream's semantics, and deliberately not in the shared parse_size_spec: --max-alloc has a 1 MiB minimum and rejects 0, so folding the rule into the shared parser would have re-opened the guard added in #7285.

4. fix(cli): a filter file that will not open is fatal with RERR_FILEIO

Upstream reports every failed filter-file open from one site with one message and one exit code (exclude.c:1712-1719), exiting 11. oc exited 1 with its own wording. Two look-alikes are deliberately excluded and pinned as such:

  • per-directory merges (dir-merge, -F) pass no XFLG_FATAL_ERRORS (exclude.c:912) and must stay a silent success - scoping the fix by the condition rather than the call site would have broken every -F transfer;
  • --files-from is reported from main.c:1886 and exits 1 on both binaries.

Verification

Measured on this branch rebased onto origin/master (e997c2c66):

  • cargo fmt --all -- --check - clean
  • cargo clippy --locked --workspace --all-targets --all-features --no-deps -- -D warnings - no issues
  • cargo nextest run -p cli --all-features - 3801 passed, 3 skipped (pristine origin/master control: 3800 passed, same 3 skipped)
  • the four new integration binaries (block_size_suffix_grammar, empty_size_value_parity, filter_file_open_failure_parity, daemon_auth_username_wire) - 14 passed

Every new test table asserts against oc and against the real upstream 3.5.0 binary in the same cell, so a shared misunderstanding of upstream cannot pass. Non-vacuity was measured per fix by reverting the production change and confirming the new rows redden.

@github-actions github-actions Bot added the bug Something isn't working label Aug 14, 2026
@oferchen
oferchen enabled auto-merge (squash) August 14, 2026 04:02
The username in the `@RSYNCD` auth response is what the daemon matches
against `auth users`, so every part of resolving it is wire-affecting.
Upstream resolves it in two stages:

    /* clientserver.c:289-292, start_inband_exchange() */
    if (!user)
        user = getenv("USER");
    if (!user)
        user = getenv("LOGNAME");
    /* authenticate.c:451-452 + :473, auth_client() */
    if (!user || !*user)
        user = "nobody";
    io_printf(fd, "%s %s\n", user, pass2);

oc consulted `USERNAME` - a Windows convention upstream never reads -
instead of `LOGNAME`, and fell back to `rsync` instead of `nobody`.

Measured by capturing the auth line from a stub daemon, real rsync 3.5.0
against oc:

  environment                  upstream    oc before   oc after
  USER=alice                   alice       alice       alice
  LOGNAME=bob (no USER)        bob         rsync       bob
  USER=alice LOGNAME=bob       alice       alice       alice
  USER='' LOGNAME=bob          nobody      ''          nobody
  neither set                  nobody      rsync       nobody
  USERNAME=win                 nobody      win         nobody

Four of six rows diverged. The practical failure is the second: on a host
that exports only `LOGNAME` - a plain `su`, cron, or a login shell that
does not export `USER` - a correctly configured `auth users = alice`
rejected the client, which authenticated as `rsync`.

The fourth row is the subtle one and is why the chain is not
"first non-empty wins": `getenv` returns a non-NULL empty string for a
set-but-empty `USER`, so `if (!user)` is false and `LOGNAME` is never
consulted; only `auth_client`'s `!*user` rescues it, as `nobody`.
`env::var` mirrors that exactly - `Ok("")` when set-empty, `Err` only
when absent.

The decision is split from the environment read so the six rows are unit
tested without mutating process-global state, and the integration test
sets the environment on the CHILD only, which keeps it correct under
parallel nextest.

⚠ Behaviour change on Windows: `USERNAME` was oc's only daemon-auth
username source there, and upstream has no such fallback, so a Windows
client with no `USER`/`LOGNAME` now authenticates as `nobody`. Mirroring
upstream is the rule; flagging the consequence rather than silently
keeping an oc-only extension that changes a wire byte.

(cherry picked from commit 6b1bccd6597d10680429f23d3bc10cfe9bcc310f)
`--block-size` is the only one of upstream's four `parse_size_arg`
options that could not take a suffix. A bare-`u64` gate in the argv
layer rejected the value before the shared, suffix-aware parser ran:

    let s = value.to_string_lossy();
    if s.parse::<u64>().is_err() { return Err(...) }

`--min-size`, `--max-size` and `--bwlimit` have no such gate three lines
away, which is why they accepted `1K` and `--block-size` did not. Upstream
parses all four with one helper (options.c:1802, :1809, :1815, :1821), so
`size.rs`'s already-tested suffix support was simply unreachable in
production for this one option.

Deleting the gate fixes 20 of the 21 measured spellings; nothing else was
needed, because the shared parser already implements the whole grammar.
Measured against the real rsync 3.5.0 binary:

  accepted   700  1K  1k  1KB  1kb  1KiB  1kib  128K  1.5K  0
             1K+1  1K-1  1B  8b  131072
  rejected   1M  1G  1T  1P  131073 (all "too large", max 128.00K)
             1Z  1KX ("invalid")

oc now matches every row. Rejection of `-1` and `abc` is preserved - it
just happens one layer down, with the value named.

The value test is the one that matters: acceptance alone would pass on a
parser that ignored the scale, so the new test pins `1K` == `1024` and
`1KB` == `1000` through the delta itemization, with a control assertion
that 1024 and 1000 actually differ on the fixture. That control fired
during development - the first fixture reported 0 matched / 0 literal for
every block size because the quick-check skipped the file, so the two
equalities were comparing nothing. `--ignore-times` fixes the fixture.

Three tests pinned the old LAYER rather than the behaviour and are
rewritten: two asserted a clap `ValueValidation` error for `-B abc` /
`-B -1` and now assert the end-to-end rejection; the third used
`--block-size=abc` only as a vehicle for a clap error while guarding
against a doubled `syntax or usage error: error:` prefix, and now uses
`--io-uring-depth=abc`, which still produces one.

Residual, deliberately not folded in: upstream accepts an EMPTY value
(`--block-size=`, which resolves to 0 and falls back to the default) for
all four of these options, and oc rejects it for all four. That is a
shared-parser divergence of a different shape and scope, and it is filed
separately rather than widened into this change.

(cherry picked from commit f84b9fd8906bfc8672339fd4b63337cd03871dc8)
Upstream accepts an empty size value: the digit scan in `parse_size_arg`
leaves `arg` on the terminator, so the suffix switch takes `def_suf` and
`strtod("")` yields 0 (options.c:1172-1175, :1215). oc rejected it on
every option that takes a size.

⚠ The filed description said "resolves to 0 and falls back to the
default". That is true only for `--block-size`. Measured behaviour, not
exit codes, on rsync 3.5.0 with a 6-byte source file:

  option         empty            =0               same?
  --block-size   transferred      transferred      yes -> default blength
  --min-size     transferred      transferred      yes -> no lower bound
  --max-size     EXCLUDED         EXCLUDED         yes -> a real 0 bound
  --bwlimit      transferred      transferred      yes -> unlimited
  --max-alloc    rejected         rejected         yes -> min is 1 MiB

So `--max-size=` does not mean "no limit" and does not mean "the
default": it is a bound of 0 that excludes every non-empty file. The one
rule that holds across all five is `empty == 0`, and what 0 MEANS is
decided by each option's own `min_value` / `unlimited_0` at its upstream
call site.

That is why the rule is applied per option rather than inside
`parse_size_spec`. `--max-alloc` has a 1 MiB minimum and rejects 0 on
both implementations; folding empty-to-zero into the shared string parser
would have silently started accepting `--max-alloc=`, undoing the guard
that landed for the zero case. `parse_size_spec` keeps rejecting empty,
and the four options whose upstream call permits 0 normalise first.

Tests assert the RESOLVED VALUE, not acceptance: each option's empty
spelling must be indistinguishable from `=0`, `--max-size=` must exclude
the file (the discriminator - a build that accepted the string and then
ignored it would pass every other assertion), a non-empty value must
still parse and apply, and `--max-alloc=` must stay rejected. A
cross-implementation cell asserts the same table against the real 3.5.0
binary. Non-vacuity measured: reverting the four call sites reddens the
two oc cells and leaves the oracle, the control and the max-alloc guard
green.

One unit test pinned the old rejection and is corrected to assert the
`=0` equivalence.

(cherry picked from commit 4835d9733f58c28924c6ba04442b5228f795b8ab)
Upstream reports every failed filter-file open from one site with one
message and one exit code (exclude.c:1712-1719):

    rsyserr(FERROR, errno, "failed to open %sclude file %s",
            template->rflags & FILTRULE_INCLUDE ? "in" : "ex", fname);
    exit_cleanup(RERR_FILEIO);

oc exited 1 with `failed to read filter file '<path>'` and Rust's
`(os error 2)` errno rendering. Measured against 3.5.0:

    --exclude-from=<missing>     upstream 11   oc 1
    --include-from=<missing>     upstream 11   oc 1
    --filter='merge <missing>'   upstream 11   oc 1
    --filter='. <missing>'       upstream 11   oc 1

The include/exclude word is DERIVED, not per option: `--filter='.+ F'`
and `--filter='merge,+ F'` report "include file" because the `+` modifier
sets FILTRULE_INCLUDE. Both spellings are in the test table, since they
are the only evidence the word is not hardcoded.

Applied at the two open sites (`load_filter_file_patterns` for
--exclude-from/--include-from, `read_merge_file` for merge rules) through
one shared helper, because upstream has exactly one such site.

Two boundaries the tests pin as deliberately NOT part of the rule:

- per-directory merges (`dir-merge`, `-F`) pass no XFLG_FATAL_ERRORS
  (exclude.c:912), so a missing per-directory filter file must stay a
  silent success. Keying the fix off "filter file missing" instead of off
  the call site would have broken every -F transfer.
- `--files-from` looks like the same shape and is NOT: upstream reports
  it from main.c:1886 and exits 1, measured on both binaries. Folding the
  two onto one helper because the messages resemble each other would have
  changed an exit code nobody asked to change.

`read_merge_file` now opens and reads in two steps so only a genuine open
failure takes upstream's wording; a mid-file read error or non-UTF-8
contents keeps its own report. The post-open read error in
`load_filter_file_patterns` is likewise left alone - upstream's getc loop
cannot distinguish a read error from EOF, so there is no upstream rule to
mirror there, and the comment says so rather than inventing a citation.

Tests: an 8-row table (6 fatal spellings, 2 that must stay non-fatal)
asserted against oc AND against the real 3.5.0 binary, plus a control
that a readable filter file still parses and applies, plus a guard that
--files-from stays exit 1. Assertions are on the exit CODE and the
WORDING and the named path together - exiting 11 with an unrelated
message would be a different bug and must not pass. Non-vacuity measured:
reverting the helper to exit 1 with the old wording reddens exactly the
oc cell and leaves the oracle, the control and the guard green.

Two tests encoded the old behaviour (`exit 1` + `failed to read filter
file`) and are corrected.

(cherry picked from commit 3f26e4500bfd2216851eaa00d80bba1fc706afe8)
@oferchen
oferchen merged commit d864c9f into master Aug 14, 2026
75 of 77 checks passed
@oferchen
oferchen deleted the fix/cli-parity-four branch August 14, 2026 08:41
oferchen added a commit that referenced this pull request Aug 24, 2026
…7313)

* fix(client): send upstream's daemon-auth username, not rsync/USERNAME

The username in the `@RSYNCD` auth response is what the daemon matches
against `auth users`, so every part of resolving it is wire-affecting.
Upstream resolves it in two stages:

    /* clientserver.c:289-292, start_inband_exchange() */
    if (!user)
        user = getenv("USER");
    if (!user)
        user = getenv("LOGNAME");
    /* authenticate.c:451-452 + :473, auth_client() */
    if (!user || !*user)
        user = "nobody";
    io_printf(fd, "%s %s\n", user, pass2);

oc consulted `USERNAME` - a Windows convention upstream never reads -
instead of `LOGNAME`, and fell back to `rsync` instead of `nobody`.

Measured by capturing the auth line from a stub daemon, real rsync 3.5.0
against oc:

  environment                  upstream    oc before   oc after
  USER=alice                   alice       alice       alice
  LOGNAME=bob (no USER)        bob         rsync       bob
  USER=alice LOGNAME=bob       alice       alice       alice
  USER='' LOGNAME=bob          nobody      ''          nobody
  neither set                  nobody      rsync       nobody
  USERNAME=win                 nobody      win         nobody

Four of six rows diverged. The practical failure is the second: on a host
that exports only `LOGNAME` - a plain `su`, cron, or a login shell that
does not export `USER` - a correctly configured `auth users = alice`
rejected the client, which authenticated as `rsync`.

The fourth row is the subtle one and is why the chain is not
"first non-empty wins": `getenv` returns a non-NULL empty string for a
set-but-empty `USER`, so `if (!user)` is false and `LOGNAME` is never
consulted; only `auth_client`'s `!*user` rescues it, as `nobody`.
`env::var` mirrors that exactly - `Ok("")` when set-empty, `Err` only
when absent.

The decision is split from the environment read so the six rows are unit
tested without mutating process-global state, and the integration test
sets the environment on the CHILD only, which keeps it correct under
parallel nextest.

⚠ Behaviour change on Windows: `USERNAME` was oc's only daemon-auth
username source there, and upstream has no such fallback, so a Windows
client with no `USER`/`LOGNAME` now authenticates as `nobody`. Mirroring
upstream is the rule; flagging the consequence rather than silently
keeping an oc-only extension that changes a wire byte.

(cherry picked from commit 6b1bccd6597d10680429f23d3bc10cfe9bcc310f)

* fix(cli): let --block-size reach the shared size parser

`--block-size` is the only one of upstream's four `parse_size_arg`
options that could not take a suffix. A bare-`u64` gate in the argv
layer rejected the value before the shared, suffix-aware parser ran:

    let s = value.to_string_lossy();
    if s.parse::<u64>().is_err() { return Err(...) }

`--min-size`, `--max-size` and `--bwlimit` have no such gate three lines
away, which is why they accepted `1K` and `--block-size` did not. Upstream
parses all four with one helper (options.c:1802, :1809, :1815, :1821), so
`size.rs`'s already-tested suffix support was simply unreachable in
production for this one option.

Deleting the gate fixes 20 of the 21 measured spellings; nothing else was
needed, because the shared parser already implements the whole grammar.
Measured against the real rsync 3.5.0 binary:

  accepted   700  1K  1k  1KB  1kb  1KiB  1kib  128K  1.5K  0
             1K+1  1K-1  1B  8b  131072
  rejected   1M  1G  1T  1P  131073 (all "too large", max 128.00K)
             1Z  1KX ("invalid")

oc now matches every row. Rejection of `-1` and `abc` is preserved - it
just happens one layer down, with the value named.

The value test is the one that matters: acceptance alone would pass on a
parser that ignored the scale, so the new test pins `1K` == `1024` and
`1KB` == `1000` through the delta itemization, with a control assertion
that 1024 and 1000 actually differ on the fixture. That control fired
during development - the first fixture reported 0 matched / 0 literal for
every block size because the quick-check skipped the file, so the two
equalities were comparing nothing. `--ignore-times` fixes the fixture.

Three tests pinned the old LAYER rather than the behaviour and are
rewritten: two asserted a clap `ValueValidation` error for `-B abc` /
`-B -1` and now assert the end-to-end rejection; the third used
`--block-size=abc` only as a vehicle for a clap error while guarding
against a doubled `syntax or usage error: error:` prefix, and now uses
`--io-uring-depth=abc`, which still produces one.

Residual, deliberately not folded in: upstream accepts an EMPTY value
(`--block-size=`, which resolves to 0 and falls back to the default) for
all four of these options, and oc rejects it for all four. That is a
shared-parser divergence of a different shape and scope, and it is filed
separately rather than widened into this change.

(cherry picked from commit f84b9fd8906bfc8672339fd4b63337cd03871dc8)

* fix(cli): resolve an empty size value to 0, per option

Upstream accepts an empty size value: the digit scan in `parse_size_arg`
leaves `arg` on the terminator, so the suffix switch takes `def_suf` and
`strtod("")` yields 0 (options.c:1172-1175, :1215). oc rejected it on
every option that takes a size.

⚠ The filed description said "resolves to 0 and falls back to the
default". That is true only for `--block-size`. Measured behaviour, not
exit codes, on rsync 3.5.0 with a 6-byte source file:

  option         empty            =0               same?
  --block-size   transferred      transferred      yes -> default blength
  --min-size     transferred      transferred      yes -> no lower bound
  --max-size     EXCLUDED         EXCLUDED         yes -> a real 0 bound
  --bwlimit      transferred      transferred      yes -> unlimited
  --max-alloc    rejected         rejected         yes -> min is 1 MiB

So `--max-size=` does not mean "no limit" and does not mean "the
default": it is a bound of 0 that excludes every non-empty file. The one
rule that holds across all five is `empty == 0`, and what 0 MEANS is
decided by each option's own `min_value` / `unlimited_0` at its upstream
call site.

That is why the rule is applied per option rather than inside
`parse_size_spec`. `--max-alloc` has a 1 MiB minimum and rejects 0 on
both implementations; folding empty-to-zero into the shared string parser
would have silently started accepting `--max-alloc=`, undoing the guard
that landed for the zero case. `parse_size_spec` keeps rejecting empty,
and the four options whose upstream call permits 0 normalise first.

Tests assert the RESOLVED VALUE, not acceptance: each option's empty
spelling must be indistinguishable from `=0`, `--max-size=` must exclude
the file (the discriminator - a build that accepted the string and then
ignored it would pass every other assertion), a non-empty value must
still parse and apply, and `--max-alloc=` must stay rejected. A
cross-implementation cell asserts the same table against the real 3.5.0
binary. Non-vacuity measured: reverting the four call sites reddens the
two oc cells and leaves the oracle, the control and the max-alloc guard
green.

One unit test pinned the old rejection and is corrected to assert the
`=0` equivalence.

(cherry picked from commit 4835d9733f58c28924c6ba04442b5228f795b8ab)

* fix(cli): a filter file that will not open is fatal with RERR_FILEIO

Upstream reports every failed filter-file open from one site with one
message and one exit code (exclude.c:1712-1719):

    rsyserr(FERROR, errno, "failed to open %sclude file %s",
            template->rflags & FILTRULE_INCLUDE ? "in" : "ex", fname);
    exit_cleanup(RERR_FILEIO);

oc exited 1 with `failed to read filter file '<path>'` and Rust's
`(os error 2)` errno rendering. Measured against 3.5.0:

    --exclude-from=<missing>     upstream 11   oc 1
    --include-from=<missing>     upstream 11   oc 1
    --filter='merge <missing>'   upstream 11   oc 1
    --filter='. <missing>'       upstream 11   oc 1

The include/exclude word is DERIVED, not per option: `--filter='.+ F'`
and `--filter='merge,+ F'` report "include file" because the `+` modifier
sets FILTRULE_INCLUDE. Both spellings are in the test table, since they
are the only evidence the word is not hardcoded.

Applied at the two open sites (`load_filter_file_patterns` for
--exclude-from/--include-from, `read_merge_file` for merge rules) through
one shared helper, because upstream has exactly one such site.

Two boundaries the tests pin as deliberately NOT part of the rule:

- per-directory merges (`dir-merge`, `-F`) pass no XFLG_FATAL_ERRORS
  (exclude.c:912), so a missing per-directory filter file must stay a
  silent success. Keying the fix off "filter file missing" instead of off
  the call site would have broken every -F transfer.
- `--files-from` looks like the same shape and is NOT: upstream reports
  it from main.c:1886 and exits 1, measured on both binaries. Folding the
  two onto one helper because the messages resemble each other would have
  changed an exit code nobody asked to change.

`read_merge_file` now opens and reads in two steps so only a genuine open
failure takes upstream's wording; a mid-file read error or non-UTF-8
contents keeps its own report. The post-open read error in
`load_filter_file_patterns` is likewise left alone - upstream's getc loop
cannot distinguish a read error from EOF, so there is no upstream rule to
mirror there, and the comment says so rather than inventing a citation.

Tests: an 8-row table (6 fatal spellings, 2 that must stay non-fatal)
asserted against oc AND against the real 3.5.0 binary, plus a control
that a readable filter file still parses and applies, plus a guard that
--files-from stays exit 1. Assertions are on the exit CODE and the
WORDING and the named path together - exiting 11 with an unrelated
message would be a different bug and must not pass. Non-vacuity measured:
reverting the helper to exit 1 with the old wording reddens exactly the
oc cell and leaves the oracle, the control and the guard green.

Two tests encoded the old behaviour (`exit 1` + `failed to read filter
file`) and are corrected.

(cherry picked from commit 3f26e4500bfd2216851eaa00d80bba1fc706afe8)
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