Skip to content

Round-3 slice 3: engine fixes for niubash #532/#529/#520/#533/#534 (e1) - #1503

Merged
caomengxuan666 merged 5 commits into
masterfrom
fix/bulk-r3-slice3
Oct 24, 2026
Merged

caomengxuan666 merged 5 commits into
masterfrom
fix/bulk-r3-slice3

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

第三轮第三片(rubash 侧):e1 簇 5 条引擎修复

问题记录在 niubash(n2 回交的引擎清单),修复落 rubash 引擎,一条 issue 一个 commit。

Fixes unixwin/niubash#532
Fixes unixwin/niubash#529
Fixes unixwin/niubash#520
Fixes unixwin/niubash#533
Fixes unixwin/niubash#534

逐条:

  • niubash#532(P1):复合重定向 + 中段管道输出被覆盖(( echo A; printf 'B\n' | cat; echo C ) > f 丢 B)。根因:管道 stage 路由把 fd 1 重播种为 stage 管道后,apply_ordered_output_redirects 的「已绑定则跳过」条件失效,payload 经第二个独立偏移的 append 句柄重开同一文件、随后被 body 写覆盖。修法:跳过条件放宽到 defer+Stdout 重播种形态,payload 经绑定句柄一次写出。8 形态电池与 GNU bash 5.3.20 逐项一致。
  • niubash#529:comsub/管道内 [ -t ] 与 GNU 相反。根因:-t 读的是按进程 stdio 镜像的端点标记,而 comsub/管道 stage 的端点实际解析到捕获/管道。修法:stdout_sink_is_terminal() / stdin_source_is_terminal() 按真实汇/源判定(fd 2 臂刻意不动,理由见 commit)。pty 脚本模式与 GNU 一致。
  • niubash#520:complete -F/-C 动态补全未接线、-D/-E 无回退。修法:resolve_compspec + complete_line_candidates_with_dynamic(合并序按 pcomplete.c),complete_line 改 &mut self 并执行 -F/-C(COMP_* 按真实词表绑定)。新增 3 条单元测试。
  • niubash#533:内建 cp -p/-a 不保留时间/mode(-p 是空转 arm,成功路径还显式设为当前时间)。修法:preserve_mode/preserve_times 两标志按 -p/--preserve[=LIST]/-a 语义置位,拷贝成功点经句柄施加(树拷贝逐节点、目录在其子项之后)。
  • niubash#534:rm -rf . 报文案错(报 ENOENT,rc 本对)。修法:按 coreutils 9.4 矩阵——递归 + 末分量为 ./.. + 解析到已存在目录时以 refusing to remove '.' or '..' directory: skipping 拒绝(存在性优先于拒绝),-f 吞没臂从 NotFound 扩到 NotADirectory。

Refs unixwin/niubash#519 — 仅诊断、无代码:该引擎类问题已由 rubash PR #1324 在基线内修复(DOS 设备 append 重开面已审计齐全),最终确认需 Windows 宿主复测,Linux 不可复现,故不关单。

验证(集成阶段在新基线 3b0686f 上复跑):lib 回归失败集与 #534 第 7 例复跑、w3 procsub EOF 时序失败的静树归因、246 差分与 pristine 集对照,结果见集成报告。

…eopening it (niubash#532 engine side)

A compound redirect (> f) is spliced into body commands as an injected append redirect whose binding lives in the fd table as a shared File endpoint. The pipeline routing walks reseed fd 1 as the stage pipe (OutputTarget::Stdout, defer_stdout_writes) before the ordered redirect walk, so the already-bound skip in apply_ordered_output_redirects missed, the walk fell through to open_command_output_target, and the stage payload was written through a second, independent-offset append handle; the body's later writes through the bound handle then overwrote it (( echo A; printf B | cat; echo C ) > f lost B). GNU keeps one open file description per redirection (redir.c do_redirections / execute_cmd.c execute_pipeline). Widen the skip to the defer+Stdout reseeded shape; the payload then leaves through the caller's write_pipeline_output via the bound handle. Verified: 8-shape battery byte-identical to GNU bash 5.3.20.
…d pipelines (niubash#529 engine side)

sync_fd_terminal_marks judged the Stdout endpoint by the process stdout and InheritedProcessStdin by the process stdin. Inside a command substitution the child's stdout is the capture pipe (subst.c:7143 command_substitute) and a pipeline element's fd 0 is the pipe (execute_cmd.c execute_pipeline), so [ -t 1 ] in $() answered Y on a terminal where GNU answers N, and [ -t 0 ] misjudged bound FUNCTION_STDIN input. New helpers: stdout_sink_is_terminal (false while a stdout_capture or the thread-local capture is active) and stdin_source_is_terminal (false while FUNCTION_STDIN is bound), applied in the sync walk and in redirect_target_is_terminal. The Stderr arm is unchanged: a stage's stderr capture is a routing buffer, not a semantic capture. Verified on a pty (script mode): D=Y A=N P0=Y, matching GNU bash 5.3.20.
…n (niubash#520 engine side)

Executor::complete_line never resolved dynamic compspec actions (its own doc called -F/-C a follow-up) and the candidate generator only did exact-name lookup, so -D default and -E empty-line compspecs could never fire and has_compspec blocked them at the host gate. Add resolve_compspec (bashline.c attempt_shell_completion: own spec, else -D; empty line: -E else -D; word 0: none), complete_line_candidates_with_dynamic merging dynamic candidates the way pcomplete.c gen_compspec_completions does (static prefix-filtered, -F COMPREPLY / -C output appended unfiltered per pcomplete.c:1129-1132, -X filter over the merged list), and Executor::completion_dynamic_for_line running the governing hook with the live COMP_* context bound (real COMP_WORDS/COMP_CWORD, build_arg_list args; _EmptycmD_ with CWORD -1 on the empty line — probed on GNU bash 5.3.20). complete_line becomes &mut self; has_compspec counts -D/-E. Three unit tests cover -D fallback, -E empty-line-only, and the unfiltered merge.
…iubash#533 engine side)

external_cp parsed -p and --preserve as no-ops and -a as recursive-only, so the destination always took the copy time (coreutils cp.c: -p preserves mode/ownership/timestamps; -a is -dR --preserve=all). Track preserve_mode/preserve_times from -p, --preserve[=LIST], --no-preserve=LIST and -a/--archive (ownership/links/context/xattr parse but are not actionable, matching an unprivileged GNU cp), and stamp destinations via cp_apply_preserved — timestamps before mode, best-effort — per file and per tree node in cp_copy_tree (directories after their contents). Verified against GNU: -p/-a/bare --preserve/--preserve=timestamps all yield the source mtime and mode; plain copies still take the current time.
…g (niubash#534 engine side)

rm -rf . answered 'cannot remove .: No such file or directory'. coreutils rm.c refuses a recursive operand whose last component (trailing slashes stripped) is . or .. and which resolves to an existing directory: 'refusing to remove . or .. directory: skipping <operand>', status 1. Add that check before the metadata dispatch in external_rm (missing operands keep the plain existence error; non-recursive keeps 'Is a directory'), and let -f swallow ENOTDIR like ENOENT (gnulib remove.c), so rm -rf f/. on a regular file is silent with status 0. Verified against coreutils 9.4 on a 7-case matrix.
@caomengxuan666
caomengxuan666 merged commit a3343c0 into master Oct 24, 2026
5 of 8 checks passed
@caomengxuan666
caomengxuan666 deleted the fix/bulk-r3-slice3 branch October 30, 2026 01:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment