Repository navigation
fix(wpm): make package upgrades survive live processes, and manage the PATH entry links - #1192
Merged
Merged
Conversation
caomengxuan666
force-pushed
the
fix/wpm-install-robustness
branch
2 times, most recently
from
October 16, 2026 09:35
5b3d646 to
0594655
Compare
…rom the payload, link package commands for PATH Three install-path defects, each reproduced on a real machine. 1. Upgrades could not replace a payload file held by a running process. Measured: a name held by another process denies CreateFileW(DELETE), DeleteFileW and overwrite alike (Access denied), so the old copy-then-fail path aborted *half-applied* - payload directories on the new version, the PATH entry still on the old one (observed live: opt on 2.56.0.1, PATH on 2.55.0). wpm now preflights every destination before touching anything and refuses with the culprit listed (plus the process running from it, via a toolhelp scan), which keeps the install all-or-nothing; the actual replacement uses a POSIX unlink first for the cases that do allow delete sharing. Verified in a sandbox: installer refuses, payload untouched (`payload untouched: True`), and the same command succeeds once the holder is gone. 2. File mappings were hardlinked out of the extraction directory. In the flat layout the artifact maps both `mingw64/` and `mingw64/bin/git.exe`, so the second mapping linked `.wpm/staging/...` into `usr/bin/git.exe` while the directory mapping copied a separate inode to `opt/niugit/...`: two payloads on disk, the PATH entry tied to a transient directory, the manifest payload unreferenced (#1188). File mappings now source from the materialized payload, and the staging tree is pruned after a successful install. Verified: `usr/bin/git.exe` and `opt/niugit/mingw64/bin/git.exe` are the same inode, `.wpm/staging/niugit` is gone. 3. Package commands had no link in the host's PATH directory. `<root>/bin` is what the installer puts on PATH (`usr/bin` stays off it - hundreds of tools would leak into GUI processes), and editors resolve git through PATH. wpm now creates `<root>/bin/<cmd>.exe` as a hardlink to the payload binary (never a launcher: 12.7 ms vs 32.2 ms forwarding), records it in the receipt, covers it in the reconcile so an update cannot delete it, and removes it on uninstall (unixwin/niubash#376 rule 5). Verified: the install reports `wpm: linked ...\\bin\\git.exe`.
caomengxuan666
force-pushed
the
fix/wpm-install-robustness
branch
from
October 16, 2026 09:44
0594655 to
5add0d5
Compare
…yload copy User-facing counterparts of the install-path fixes: - the layout tree and the install guide now describe <root>/bin/<cmd>.exe as a hardlink to the real binary and how it is kept in sync; - an install that cannot replace a held file now refuses before writing anything and names the programs to close - the guide says so, so the message is not a surprise; - the package-authoring fields explain that a repackaged artifact needs a Debian-style revision to be offered as an update, and that sha256/size/files must describe the published artifact exactly; - a file mapping that duplicates a directory mapping shares the payload inode instead of copying the file twice.
This was referenced Oct 17, 2026
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.
Three install-path defects, each reproduced on a real machine, plus the test that pinned the old (wrong) behaviour.
1. An upgrade could not replace a payload file held by a live process — and aborted half-applied
On the live machine:
git's
fsmonitor--daemonruns from exactly that file while any monitored repository keeps it alive. The upgrade stopped mid-way:opt/niugiton 2.56.0.1,usr/bin/git.exestill on 2.55.0. Worse, the payload on disk could be a mixture, because files are not a transaction.My first attempt (POSIX unlink before copy) turned out to be insufficient, and the measurement is the interesting part:
SetFileInformationByHandleFILE_DISPOSITION)Only the package's own running image can be unlinked (that is why the
wpm update winuxcmdself-lock fix works). A file held by another process cannot be removed or replaced by any mechanism short of terminating that process.So the fix is a preflight, not a cleverer copy:
CreateFileW(DELETE, FILE_SHARE_READ|WRITE|DELETE);QueryFullProcessImageNameW, the process running from it) and refuses, leaving the installation exactly as it was;Sandbox reproduction (
share=Nonehandle on the payload'slibexec/git-core/git.exe, theninstall --force):All-or-nothing, and the user is told what to close. The test
wpm_install_force_locked_destination_fails_loudly(#1156) now asserts the new contract — refusal names the file, nothing is installed — instead of the old "copy, then fail".2. File mappings were hardlinked out of
.wpm/staging(#1188)In the flat layout the artifact maps both
mingw64/andmingw64/bin/git.exe, so the file mapping linked the extraction directory's copy intousr/bin/git.exewhile the directory mapping copied a separate inode toopt/niugit/…. Two full payloads on disk, the PATH entry tied to a transient directory, the manifest's payload unreferenced.File mappings now source from the materialized payload (
payload_source_for), and.wpm/staging/<pkg>is pruned after a successful install. Verified in the sandbox:usr/bin/git.exeandopt/niugit/mingw64/bin/git.exeare the same inode, staging is gone.3. Package commands had no link in the entry directory (unixwin/niubash#376 rule 5)
%PATH%receives a directory of links from two places: the standalone WinuxCmd setup adds<root>\usr\bin(verified inpackaging/winuxcmd.iss; flat payloads and shim dispatchers already land there, so those resolve), and the niubash layout has<root>\binon PATH — which had nothing of a package's own in it, while editors and language servers resolvegitthrough PATH as well.wpm now creates
<root>/bin/<cmd>.exefor every command of a package as a hardlink to the real binary — the payload underopt/<pkg>/for shim packages, the mapped binary inusr/bin/for flat ones — never a launcher (12.7 ms as a real binary vs 32.2 ms behind a forwarding process), records it in the receipt'sdestinations, covers it in the reconcile so an update cannot delete it, and removes it on uninstall. Verified: the install reportswpm: linked …\bin\git.exe.Verification
tailtiming test flaked once under load and passes).--rootsandbox, index pointed at niugit 2.56.0.1): fresh install creates the entry link; a held payload makes the forced upgrade refuse with the file named and no mutation; once the holder is gone the same command succeeds withusr/bin/git.exe== payload inode and staging pruned.wpm update winuxcmd1.1.9 → 1.1.11 through the unlink+rename path,install niugit --forceonto 2.56.0.1, gawk's legacy flat residue cleaned, openssh migrated flat → shim withusr/bincarrying zero DLLs.Docs
CHANGELOG.mdgains an[Unreleased]section andDOCS/en/wpm_guide.mddocuments the entry links, the refusal, the packaging-revision rule and the payload-copy behaviour (commit7f8df2bin this PR). The agent-facing counterpart is #1191.