Skip to content

fix(wpm): make package upgrades survive live processes, and manage the PATH entry links - #1192

Merged
caomengxuan666 merged 2 commits into
mainfrom
fix/wpm-install-robustness
Oct 16, 2026
Merged

caomengxuan666 merged 2 commits into
mainfrom
fix/wpm-install-robustness

Conversation

@caomengxuan666

@caomengxuan666 caomengxuan666 commented Oct 16, 2026 •

Copy link
Copy Markdown
Member

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:

wpm: failed to copy '…\opt/niugit/mingw64\libexec\git-core\git.exe': The process
cannot access the file because it is being used by another process.

git's fsmonitor--daemon runs from exactly that file while any monitored repository keeps it alive. The upgrade stopped mid-way: opt/niugit on 2.56.0.1, usr/bin/git.exe still 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:

holder DeleteFileW POSIX unlink (SetFileInformationByHandle FILE_DISPOSITION) overwrite
a foreign process's image (git daemon) Access denied Access denied (5) Access denied

Only the package's own running image can be unlinked (that is why the wpm update winuxcmd self-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:

  • before any mutation, every destination the artifact would replace is probed with CreateFileW(DELETE, FILE_SHARE_READ|WRITE|DELETE);
  • if any name is not replaceable, wpm lists it (and, via a toolhelp scan of QueryFullProcessImageNameW, the process running from it) and refuses, leaving the installation exactly as it was;
  • the actual replacement still unlinks first, which covers the handles that do allow delete sharing.

Sandbox reproduction (share=None handle on the payload's libexec/git-core/git.exe, then install --force):

wpm: 1 file(s) are in use and cannot be replaced; close the listed programs
(a running git, an editor's git integration, a fsmonitor daemon) and retry:
  …\opt/niugit/mingw64/libexec/git-core/git.exe
      (held by a process that cannot be named)
payload untouched: True

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/ and mingw64/bin/git.exe, so the file mapping linked the extraction directory's copy into usr/bin/git.exe while the directory mapping copied a separate inode to opt/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.exe and opt/niugit/mingw64/bin/git.exe are 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 in packaging/winuxcmd.iss; flat payloads and shim dispatchers already land there, so those resolve), and the niubash layout has <root>\bin on PATH — which had nothing of a package's own in it, while editors and language servers resolve git through PATH as well.

wpm now creates <root>/bin/<cmd>.exe for every command of a package as a hardlink to the real binary — the payload under opt/<pkg>/ for shim packages, the mapped binary in usr/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's destinations, covers it in the reconcile so an update cannot delete it, and removes it on uninstall. Verified: the install reports wpm: linked …\bin\git.exe.

Verification

  • Unit suite: 2846/2848 — the two failures are this machine's i18n locale-hint tests, identical before the change (the locked-destination test was updated to the new contract; a tail timing test flaked once under load and passes).
  • Sandbox (--root sandbox, 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 with usr/bin/git.exe == payload inode and staging pruned.
  • Live machine earlier today: wpm update winuxcmd 1.1.9 → 1.1.11 through the unlink+rename path, install niugit --force onto 2.56.0.1, gawk's legacy flat residue cleaned, openssh migrated flat → shim with usr/bin carrying zero DLLs.

Docs

CHANGELOG.md gains an [Unreleased] section and DOCS/en/wpm_guide.md documents the entry links, the refusal, the packaging-revision rule and the payload-copy behaviour (commit 7f8df2b in this PR). The agent-facing counterpart is #1191.

@caomengxuan666
caomengxuan666 force-pushed the fix/wpm-install-robustness branch 2 times, most recently from 5b3d646 to 0594655 Compare October 16, 2026 09:35
…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
caomengxuan666 force-pushed the fix/wpm-install-robustness branch from 0594655 to 5add0d5 Compare October 16, 2026 09:44
…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.
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.

1 participant