Skip to content

fix(binding): resolve mirrors through junctions and symlinks (#173) - #177

Merged
flymysql merged 2 commits into
mainfrom
fix/issue173-realpath-mirror
Nov 19, 2026
Merged

flymysql merged 2 commits into
mainfrom
fix/issue173-realpath-mirror

Conversation

@flymysql

Copy link
Copy Markdown
Owner

Fixes #173.

问题

resolveMirror() 把会话 cwd 与镜像根当纯字符串比前缀。path.resolve 是词法的,不解析 Junction/symlink:

  • 当 %USERPROFILE%\.dsh 是指向真实目录的 NTFS Junction 时,镜像根按 Junction 形式拼写,而会话 cwd 常以真实路径形式到达;
  • 两侧前缀天然不同 → 判定「不属于任何镜像」→ 会话被当作 LOCAL,rw_* 全部拒绝,只有 rw_connect / rw_pick_workspace 可用。

改动

  • 同时扫描注册根的字面与真实路径两种拼写;
  • Windows 上路径比较改为大小写不敏感(盘符大小写在不同 API 间不稳定);
  • 返回的 mirrorDir 会按 cwd 的拼写重新表达(spellLike),使下游路径映射两侧可比;
  • 没有 meta 的目录依旧绝不绑定(有专门用例守着)。

与 lib/workspace-cleanup.js 里既有的 realpathSync 做法保持一致。

测试

新增 3 条用例,真实创建 junction(Windows)/ 目录符号链接(POSIX),OS 拒绝时 skip 而非静默通过:

  1. cwd 真实拼写 + 注册根是 junction → 绑定成功,且 mirrorDir 用 cwd 拼写;
  2. cwd 经 junction 拼写 + 注册根字面拼写 → 绑定成功,mirrorDir 用链接拼写;
  3. 链接根下的非镜像目录 → 仍然 machine === null。

负对照:还原实现后,用例 1、2 失败(machine 为 null),修复后全绿——证明它们不是永远绿。

npm test → 1542 tests, 1519 pass, 0 fail, 23 skipped

`resolveMirror` compared the session cwd with the mirror root as raw
strings. `path.resolve` is purely lexical, so a cwd in the REAL spelling
never matched a registry root spelled through `%USERPROFILE%\.dsh`
(NTFS Junction) — the session was reported as LOCAL and every rw_* tool
refused it, even though the mirror and its meta were right there.

Scan both the literal and the real-path spelling of the registry root,
compare case-insensitively on Windows (drive-letter case is not stable),
and re-spell the reported mirrorDir the way the cwd spells it so
downstream path mapping compares like with like. Non-mirror directories
still never bind.

The three new cases create a real junction (Windows) / directory symlink
(POSIX) and SKIP when the OS refuses; two of them fail on the old code.
`spellLike` rebuilt the path from split segments, which dropped the leading
`/` on POSIX (`/tmp/x` came back as `tmp/x`) — Windows passed only because
the drive segment (`C:`) carried the root. Step up with `path.dirname`
instead, so `/`, `C:\` and UNC roots all survive.
@flymysql
flymysql merged commit 32dc89e into main Nov 19, 2026
19 of 34 checks passed
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.

[Bug] rw_* tools refuse a session whose cwd is the mirror reached through a junction/symlink ("this session is LOCAL")

1 participant