Repository navigation
perf(winuxcmd): find the installation from any entry point, and inject its real root - #393
Merged
Merged
Conversation
caomengxuan666
force-pushed
the
perf/winuxcmd-discovery-ancestors
branch
from
October 17, 2026 03:37
eedbbf3 to
1818a9e
Compare
…t its real root
The discovery search only looked beside the running executable. That was
enough while `niu.exe` always lived in the installation root, but the shell is
about to be reachable as a hardlink named `bash.exe`/`sh.exe` in the PATH entry
directories (`<root>\bin`, and for agents and editors one or two levels
beside the installation). From those, nothing beside the executable is a
WinuxCmd tree, so discovery failed, PATH injection never happened and every
coreutil disappeared inside that shell - the hidden blocker behind niubash#377.
- `bundled_winuxcmd_candidates` now walks up to six ancestor levels from the
executable, keeping the existing relative shapes first and adding
`<base>\bin\winuxcmd.exe` (the PATH entry link wpm creates).
- Each candidate carries the installation root its shape implies instead of
re-deriving it later from the path. That fixes a real bug on the current
layout: from `<root>\bin\bash.exe` the sibling candidate `<root>\bin\
winuxcmd.exe` matched, and `installation_root` then reported `bin` as the
root, which injected only `bin` into PATH. `<root>\bin\winuxcmd.exe`,
`<root>\usr\bin\winuxcmd.exe` and `<root>\winuxcmd.exe` all imply `<root>`;
`<x>\winuxcmd\usr\bin\winuxcmd.exe` implies `<x>\winuxcmd`.
- `injected_path_dirs(root, exe)` replaces the `ends_with("usr/bin")` test:
a tree whose executable sits below the root injects `usr/local/bin`,
`usr/bin`, `bin` and the root in POSIX order, while a portable layout that
keeps `winuxcmd.exe` beside its tools still injects only that directory.
- The install root is resolved once and threaded through prepare/ensure instead
of being recomputed from the path.
Tests: 18/18 in `winuxcmd::tests` (16 existing, no regressions; two new ones
cover the ancestor walk with implied roots and the injected directory set for
the canonical location, the PATH entry link and a payload deeper in the tree).
caomengxuan666
force-pushed
the
perf/winuxcmd-discovery-ancestors
branch
from
October 17, 2026 03:43
1818a9e to
96a7a52
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The hidden blocker behind #377, found while planning the
bash.exe/sh.exehardlink and fixed on its own so it can land independently.Why this is needed
Discovery today only looks beside the running executable (
crates/niubash-runtime/src/winuxcmd.rs). That worked whileniu.exealways sat in the installation root. The moment the shell is reachable as a hardlink namedbash.exe/sh.exein the PATH entry directories —<root>\bin(where wpm puts the entry links), and for agents/editors one or two levels beside the installation (…\Niubash\bin,…\winuxcmd\opt\niugit\bin) — nothing beside that executable is a WinuxCmd tree, so discovery fails, PATH injection never runs and every coreutil disappears inside that shell. That is why "just hardlink it" breaks, and why the shim exists.What changes
bundled_winuxcmd_candidateswalks up to six ancestor levels, keeping the existing relative shapes first and adding<base>\bin\winuxcmd.exe(the PATH entry link wpm creates).<root>\bin\bash.exethe sibling candidate<root>\bin\winuxcmd.exematches (wpm creates it for the winuxcmd package), andinstallation_rootthen reportedbinas the root, injecting onlybinintoPATH.<root>\usr\bin\winuxcmd.exe,<root>\winuxcmd.exe,<root>\bin\winuxcmd.exe⇒<root><x>\winuxcmd\usr\bin\winuxcmd.exe⇒<x>\winuxcmdinjected_path_dirs(root, exe)replaces theexe_dir.ends_with("usr/bin")test: a tree whose executable sits below the root injectsusr/local/bin,usr/bin,binand the root in POSIX order; a portable layout that keepswinuxcmd.exebeside its tools still injects only that directory.prepare_winuxcmd_with_override/ensure_on_path_with_override, instead of being recomputed from the path in three places.Verification
cargo test -p niubash-runtime --lib winuxcmd::tests→ 18/18 (16 pre-existing tests unchanged, no regressions). The two new ones:bundled_candidates_climb_to_ancestor_installations— from<root>\bin, from a payload at<root>\winuxcmd\opt\niugit\bin, and from<x>\bin(the niubash layout), the candidate that matches is the canonicalusr\bin\winuxcmd.exeand its implied root is the tree, notbin.injected_path_dirs_cover_the_installation_root— the canonical location, the PATH entry link and a package copy deeper in the tree all inject the same four directories; the portable layout injects only its own.No behaviour change for any layout that works today (the relative shapes stay first, and the
usr/bincase still injects the same four directories).Next steps (not in this PR)
With discovery fixed, the shim can be replaced by a hardlink to
niu.exeforbash.exe/sh.exe; the remaining pieces are the packaging change plus re-linking after an update replacesniu.exe(the same maintenance stepwpm links rebuildperforms for package links).