Skip to content

fix(executor): anchor bind -f / history file operands at the session cwd (Refs #3090) - #3114

Merged
caomengxuan666 merged 4 commits into
masterfrom
fix/3090-relative-operand-session-cwd
Nov 18, 2026
Merged

caomengxuan666 merged 4 commits into
masterfrom
fix/3090-relative-operand-session-cwd

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Refs #3090

(车道自报,待队长复核。)

问题与根因

文件操作数型 builtin 在进程内打开用户给的文件名时按进程 cwd 解析相对名,而 GNU 的唯一 cwd 就是会话 cwd:

  • bind -f(bind_builtins.rs)直接 std::fs::read_to_string(file);
  • history 文件面 -a/-n/-r/-w(history_exec.rs)翻译拼写后把相对名原样交给 SessionHistory 打开。

于是 cd 之后:bind -f pbind 报 cannot read rc 1;history -r phist 静默 rc 1;history -w whist 在进程 cwd 建文件(rc 0、错位落盘)。平名复现,与载体字节无关。

GNU 锚点:builtins/bind.def:274(rl_read_init_file 原样打开操作数;$include 同路,lib/readline/bind.c:1502 parser_include → bind.c:1079);builtins/history.def:273,295-316(文件名——操作数或 $HISTFILE——原样交给 read_history / write_history / maybe_append_history / read_history_range)。

修法(同门同锚定)

  • src/executor/path.rs:G-02 锚点 anchor_at_session_cwd(PATH 查找/cd 一直在用的那个)放宽为 pub(crate);新增组合 anchored_file_operand = 拼写翻译 + 会话 cwd 锚定,空操作数直通以保住 GNU 的 ENOENT 形状。
  • bind_builtins.rs:-f 读取与 $include 回调读取都走 anchored_file_operand。
  • history_exec.rs:四种文件模式的打开走锚定形 fs_path;诊断保留翻译后的 as-typed path 不变。

本 PR 删除了什么

无删除。3 文件 +52/−7(path.rs +24、bind_builtins.rs +17/−2 面、history_exec.rs +18/−4 面),外加前一提交的回归钉 +196。

未含在本 PR 的同单残余(硬停护栏)

验证(车道自报,全量日志在 ~/workspace/fix-3090/verify-*.log)

  • 钉 tests/issue3090_relative_operand_session_cwd.rs(9 格):修复树 9/0;移植纯基底 95ba5914 4 过 / 5 红——5 个缺陷格(bind 相对、bind $include、history -r、history -n+$HISTFILE 默认、history -w/-a 落点)全红,4 个守卫格(绝对名 ×2、诊断原文 ×2)双边绿。
  • GNU 三方对照(探针 p01–p05,脚本文件,LC_ALL=C.UTF-8):修复树与 GNU bash 5.3.20 的 stdout/stderr/落盘位置全 SAME;基底相对形全红、绝对形已绿。
  • lib 双边、邻茎 10 茎(marker_leak_golden + history 六茎 + bind 三茎)、RUSTFLAGS="-D warnings"、fmt/hygiene/CR:见车道 REPORT 逐腿数字。

…on cwd (Refs #3090)

tests/issue3090_relative_operand_session_cwd.rs: 9 cells — cd-then-
relative bind -f (incl. $include), history -r/-n (operand and
$HISTFILE default), -w/-a landing in the session cwd, plus
absolute-operand and diagnostic-spelling guards.

GNU: builtins/bind.def:274 (rl_read_init_file opens the operand
verbatim); builtins/history.def:273,295-316 (the filename is handed
verbatim to read_history / write_history / maybe_append_history).

On pristine base 95ba591 the pin reads 4 passed / 5 failed: the 5
defect cells red, the 4 guard cells green.
…cwd (Refs #3090)

Both builtins opened a relative filename against the process cwd.
GNU's single cwd is the session cwd (builtins/bind.def:274;
builtins/history.def:273,295-316), so after `cd` the operand missed
files sitting in the current directory, and `history -w` silently
created its file in the process cwd instead.

Route both faces through the one G-02 anchor: the new
executor::path::anchored_file_operand composes the spelling
translation with anchor_at_session_cwd (the lookup/cd anchor, now
pub(crate)); bind -f and its $include reads (lib/readline/bind.c:1502
parser_include) and the history -a/-n/-r/-w opens use the anchored
form. Diagnostics keep the as-typed spelling, and the empty operand
passes through so its open keeps GNU's ENOENT shape.

The host-provider history face in job_builtins.rs is NOT touched:
that file is in PR #2968's table (in flight) — see the lane REPORT
for the residual.

This PR deletes nothing: no code removed; the change is +52/-7
across path.rs, bind_builtins.rs and history_exec.rs, plus the
196-line regression pin in the preceding commit.
# Conflicts:
#	src/executor/history_exec.rs
@caomengxuan666
caomengxuan666 marked this pull request as ready for review November 18, 2026 08:30
@caomengxuan666
caomengxuan666 merged commit 3128859 into master Nov 18, 2026
10 of 12 checks passed
@caomengxuan666
caomengxuan666 deleted the fix/3090-relative-operand-session-cwd branch November 18, 2026 08:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant