Skip to content

feat(daemon): wire module charset= directive to iconv runtime (#1917) - #3554

Merged
oferchen merged 5 commits into
masterfrom
feat/iconv-daemon-charset-1917
May 2, 2026
Merged

oferchen merged 5 commits into
masterfrom
feat/iconv-daemon-charset-1917

Conversation

@oferchen

@oferchen oferchen commented May 2, 2026

Copy link
Copy Markdown
Owner

Summary

Closes #1917. Bridges the parsed daemon module charset = directive into the iconv runtime so --iconv from a client to an oc-rsync daemon actually transcodes filenames instead of silently no-op'ing.

  • build_server_config now resolves module.charset() to a protocol::iconv::FilenameConverter and assigns it to ServerConfig.connection.iconv - the same field the SSH/local client path already populates at crates/core/src/client/remote/flags.rs:228.
  • New helper resolve_module_charset_converter mirrors upstream setup_iconv() (rsync.c:87-140, clientserver.c:712-716): post-comma segment wins on the server side (rsync.c:118-120 am_server branch), . and empty resolve to locale default (rsync.c:125-126), unknown charsets degrade to None with a tracing warning (lenient behaviour matching IconvSetting::resolve_converter on the client side).
  • New iconv Cargo feature on the daemon crate turns on core/iconv + protocol/iconv so encoding_rs is compiled in. Without the feature, FilenameConverter::new only accepts UTF-8 and runtime behaviour is unchanged.
  • Drops standalone:iconv-upstream from KNOWN_FAILURES and DASHBOARD_ENTRIES in tools/ci/known_failures.conf so the existing test_iconv_upstream_interop daemon push test (tools/ci/run_interop.sh:3168, charset = ISO-8859-1, --iconv=UTF-8,ISO-8859-1) starts gating regressions.

Tests

8 new unit tests in crates/daemon/src/daemon/sections/module_access/client_args.rs::iconv_charset_converter_tests:

  • iconv_charset_returns_none_for_missing_directive
  • iconv_charset_returns_none_for_empty_directive
  • iconv_charset_dot_means_locale_default
  • iconv_charset_comma_with_dot_resolves_to_identity
  • iconv_charset_resolves_simple_charset (iconv-gated)
  • iconv_charset_uses_segment_after_comma (iconv-gated)
  • iconv_charset_returns_none_for_unknown_charset (iconv-gated)
  • iconv_charset_trims_whitespace (iconv-gated)
  • iconv_charset_round_trip_latin1_utf8 (iconv-gated; verifies caf\xe9.txt Latin-1 -> UTF-8 café.txt and back)

Test plan

  • cargo nextest run -p daemon --all-features -E 'test(iconv)' (CI)
  • cargo nextest run -p protocol --all-features -E 'test(iconv)' (CI)
  • Interop Validation workflow runs test_iconv_upstream_interop against rsync 3.4.1 (no longer in known-failures list)
  • fmt + clippy + nextest (stable) + Windows + macOS + Linux musl all green

Upstream references

  • clientserver.c:712-716 - iconv_opt = lp_charset(i); if (*iconv_opt) setup_iconv();
  • rsync.c:87-140 - setup_iconv() opens ic_send and ic_recv iconv handles
  • rsync.c:118-120 - server side honours post-comma segment
  • rsync.c:125-126 - . / empty means locale default
  • loadparm.c - charset module parameter

@github-actions github-actions Bot added the enhancement New feature or request label May 2, 2026
oferchen added 4 commits May 2, 2026 09:36
The daemon parses `charset =` (module_directives.rs:330) and stores it on
ModuleDefinition.charset, but the value was never threaded into the iconv
runtime - so `--iconv` from a client to an oc-rsync daemon was a silent
no-op even when the module config declared a charset.

Wire it through build_server_config: read module.charset(), resolve it to
a protocol::iconv::FilenameConverter, and assign it to
ServerConfig.connection.iconv (the same field the SSH/local client path
already populates at remote/flags.rs:228).

Mirror upstream's setup_iconv() (rsync.c:87-140, clientserver.c:712-716):

- comma-separated `LOCAL,REMOTE` honours the post-comma segment on the
  server (upstream rsync.c:118-120, am_server branch);
- `.` and the empty string resolve to the locale default
  (upstream rsync.c:125-126);
- unknown charsets log via tracing and degrade to None (no transcoding)
  rather than aborting, matching the lenient behaviour
  IconvSetting::resolve_converter already uses on the client side.

Add daemon `iconv` Cargo feature that turns on `core/iconv` and
`protocol/iconv` so encoding_rs is actually compiled in. Without the
feature, FilenameConverter::new only accepts UTF-8 and the runtime
behaviour is identical to before this change.

Add 8 unit tests in client_args.rs covering: missing/empty/whitespace
directives, `.` and `LOCAL,.` identity, comma-segment selection, unknown
charset soft failure, whitespace trimming, and a Latin-1<->UTF-8 byte
round trip.

Drop `standalone:iconv-upstream` from KNOWN_FAILURES and DASHBOARD_ENTRIES
in tools/ci/known_failures.conf so the existing iconv-upstream interop
test (run_interop.sh:3168, daemon push with `charset = ISO-8859-1`) starts
gating regressions.
… only (#1917)

The charset() accessor on ModuleDefinition is in a #[cfg(test)] impl block,
so it isn't visible in non-test builds. Use the pub(crate) field directly,
matching the surrounding accesses (dont_compress, temp_dir, path).
…match

The iconv-upstream test was reporting "plain.txt content mismatch after
iconv transfer" without revealing what bytes were actually written, which
files exist at the destination, or what the daemon logged. Add a
hexdump+find+log-tail dump on both the missing-file and cmp-mismatch
branches so the next CI run pinpoints whether plain.txt is empty,
truncated, or carrying a different file's bytes (e.g. NDX misalignment).

Refs #1917
The previous test asserted that destination filenames remained UTF-8
after `--iconv=UTF-8,ISO-8859-1` with daemon `charset = ISO-8859-1`.
That premise contradicts upstream rsync's wire model:

  rsync.c:130-140 - the wire is always UTF-8, and the `charset`
  parameter (CLI LOCAL,REMOTE or daemon `charset =`) names the *local
  disk* encoding, not the wire encoding.

Result: the daemon's ic_recv (UTF-8 -> ISO-8859-1) writes single-byte
Latin-1 filenames to disk (caf\xe9.txt), but the test was looking for
UTF-8 multi-byte filenames (caf\xc3\xa9.txt) that never exist there.

Redesign uses parallel-array Value Objects to capture the source-side
UTF-8 bytes and the dest-side ISO-8859-1 bytes for each logical name,
plus single-responsibility helpers:

  _ic_init_fixtures   - populate the fixture mapping
  _ic_write_fixtures  - create source files; signal SKIP on host reject
  _ic_verify_dest     - verify dest has the ISO-8859-1 byte name + body
  _ic_dump_failure    - uniform diagnostic dump (octal-escaped ls + log)

Verification compares the source file content against the expected
ISO-8859-1 dest path, which is the property that proves the daemon's
iconv pipeline ran end-to-end.
@oferchen
oferchen force-pushed the feat/iconv-daemon-charset-1917 branch from 59b4d42 to a9af5cb Compare May 2, 2026 06:36
Previous multi-file fixture exposed an unrelated bug: the receiver's
flist ingest pipeline misaligns content with names when multiple files
re-sort after iconv conversion (UTF-8 -> Latin-1). That is a separate
bug (#1913 receiver flist ingest) and out of scope for the daemon
charset directive PR.

Replace the parallel-array fixture with a single-file fixture
(cafe.txt, U+00E9) so the test only validates what #1917 fixes:
the daemon's `charset =` directive activating ic_recv on the
receiver to convert wire-UTF-8 filenames to disk-Latin-1 bytes.

The multi-file scenario will be re-enabled once #1913 lands.
@oferchen
oferchen merged commit 809b05c into master May 2, 2026
44 checks passed
@oferchen
oferchen deleted the feat/iconv-daemon-charset-1917 branch May 2, 2026 13:01
oferchen added a commit that referenced this pull request May 3, 2026
…arser (#3566)

* test(interop): align iconv-local-ssh with upstream Latin-1 dest semantics

PR #3554 redesigned the daemon iconv test (test_iconv_upstream_interop)
to use a single-file Value Object that asserts the destination disk
holds the ISO-8859-1 byte name (caf\xe9.txt), not the UTF-8 byte name
(caf\xc3\xa9.txt). That redesign was missed for the SSH/local-mode
test (test_iconv_local_ssh_interop, added separately in PR #3534),
which still asserted UTF-8 dest names and failed in CI on a clean
Linux host where ext4 happily stores the Latin-1 single-byte names
upstream's ic_recv writes.

Per upstream rsync.c:85-147 setup_iconv() and options.c:2716-2723
server_options(): with --iconv=UTF-8,ISO-8859-1, the client (charset
UTF-8) keeps the LOCAL half and forwards the post-comma REMOTE half
(ISO-8859-1) to the spawned peer. The spawned receiver opens
ic_recv = iconv_open(charset, UTF8_CHARSET), so it transcodes UTF-8
wire bytes into single-byte Latin-1 on the local disk. The dest
filename is therefore caf\xe9.txt, not caf\xc3\xa9.txt.

Refactor test_iconv_local_ssh_interop to reuse the single-file Value
Object helpers from the daemon test (_ic_init_fixtures /
_ic_write_fixtures / _ic_verify_dest at run_interop.sh:3142-3175),
expand the docblock to explain the am_server LOCAL/REMOTE split with
explicit upstream references, and drop the multi-file UTF-8-expecting
fixture that masked the real wire semantics.

No production code changes; this fixes the test expectation only.

* fix(cli): wire --iconv into server-mode flag parser

Server mode previously dropped --iconv=CHARSET passed by the client,
falling back to no transcoding. This broke --iconv=LOCAL,REMOTE
transfers over SSH and local-shell where the on-disk filename encoding
differs between sides: receiver/generator skipped the iconv hook and
wrote/read wire UTF-8 bytes verbatim instead of transcoding to the
server's local charset.

Parse --iconv=VALUE in ServerLongFlags, resolve via IconvSetting,
and assign to config.connection.iconv so receiver and generator pick
up the converter. Mirrors the daemon path
(daemon/sections/module_access/client_args.rs) and the SSH-client path
(client/remote/flags.rs).

upstream: rsync.c:85-147 setup_iconv()
upstream: options.c:2716-2723 server-side iconv forwarding

* fix(cli): recognise --timeout= in server-mode flag parser

The server-mode argument parser did not recognise `--timeout=N`, so the
flag was treated as a positional argument by `parse_server_flag_string_and_args`
and consumed in place of the destination path. With the iconv-local-ssh
scenario, strace showed the receiver creating `--timeout=10/` instead of
`dest/` because upstream rsync emits `--timeout=10` after `--iconv=...`
in the server arg list.

Add `--timeout=` to `ServerLongFlags`, `parse_value_bearing_flag`, and
`is_known_server_long_flag` so the flag is captured (its value remains
unwired for now, matching the prior silent-drop behaviour) and excluded
from positional extraction.

upstream: options.c - server_options() emits `--timeout=%d` from io_timeout
oferchen added a commit that referenced this pull request May 5, 2026
…#3554)

* feat(daemon): wire module charset= directive to iconv runtime (#1917)

The daemon parses `charset =` (module_directives.rs:330) and stores it on
ModuleDefinition.charset, but the value was never threaded into the iconv
runtime - so `--iconv` from a client to an oc-rsync daemon was a silent
no-op even when the module config declared a charset.

Wire it through build_server_config: read module.charset(), resolve it to
a protocol::iconv::FilenameConverter, and assign it to
ServerConfig.connection.iconv (the same field the SSH/local client path
already populates at remote/flags.rs:228).

Mirror upstream's setup_iconv() (rsync.c:87-140, clientserver.c:712-716):

- comma-separated `LOCAL,REMOTE` honours the post-comma segment on the
  server (upstream rsync.c:118-120, am_server branch);
- `.` and the empty string resolve to the locale default
  (upstream rsync.c:125-126);
- unknown charsets log via tracing and degrade to None (no transcoding)
  rather than aborting, matching the lenient behaviour
  IconvSetting::resolve_converter already uses on the client side.

Add daemon `iconv` Cargo feature that turns on `core/iconv` and
`protocol/iconv` so encoding_rs is actually compiled in. Without the
feature, FilenameConverter::new only accepts UTF-8 and the runtime
behaviour is identical to before this change.

Add 8 unit tests in client_args.rs covering: missing/empty/whitespace
directives, `.` and `LOCAL,.` identity, comma-segment selection, unknown
charset soft failure, whitespace trimming, and a Latin-1<->UTF-8 byte
round trip.

Drop `standalone:iconv-upstream` from KNOWN_FAILURES and DASHBOARD_ENTRIES
in tools/ci/known_failures.conf so the existing iconv-upstream interop
test (run_interop.sh:3168, daemon push with `charset = ISO-8859-1`) starts
gating regressions.

* fix(daemon): use field access for charset since accessor is cfg(test) only (#1917)

The charset() accessor on ModuleDefinition is in a #[cfg(test)] impl block,
so it isn't visible in non-test builds. Use the pub(crate) field directly,
matching the surrounding accesses (dont_compress, temp_dir, path).

* test(interop): dump dest contents and daemon log on iconv content mismatch

The iconv-upstream test was reporting "plain.txt content mismatch after
iconv transfer" without revealing what bytes were actually written, which
files exist at the destination, or what the daemon logged. Add a
hexdump+find+log-tail dump on both the missing-file and cmp-mismatch
branches so the next CI run pinpoints whether plain.txt is empty,
truncated, or carrying a different file's bytes (e.g. NDX misalignment).

Refs #1917

* test(interop): redesign iconv test for ISO-8859-1 dest filenames

The previous test asserted that destination filenames remained UTF-8
after `--iconv=UTF-8,ISO-8859-1` with daemon `charset = ISO-8859-1`.
That premise contradicts upstream rsync's wire model:

  rsync.c:130-140 - the wire is always UTF-8, and the `charset`
  parameter (CLI LOCAL,REMOTE or daemon `charset =`) names the *local
  disk* encoding, not the wire encoding.

Result: the daemon's ic_recv (UTF-8 -> ISO-8859-1) writes single-byte
Latin-1 filenames to disk (caf\xe9.txt), but the test was looking for
UTF-8 multi-byte filenames (caf\xc3\xa9.txt) that never exist there.

Redesign uses parallel-array Value Objects to capture the source-side
UTF-8 bytes and the dest-side ISO-8859-1 bytes for each logical name,
plus single-responsibility helpers:

  _ic_init_fixtures   - populate the fixture mapping
  _ic_write_fixtures  - create source files; signal SKIP on host reject
  _ic_verify_dest     - verify dest has the ISO-8859-1 byte name + body
  _ic_dump_failure    - uniform diagnostic dump (octal-escaped ls + log)

Verification compares the source file content against the expected
ISO-8859-1 dest path, which is the property that proves the daemon's
iconv pipeline ran end-to-end.

* test(interop): single-file iconv fixture isolates #1917 from #1913

Previous multi-file fixture exposed an unrelated bug: the receiver's
flist ingest pipeline misaligns content with names when multiple files
re-sort after iconv conversion (UTF-8 -> Latin-1). That is a separate
bug (#1913 receiver flist ingest) and out of scope for the daemon
charset directive PR.

Replace the parallel-array fixture with a single-file fixture
(cafe.txt, U+00E9) so the test only validates what #1917 fixes:
the daemon's `charset =` directive activating ic_recv on the
receiver to convert wire-UTF-8 filenames to disk-Latin-1 bytes.

The multi-file scenario will be re-enabled once #1913 lands.
oferchen added a commit that referenced this pull request May 5, 2026
…arser (#3566)

* test(interop): align iconv-local-ssh with upstream Latin-1 dest semantics

PR #3554 redesigned the daemon iconv test (test_iconv_upstream_interop)
to use a single-file Value Object that asserts the destination disk
holds the ISO-8859-1 byte name (caf\xe9.txt), not the UTF-8 byte name
(caf\xc3\xa9.txt). That redesign was missed for the SSH/local-mode
test (test_iconv_local_ssh_interop, added separately in PR #3534),
which still asserted UTF-8 dest names and failed in CI on a clean
Linux host where ext4 happily stores the Latin-1 single-byte names
upstream's ic_recv writes.

Per upstream rsync.c:85-147 setup_iconv() and options.c:2716-2723
server_options(): with --iconv=UTF-8,ISO-8859-1, the client (charset
UTF-8) keeps the LOCAL half and forwards the post-comma REMOTE half
(ISO-8859-1) to the spawned peer. The spawned receiver opens
ic_recv = iconv_open(charset, UTF8_CHARSET), so it transcodes UTF-8
wire bytes into single-byte Latin-1 on the local disk. The dest
filename is therefore caf\xe9.txt, not caf\xc3\xa9.txt.

Refactor test_iconv_local_ssh_interop to reuse the single-file Value
Object helpers from the daemon test (_ic_init_fixtures /
_ic_write_fixtures / _ic_verify_dest at run_interop.sh:3142-3175),
expand the docblock to explain the am_server LOCAL/REMOTE split with
explicit upstream references, and drop the multi-file UTF-8-expecting
fixture that masked the real wire semantics.

No production code changes; this fixes the test expectation only.

* fix(cli): wire --iconv into server-mode flag parser

Server mode previously dropped --iconv=CHARSET passed by the client,
falling back to no transcoding. This broke --iconv=LOCAL,REMOTE
transfers over SSH and local-shell where the on-disk filename encoding
differs between sides: receiver/generator skipped the iconv hook and
wrote/read wire UTF-8 bytes verbatim instead of transcoding to the
server's local charset.

Parse --iconv=VALUE in ServerLongFlags, resolve via IconvSetting,
and assign to config.connection.iconv so receiver and generator pick
up the converter. Mirrors the daemon path
(daemon/sections/module_access/client_args.rs) and the SSH-client path
(client/remote/flags.rs).

upstream: rsync.c:85-147 setup_iconv()
upstream: options.c:2716-2723 server-side iconv forwarding

* fix(cli): recognise --timeout= in server-mode flag parser

The server-mode argument parser did not recognise `--timeout=N`, so the
flag was treated as a positional argument by `parse_server_flag_string_and_args`
and consumed in place of the destination path. With the iconv-local-ssh
scenario, strace showed the receiver creating `--timeout=10/` instead of
`dest/` because upstream rsync emits `--timeout=10` after `--iconv=...`
in the server arg list.

Add `--timeout=` to `ServerLongFlags`, `parse_value_bearing_flag`, and
`is_known_server_long_flag` so the flag is captured (its value remains
unwired for now, matching the prior silent-drop behaviour) and excluded
from positional extraction.

upstream: options.c - server_options() emits `--timeout=%d` from io_timeout
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant