Repository navigation
fix(wpm): replace held payload files by parking them, not by refusing - #1194
Merged
Merged
Conversation
The 1.1.12 preflight asked "can I open this name with DELETE access?" before
writing anything. On Windows that probe answers *yes* for a file another
process has mapped as its image, while the operation that follows -
SetFileInformationByHandle(FILE_DISPOSITION_INFO), and an in-place overwrite -
fails with Access denied. Measured on a live install with git's fsmonitor
daemon holding libexec/git-core/git.exe:
CreateFileW(DELETE, share all) -> OK
SetFileInformationByHandle(unlink) -> Access denied (5)
rename the name aside -> OK
So the probe lied in exactly the case it existed for, and `wpm install niugit
--force` failed anyway ("failed to replace '...git.exe'") *after* the reconcile
and the entry links had run, leaving the package half-updated: opt/niugit on
2.56.0.1, usr/bin/git.exe still on the old inode, staging unpruned.
Replace the probe with the operation itself:
- before anything is written, every destination the artifact would replace is
renamed aside to `<name>.wpm-old-<pid>`; a rename is what a mapped image
allows, it leaves the running process on its old inode, and it is reversible;
- if any destination cannot even be renamed, everything already parked is
renamed back and the install refuses with the culprit and the processes
running from it - all-or-nothing, never half-updated;
- after the install commits, the parked names are deleted best-effort (while
the old process holds the bytes they stay), and `wpm clean [staging|all]` now
sweeps those leftovers;
- the reconcile parks a superseded path it cannot remove instead of aborting
the upgrade.
Verified live: 28 fsmonitor daemons holding opt/niugit/.../libexec/git-core
/git.exe, `install niugit --force` succeeds, usr/bin/git.exe and bin/git.exe
both share the payload inode (#1188), staging is pruned, and the old bytes are
parked. New regression test starts a process from the installed destination
and asserts the forced upgrade still completes.
caomengxuan666
added a commit
to unixwin/niubash
that referenced
this pull request
Oct 17, 2026
The shell has been reached through a 243 KB forwarding shim that sets `NIU_INVOKED_AS` and re-executes `niu.exe`, which costs one extra process on every `bash -c` / `sh -c` - measured at +12.8 ms per call, and the per-command tax AI agents, CI and git hooks pay constantly (#377). The same faces are free as hardlinks: the engine already selects `$0`, `BASH_VERSION` and the POSIX mode from `argv[0]`, and discovery now finds the installation from any entry point, so a name in `<root>\bin` is enough. - `niubash_runtime::shell_links` creates `bash.exe` and `sh.exe` as hardlinks to the running `niu.exe` in `<root>\bin`, `<root>\winuxcmd\bin` and `<root>\winuxcmd\usr\bin`, whichever of those exist. `find_installation_root` walks up to the directory that holds `niu.exe` next to the bundled winuxcmd tree, so the same root is found whether the shell was reached as `niu.exe`, as `<root>\bin\bash.exe` or from inside the winuxcmd tree. - It is idempotent, and an existing name that is not this `niu.exe` (the shipped shim, or a link left on the previous inode after an update replaced `niu.exe`) is kept unless `--force` is given. With `--force` the name is parked first, linked, and only then dropped - a shell running right now keeps its bytes (the technique from unixwin/WinuxCmd#1194). - Exposed as `niu --relink-shells [--force] [--quiet]`, and called from the installer's `[Run]` right after `wpm links rebuild`, so an update that replaces `niu.exe` refreshes the names instead of leaving them stale. - Hardlinks are created on the user's machine, never in the distribution: a zip would store the 12 MB payload once per name. Portable layouts and filesystems without hardlinks keep the shipped shim, which produces the same identity through `NIU_INVOKED_AS` - both paths stay supported. - `docs/src/installer.md` now documents that contract instead of forbidding the `argv[0]` route. Measured in a sandbox with six fake shims: `--relink-shells --force` replaced all six with links to `niu.exe` (no leftovers), a second run reports `0 created, 6 already current`, and `bash -c exit` costs the same as `niu.exe -c exit`. `sh` still selects POSIX mode and `bash` does not.
This was referenced Oct 17, 2026
Merged
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.
Follow-up to #1192, from watching it fail on a real machine.
What 1.1.12 got wrong
The preflight asked can I open this name with DELETE access? and treated yes as "replaceable". On Windows that probe answers yes for a file another process has mapped as its image, while the operation that follows fails. Measured live with git's
fsmonitor--daemonholdingopt/niugit/mingw64/libexec/git-core/git.exe:CreateFileW(DELETE, FILE_SHARE_READ|WRITE|DELETE)SetFileInformationByHandle(FILE_DISPOSITION_INFO)(POSIX unlink)MoveFileExW(name, <name>.wpm-old-…, 0)So the probe lied in exactly the case it existed for, and
wpm install niugit --forcefailed anyway — after the reconcile and the entry links had run, leaving the package half-updated:opt/niugiton 2.56.0.1,usr/bin/git.exestill on the old inode,.wpm/staging/niugitunpruned.The fix: park, then write
<name>.wpm-old-<pid>;wpm clean [staging|all]now sweeps those leftovers;Renaming is what makes this work on a running image: the process keeps its old inode, the name is free for the new bytes, and nothing is lost if the install stops.
Evidence
Live machine, before the fix:
after, with 28 fsmonitor daemons holding that exact file:
Tests: 2847/2849 (the two failures are this machine's i18n locale-hint fixtures, unchanged), including a new
wpm_install_replaces_a_destination_a_process_runs_fromthat starts a process from the installed destination and asserts the forced upgrade completes. The locked-destination refusal test from #1156 still passes: a file held without share-delete cannot even be renamed, so the refusal path is exercised by the same message.Note for the docs
wpm cleannow also removes.wpm-old-<pid>names; the 1.1.13 entry should say so, and the machine-level observation that the fsmonitor daemons accumulate (28 of them) is worth its own issue.