Skip to content

path model: cd ~ uses the startup HOME; mkdir succeeds where cd then fails at ~260 chars; pwd and realpath disagree on spelling #754

Closed

Description

@caomengxuan666

Summary

Three path-model divergences from GNU, all verified. Taxonomy family S10 ("Windows 进程/路径", ~104 commits), the same area the project's own ledger already tracks.

Verified with LF script files; niu (installed 1.4.0) vs WSL GNU bash 5.3.0; stdout/stderr captured separately. A first attempt at item 2 was invalid on my side (I generated the long path with python, which WSL does not have) — re-run below without it.


1. cd ~ uses the HOME captured at startup, not the current $HOME

mkdir -p newhome
HOME="$PWD/newhome"; cd ~; echo "$PWD"
result
GNU bash …/newhome — the current $HOME
niu / rubash /c/Users/cmx — the value at startup

So a script that changes HOME and then cd ~ lands somewhere else. (Same sweep reports that command cd ~ resolves correctly, i.e. it is the bare builtin path that keeps the stale capture.)

2. mkdir succeeds on a path that cd then refuses — niu can create a directory it cannot enter

for n in 180 220 240 260; do
  P="$PWD/$(printf 'a%.0s' $(seq 1 $n))"
  mkdir -p "$P"; echo "mkdir=$?  test-d=$([ -d "$P" ] && echo yes || echo no)  cd=$((cd "$P") 2>/dev/null; echo $?)"
done
total path length mkdir test -d cd — niu cd — GNU
225 0 yes 0 0
265 0 yes 1 (File name too long) 0
285 0 yes 1 (File name too long) 0
305 1 (Invalid argument) no 1 1

GNU's cd works up to ~289. niu's fails from somewhere between 225 and 265 — below the length at which Windows itself refuses to create the directory. So the two operations disagree about the same path, which is the "N paths, separately patched" pattern from S3/S10 rather than one length policy.

3. pwd and realpath disagree on the spelling of the same directory

[ "$(pwd)" = "$(realpath .)" ] && echo equal || echo differ
pwd realpath . equal?
GNU bash /mnt/c/… /mnt/c/… yes
niu / rubash /c/… C:\… NO

Any [ "$(pwd)" = "$(realpath …)" ] or case $PWD in $(realpath …) idiom therefore silently fails. (~/$HOME uses yet a third spelling, C:/….) This is the same family as the boundary-table work in niubash#384 and the PWD-form policy in rubash#537.

Not included

Four more items from the same sweep are not re-checked by me and are not part of this issue: pwd -P at / reporting the winuxcmd root; pwd -P vs pwd -L disagreeing after cd /mnt/c/…; ~root / ~nobody staying literal; and ls -d c:foo succeeding on a drive-relative path that [ -e ] and native children refuse.

Method

As above; each case in a fresh directory (a previous sweep retracted two of its own glob/path diffs as run-order pollution, so isolation was enforced here).

Activity

  1. added
    bug
    P2-medium
    area:path
    on Oct 17, 2026
  2. caomengxuan666 commented on Oct 17, 2026

    @caomengxuan666
    MemberAuthor

    One more from the same family as this issue, and it is a script's own positional parameters rather than a native child's:

    printf 'echo "arg1=[$1]"\n' > argv.sh
    niu argv.sh /c/Users/x/repo        # $1 arrives as  C:\Users\x\repo
    niu argv.sh C:/Users/x/repo        # $1 arrives as  C:/Users/x/repo
    bash argv.sh /mnt/c/Users/x/repo   # $1 arrives as  /mnt/c/Users/x/repo
    invocation what the script sees in $1
    niu argv.sh /c/… C:\…
    niu argv.sh C:/… C:/…
    bash argv.sh /mnt/c/… /mnt/c/…

    The translation is consistent with the documented rule ("every other child … always receives native Windows paths" — the child here being niu re-invoking itself), so this may be intended. Filing it against the path model because the recipient is the shell's own $1..$n, where a script author expects what they typed. It is also how I lost a whole probe run: a script that did cd "$1" followed by relative file work landed in a different place than the caller intended, with no diagnostic.

    If it is intended, the path contract could say so explicitly for the script-argument case (as it already does for native children), since scripts are the one place a user is most likely to assume verbatim.

    Environment: Niubash 1.4.0 (rubash git e785c3c8f610), Windows 10 x64 (build 19045); GNU bash 5.3.0 via WSL; arguments passed to a plain .sh file run as a script.

  3. caomengxuan666 commented on Oct 17, 2026

    @caomengxuan666
    MemberAuthor

    Duplicate-sweep note: this is residue of the closed path family #329 / #331 / #592 / #537 / #566 / #224

    Sweeping the tracker for closed predecessors: the path-model half of this issue belongs to a family that has already been closed six times from six entry points —

    closed entry point
    #329 → #331 env-inherited POSIX paths re-rendered to D:/ drive form; self-produced path values unify to POSIX
    #592 POSIX absolute-path operand translation drifts by execution context
    #537 PWD drive form makes nvm_find_up spin
    #566 cd /c (bare drive-root POSIX form) ENOENT when root is configured
    #224 $0/BASH_SOURCE rewritten for a script invoked by an absolute /d/ path

    Each closed fix covered its entry point; this issue reports the same contract failing from cd ~ (startup vs current HOME) and from cd into a >260-char path. That is residue of the family, not a seventh independent bug.

    The ~260-char mkdir-succeeds-but-cd-fails item does look new (no closed predecessor found: CreateDirectory and SetCurrentDirectory disagree on long paths). If you want, I can split that out so the residue discussion does not bury it.

  4. caomengxuan666 commented on Oct 18, 2026

    @caomengxuan666
    MemberAuthor

    由 #819 修复落地(合并):HOME 基准统一为 GNU 活 cell 语义(空值=真值、缺失才回退)、裸 cd/pushd/popd 空词规则、comsub 快路委托内建消除漂移、20+8 用例 GNU 差分全对齐。CR 两轮(第二轮 APPROVE-WITH-NITS)。法证疑点(安装位 vs 源码构建行为不符)移交 #827(P1 发行完整性)跟踪。相邻新发现(popd 默认弹出不 chdir)另立 #830。

  5. caomengxuan666 commented on Oct 23, 2026

    @caomengxuan666
    MemberAuthor

    在装的 1.4.4(rubash git fa64d58dfb9c,2026-10-22 构建,已包含 ce6e16d / PR #819)上,这条的两条都仍可复现。

    1. cd ~ 仍用启动时的 HOME,而裸 cd 用当前 $HOME

    cd /d/probe-20261023/r7/e3
    mkdir -p newhome; HOME="$PWD/newhome"
    cd ~;  echo "cdtilde=$PWD"    # 实测 /c/Users/cmx                      (启动时 HOME)
    cd;    echo "barecd=$PWD"     # 实测 /d/probe-20261023/r7/e3/newhome  (当前 HOME)
    echo "HOME=$HOME"

    GNU bash 两行都给 …/newhome。修完之后裸 cd 对了、cd ~ 还是旧基线 —— 同一操作内两个 HOME 基线并存。

    2. cd 拒绝长路径,而同路径的 [ -d ] / 写入 / cat / ls 都正常(边界已收敛到 258/259)

    BASE="D:/probe-20261023/r7/e3/lt"
    for T in 258 259; do
      n=$((T-27)); p="$BASE/$(printf c%.0s $(seq 1 $n))"
      printf "len=%s " "${#p}"
      [ -d "$p" ] && printf "testd=Y " || printf "testd=N "
      (cd "$p") 2>/dev/null && printf "cd=OK " || printf "cd=FAIL "
      echo x > "$p/w.txt" && printf "wr=Y "
      cat "$p/w.txt" >/dev/null && printf "cat=Y"
      echo; rm -f "$p/w.txt"
    done

    实测:

    len=258 testd=Y cd=OK   wr=Y cat=Y
    len=259 testd=Y cd=FAIL wr=Y cat=Y      # stderr: cd: D:/…: File name too long
    len=269 testd=Y cd=FAIL wr=Y cat=Y ls=Y # 同一路径写入/读取/列目录全成功
    

    即阈值正好落在 MAX_PATH(258 通过、259 起失败),而其余路径操作走长路径通道、269 也能读写。

    上游状态

    本机 D:/repo/rubash HEAD(ef271973)比安装构建新 230 个提交;git log fa64d58dfb9c..HEAD --grep=HOME|tilde|cd 只命中 dirs 的 ~ 缩写显示与 rc 加载,没有触碰 cd 长度检查或 HOME 基线的提交,所以两条都不是「已修未发布」。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2-mediumarea:pathbug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions