Repository navigation
fix(cd): share the deleted-cwd dot-only move between -L and -P, trust stored logical cwd - #3386
Conversation
… stored logical cwd The issue's two title symptoms (cd . in a deleted cwd: pushd entry fails rc 1; cd entry lacks getcwd diagnostic and PWD /. suffix) were already fixed at HEAD by unixwin#2796's 20f9fb5 — reproducing them on f5f65d3 gives rc 0 + getcwd diagnostic + PWD /. on both entries, matching GNU 5.3.20. Digging the same mechanism family found three live residuals, fixed here by mechanism, not per case: 1. -P has no dot-only arm (src/builtins/cd.rs): 'cd -P .' / 'cd -P ./' fell into the anchor fallback, silently binding the physical path with no diagnostic. The Logical branch's dot-only arm is now a shared deleted_dot_move closure used by both modes, with the physical cwd as the make_absolute base under -P (GNU under -P binds the physical spelling; probe confirms a symlink entry binds $D/a/real/.) and the logical base under -L, both checked before the anchor fallback. 2. Logical spelling lost in a deleted cwd (old_logical derivation): logical_value_names_cwd and validated_logical_pwd both require a successful canonicalize, which always fails in a deleted cwd, so the code fell back to the physical cwd and a symlink entry's 'cd .' bound $D/a/real/. instead of GNU's $D/link/.. Now, when the cwd itself fails to canonicalize, the stored logical_cwd is trusted (it cannot be falsified in a deleted cwd; GNU's tcwd is exactly the stored string, common.c:589). 3. pushd/popd do not maintain session cwd state (execute_stack_builtin): pushd never wrote logical_cwd and never warmed the cwd inode anchor, so 'cd ..' / 'cd -P ..' / 'cd -P .' from a pushd entry in a deleted cwd failed rc 1. On a successful move (status 0 and cwd changed) the funnel now sets logical_cwd to the bound PWD and refreshes the anchor — the same maintenance execute_cd does; -n and dirs do not move the cwd, so the gate skips them automatically. GNU: change_to_directory verbatim-chdirs newdir when canon fails, and under -P the verbatim chdir is the first attempt (cd.def:522); dot-only operands succeed on the cwd inode, resetpwd('cd') emits the getcwd diagnostic (cd.def:183), set_working_directory(tdir) binds the uncanonicalized make_absolute form, giving PWD its /. suffix; get_working_directory prints '{caller}: error retrieving current directory: getcwd: cannot access parent directories: {strerror}' (common.c:592); tcwd is a stored string never revalidated against the filesystem (common.c:589); pushd's Dir operand goes through cd_builtin (pushd.def:296-302), so pushd is a cd-family mover and must maintain the same session cwd state. Refs unixwin#3335 Regression pin tests/issue3335_cd_dot_deleted_cwd.rs (15 tests; fail-first 7 passed / 8 failed on the unpatched tree, 15/15 pass after; supervisor verified both rounds with the patch method). The 8 red cells are exactly the three residuals: cd -P ., cd -P ./, symlink -P ., symlink cd . (logical spelling), pushd-symlink cd ., pushd-entry cd .., cd -P .., cd -P .; the 7 green cells lock the already-fixed title symptoms and controls. Two GNU probe matrices (cd ./, ./., -L, -P, both symlink entries, pushd-entry ../-P ../-P ., controls) are byte-identical with GNU 5.3.20 after the fix. Adjacent: unixwin#2796 12/12, unixwin#2797 7/7, unixwin#2798 5/5, unixwin#2799 7/7, unixwin#2143 8/8, unixwin#3268 cd-redirect 19/19, unixwin#3268 birth 12/12, unixwin#3198 7/7, unixwin#3275 4/4, unixwin#2391 6/6, unixwin#2408 4/4, unixwin#3196 6/6, unixwin#3197 3/3, unixwin#2937 24/24, unixwin#2220 9/9, unixwin#1415 1/1, unixwin#392 2/2 (supervisor re-ran unixwin#2796, issue3198, unixwin#2937). cargo fmt clean.
|
Thanks for the PR. This is queued for captain review — collaborator PRs are reviewed by the captain before merge, and #3335 stays open until that review lands. CI at intake: all 10 checks green (1 skipping). First pass: the honest correction in the body is noted (the two title symptoms were already fixed at HEAD by #2796) — the PR fixes the three live residuals by mechanism, pin 15/15 fail-first (7 passed / 8 failed on the unpatched tree, exactly the 8 residual cells). Two things noted for the captain: your Owed items (relative-path redirect creation in a deleted cwd; the |
Captain review — PASS (merge conditions below)Joint review with PR #3384 (same funnel, one dossier: Declaration reconciliation — every claim checks out, including the honest note
Two things the merge round must know
Owed items — captain delimitation (evidence in the dossier)
Merge conditions: final head CI finished all-green (the current head already is); if this PR merges second, the union protocol above applies. |
# Conflicts: # src/executor/trap_stack_builtins.rs
Fixes #3335
What was fixed
Honest note first: the issue's two title symptoms (
cd .in a deleted cwd — pushd entry fails rc 1; cd entry lacks the getcwd diagnostic and the PWD/.suffix) were already fixed at HEAD by #2796's20f9fb5— reproducing them onf5f65d3gives rc 0 + getcwd diagnostic + PWD/.on both entries, matching GNU 5.3.20. Digging the same mechanism family found three live residuals, fixed here by mechanism, not per case:-Phas no dot-only arm (src/builtins/cd.rs):cd -P ./cd -P ./fell into the anchor fallback, silently binding the physical path with no diagnostic. The Logical branch's dot-only arm is now a shareddeleted_dot_moveclosure used by both modes, with the physical cwd as themake_absolutebase under-P(GNU under-Pbinds the physical spelling; probe confirms a symlink entry binds$D/a/real/.) and the logical base under-L, both checked before the anchor fallback.old_logicalderivation):logical_value_names_cwdandvalidated_logical_pwdboth require a successful canonicalize, which always fails in a deleted cwd, so the code fell back to the physical cwd and a symlink entry'scd .bound$D/a/real/.instead of GNU's$D/link/.. Now, when the cwd itself fails to canonicalize, the storedlogical_cwdis trusted (it cannot be falsified in a deleted cwd; GNU's tcwd is exactly the stored string,common.c:589).execute_stack_builtin): pushd never wrotelogical_cwdand never warmed the cwd inode anchor, socd ../cd -P ../cd -P .from a pushd entry in a deleted cwd failed rc 1. On a successful move (status 0 and cwd changed) the funnel now setslogical_cwdto the bound PWD and refreshes the anchor — the same maintenanceexecute_cddoes;-nanddirsdo not move the cwd, so the gate skips them automatically.GNU:
change_to_directoryverbatim-chdirsnewdirwhen canon fails, and under-Pthe verbatim chdir is the first attempt (builtins/cd.def:522); dot-only operands succeed on the cwd inode,resetpwd("cd")emits the getcwd diagnostic (cd.def:183),set_working_directory(tdir)binds the uncanonicalizedmake_absoluteform, giving PWD its/.suffix;get_working_directoryprints{caller}: error retrieving current directory: getcwd: cannot access parent directories: {strerror}(builtins/common.c:592); tcwd is a stored string never revalidated against the filesystem (common.c:589); pushd's Dir operand goes throughcd_builtin(builtins/pushd.def:296-302), so pushd is a cd-family mover and must maintain the same session cwd state.Merge note: this PR touches
execute_stack_builtininsrc/executor/trap_stack_builtins.rs, the same function #3336 (PR #3384) touches — different hunks (lines ~497 vs ~511 on the base), so git should merge them, but the captain should review the combined function since both change what the funnel maintains on a move.What was deleted
Nothing. No files, features, or tests were removed.
Verification (all run, per-item counts)
tests/issue3335_cd_dot_deleted_cwd.rs: 15/15 pass. Fail-first on the unpatched tree (supervisor re-ran with the patch method): 7 passed / 8 failed — the 8 red cells are exactly the three residuals (cd -P .,cd -P ./, symlink-P ., symlinkcd .logical spelling, pushd-symlinkcd ., pushd-entrycd ..,cd -P ..,cd -P .); the 7 green cells lock the already-fixed title symptoms and controls. Expectations are all from GNU 5.3.20 measurements.cd ./,./.,-L,-P, both symlink entries, pushd-entry../-P ../-P ., controls): byte-identical with GNU 5.3.20 after the fix (only tmpdir name and shell path normalized away)...按物理路径解析,默认与 -L 下均偏离逻辑目录 #2796 12/12, [bug] pwd -L 照印 $PWD 变量原文,不做逻辑目录规范化 #2797 7/7, [bug] pwd -P 在 cwd 已删时不报 getcwd 错,静默印陈旧目录且 rc 0 #2798 5/5, [bug] 子壳启动丢弃继承的逻辑 PWD,重置为物理路径 #2799 7/7, [bug] 逻辑 PWD 未校验是否指代当前目录:伪造/陈旧 $PWD 被 pwd/cd 盲信 #2143 8/8, 已删 cwd 下进程内路径串解析同族残差:comsub 内 cat、cd ..、壳侧输入重定向、模拟 cp 操作数面 #3268 cd-redirect 19/19, 已删 cwd 下进程内路径串解析同族残差:comsub 内 cat、cd ..、壳侧输入重定向、模拟 cp 操作数面 #3268 birth 12/12, 已删 cwd 下前台外部命令 spawn 全部 rc 127(spawn 按陈旧逻辑 cwd chdir) #3198 7/7, 删后原地重建目录的幽灵穿越:静止会话经复活路径读到新目录内容(GNU 仍坐死 inode 报 ENOENT) #3275 4/4, [bug] pushd 建栈后 cd 不更新 DIRSTACK[0](dirs 栈顶仍为旧 cwd) #2391 6/6, [bug] 伪造 $PWD 后 DIRSTACK 顶跟随变量而非物理 cwd(GNU 经 get_working_directory 校验 $PWD) #2408 4/4, pushd 不查 CDPATH(cd 同形正常) #3196 6/6, pushd // 被归一化成 /(dirs 顶与 PWD 均错) #3197 3/3, dirs/pushd/popd: option loop stops at the first index word; rotation and '-n' mishandled #2937 24/24, comsub 快捷路径 pwd 逻辑拼写渲染成物理路径(symlink 与双斜杠根分歧) #2220 9/9, [bug] UNC 工作目录下 $PWD / pwd -L 丢掉一个前导斜杠:$PWD 不再是可解析路径,cd "$PWD" 失败(pwd -P / realpath 正确) #1415 1/1, cd with cdable_vars does not update $PWD (and sets $OLDPWD in the Windows path domain) #392 2/2 (supervisor re-ran [bug] cd 对软链父目录的..按物理路径解析,默认与 -L 下均偏离逻辑目录 #2796, issue3198, dirs/pushd/popd: option loop stops at the first index word; rotation and '-n' mishandled #2937).#844_848and#896arecfg(windows)— 0 tests on Linux.cargo build -j 2clean,cargo fmt --checkclean.src/lexer/continuation.rsuntouched. Supervisor re-checked the collision: [bug] cd . in a deleted cwd: pushd entry still fails rc 1; cd entry lacks getcwd diagnostic and PWD /. suffix #3335 is open, assigned to Uarz, 0 open PRs referencing it.Owed
cd "$PWD" 2>err.txt(relative path) reportserr.txt: No such file or directoryin rubash; GNU creates the file through the cwd inode. This is an independent redirect-creation divergence, not part of [bug] cd . in a deleted cwd: pushd entry still fails rc 1; cd entry lacks getcwd diagnostic and PWD /. suffix #3335's cd face; the pin's control cells therefore assert the diagnostic tail with absolute paths. Suggest a separate issue.bindpwd-readonly edge: with PWD/OLDPWD readonly, GNU's chdir still succeeds and tcwd is updated; this change's maintenance gate is on status == 0, so that edge still leaves stale state. Fixing it needs the logical value from the stack top rather than env PWD; left for a follow-up.