Skip to content

WIP: 模拟层 builtins 选项纪律九单(#1941-#1948 + #1939) - #2018

Merged
caomengxuan666 merged 7 commits into
masterfrom
fix/builtins-opts-1941-1948-1939
Oct 29, 2026
Merged

caomengxuan666 merged 7 commits into
masterfrom
fix/builtins-opts-1941-1948-1939

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

WIP: 模拟层 builtins 选项纪律九单(cp/chmod/touch/mkfifo/rm + TIMEFORMAT)

共享机制一处收敛:external_file_builtins.rs 新增 gnulib getopt_long
纪律层——resolve_long_option(精确/唯一前缀缩写/no_abbrev)、grouped
argmatch 值匹配、coreutils 9.4 逐字节诊断助手(含 Try 行);各命令
选项表驱动 handler 与 declines,不再逐命令手写 match。

Fixes #1941
Fixes #1942
Fixes #1943
Fixes #1944
Fixes #1945
Fixes #1946
Fixes #1947
Fixes #1948
Fixes #1939

逐单要点(oracle = 本机 coreutils 9.4 + GNU bash 5.3.20 实测):

回归钉:tests/issue1941_1948_sim_layer_option_regressions.rs(逐单种子)

  • tests/cli_tests.rs 两条 TIMEFORMAT 钉。门账见工区 REPORT.md。

…ons, =value (rubash#1941, #1942, #1946)

Shared gnulib-style machinery in external_file_builtins.rs:
resolve_long_option (exact match / unique-prefix abbreviation /
no_abbrev), grouped argmatch for option values, and the coreutils
9.4 diagnostic shapes with the Try line. cp is the first consumer:

- #1941: --preserve validates against the full attribute table
  (mode/timestamps/ownership/links/context/xattr/all) with argmatch
  prefixes; invalid or empty elements diagnose with the Valid
  arguments block and create nothing; links reuses the first copy
  through an inode identity map (hard_link); xattr is copied
  best-effort on unix.
- #1942: unknown long options report the whole word (=value
  included), ambiguous prefixes list candidates in table order,
  unambiguous abbreviations are accepted, unknown short options
  gain the Try line; dead cp_usage_text removed.
- #1946 (cp leg): a no-argument long option given =value fails
  with the canonical-name "doesn't allow an argument" diagnostic.

Regression pins: the #1941/#1942 sections of
tests/issue1941_1948_sim_layer_option_regressions.rs.
…te machine (rubash#1944, #1947, #1948, #1946)

- #1944: -f is GNU's silent legacy no-op flag, not an invalid
  option.
- #1947: missing values for -r/-t/-d and --date/--reference/--time
  diagnose in the short/long coreutils forms with the Try line;
  --time resolves through grouped argmatch with its Valid block.
- #1948: -t converts eagerly (a bad stamp fails at once, a later
  valid -t cannot rescue it); -d/-r are recorded during the scan
  and resolved once after it — last wins, superseded references
  are never stat'ed and superseded dates never parsed; -t with
  -d/-r is the more-than-one-source error; -r with -d stats the
  reference first, then parses the date, and the date wins in
  either order. touch_declines resolves abbreviations through the
  same table.
- #1946 (touch leg): no-argument long options reject =value by
  canonical name through the shared resolver.

Regression pins: the #1944/#1947/#1948 sections of
tests/issue1941_1948_sim_layer_option_regressions.rs.
- #1946 (rm leg): --force=x / --recursive=x / --dir=x /
  --verbose=x fail with the canonical "doesn't allow an argument"
  diagnostic; unknown options keep the whole-word unrecognized
  form; --ver reports the verbose/version ambiguity.
- --no-preserve-root may not be abbreviated: any proper prefix
  fails with "rm: you may not abbreviate the --no-preserve-root
  option" (no Try line, coreutils 9.4). --preserve-root keeps its
  optional argument and its own value diagnostic. rm_declines
  resolves abbreviations through the same table, so abbreviated
  --interactive forms decline like the full spellings.

Regression pins: the #1946 section of
tests/issue1941_1948_sim_layer_option_regressions.rs.
…dows arm (rubash#1945)

The Windows leaf no longer exits 0 in silence: an invocation with
no operand prints "mkfifo: missing operand" plus the Try line
(rc 1); a dangling -m or --mode prints the short/long
requires-an-argument forms; unknown short and long options
diagnose instead of being swallowed; -m consumes the rest of its
cluster or the next word. Per-operand refusals are unchanged, and
the non-Windows face still declines wholesale (rubash#1725).

Regression pins: the #1945 section of
tests/issue1941_1948_sim_layer_option_regressions.rs
(Windows-gated — the shape only exists on the Windows arm).
…h#1943)

coreutils mode_adjust judges X against the mode the file had
before this invocation, plus is_dir — never against bits an
earlier clause of the same mode string just created (a 644 file
under `u+x,g+X` ends 744, not 754). apply_chmod_mode takes is_dir
and tests the ORIGINAL base; the call site reads is_dir from the
same metadata that supplies the base mode.

Regression pins: the #1943 section of
tests/issue1941_1948_sim_layer_option_regressions.rs.
GNU print_formatted_time (execute_cmd.c:1346) expands only %
directives; every other byte, backslash included, is copied
verbatim, so TIMEFORMAT='A\nB' prints a literal backslash-n.
expand_time_format drops its backslash-decoding arm, and the
default format becomes BASH_TIMEFORMAT's actual value — real
newline and tab characters (execute_cmd.c:1245) — instead of
backslash escapes the old expander happened to decode.

Regression pins: tests/cli_tests.rs
timeformat_backslash_is_a_literal_byte and
time_default_format_starts_with_a_real_newline_and_tabs.
…ash#1941)

CI round 1 on PR #2018 caught two target breaks in the cp commit:

- Windows: MetadataExt::file_index is the unstable
  windows_by_handle feature (E0658). cp_inode_key now takes the
  source path and, on Windows, reuses executor::path::file_identity
  (promoted to pub(crate)) — the stable handle-based
  (volume serial, file index) pair `[ a -ef b ]` already compares.
- macOS: libc's listxattr/getxattr/setxattr take extra
  options/position arguments (E0061). The copy walk now goes
  through xattr_list/xattr_get/xattr_set shims that fold those to
  zero on macOS and forward the Linux/Android forms elsewhere.

Verified locally: cargo check --lib clean on x86_64-linux and
x86_64-pc-windows-gnu; the darwin leg is CI-verified (this host
lacks the psm cross C toolchain).
@caomengxuan666
caomengxuan666 marked this pull request as ready for review October 29, 2026 01:38
@caomengxuan666
caomengxuan666 merged commit 9e91412 into master Oct 29, 2026
8 of 9 checks passed
caomengxuan666 added a commit that referenced this pull request Oct 29, 2026
New battery tests/issue2036_s4_projection_regressions.rs pinning
the projected faces' current behavior, measured on the
post-projection tree:

- stage arms (grep/head/wc/tr/sed/trap -p), true/false status,
  the pre-check's 127 decline, the sequential-route cat arm
  replacing while the planner yields (the registered per-face
  rule), the yes stand-in;
- timed models: consumer timeout 142, producer+consumer+followup
  chain, bare-read model engagement;
- comsub word arms (echo/printf/cat + its stand-down
  decline-to-127, basename/umask/pwd/type/kill/ulimit), the
  mktemp arm answering for an unresolvable name (its registered
  per-face rule), the exact-body True/Colon/False slots;
- comsub timed arms (echo/cat/tty + the time report), the front
  face's tty bare and slash forms, heredoc cat and sort -u;
- the #2066 host-flag gates riding the projected slots (Session
  Tier-C seam, #2066 probe technique): cat off -> PATH program,
  on -> in-process; sed off -> PATH program, on -> still the PATH
  program via the arm's InvertedSed recheck.

Two adjudications recorded in the battery itself: the sed
flag-on expectation follows the InvertedSed row (it is not a
plain Replace), and a bare trap-table print is deliberately not
pinned (it reflects signal dispositions inherited from the host
process, which this binary's own Session tests mutate - a
pre-existing host-visible side effect, orthogonal to S4).

Local gates: battery 17/17 (twice), lib suite 961/1/3 with the
failure set identical to the master baseline (the +2 passes are
the new registry pins), -D warnings clean on the lib and this
slice's test targets (the one all-targets -D warnings failure is
the pre-existing dead_code in the #2018 test file, owned by
PR #2079).

Refs #2036
@caomengxuan666
caomengxuan666 deleted the fix/builtins-opts-1941-1948-1939 branch October 30, 2026 01:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment