Skip to content

fix(wpm): name the command link a rebuild cannot replace, and park it instead of giving up - #1209

Merged
caomengxuan666 merged 2 commits into
mainfrom
fix/relink-diagnostics
Oct 17, 2026
Merged

caomengxuan666 merged 2 commits into
mainfrom
fix/relink-diagnostics

Conversation

@caomengxuan666

@caomengxuan666 caomengxuan666 commented Oct 17, 2026 •

Copy link
Copy Markdown
Member

Part of #1206 (the naming/diagnosis half; the helper log and the post-swap verification stay in the issue).

Why

A command link left on the previous winuxcmd.exe (observed as usr\bin\yes.exe on a live install, hours after an update) is counted in the summary but never named, and remove_link_if_safe gives up on it without trying anything else. So an installation can be running two different winuxcmd builds, one command at a time, and nothing says so.

What changes

  • Park, then link. A name that cannot be deleted is renamed aside and the link is created over the freed name — the same move a package upgrade makes for a held payload file (fix(wpm): replace held payload files by parking them, not by refusing #1194). If the link fails, the parked name is renamed back, so nothing is lost.
  • Name the failure. When even the rename is refused, wpm prints which link it could not replace, plus what that means ('…' still points at the previous winuxcmd.exe) instead of leaving a bare failed=1 in the summary.
  • Document the asynchronous update. wpm update winuxcmd returns before the swap: the detached helper waits for the updating process to exit (up to 30 s) and only then replaces the image and relinks. Auditing versions or links immediately after the command returns can legitimately show the previous build — that window cost real time during this investigation, so §4.3 of the guide now says it, and points at wpm links rebuild --force, which recreates the links from the installed image at any time.

Verification

New test wpm.links_rebuild_names_a_link_it_cannot_replace: a stale yes.exe is held without FILE_SHARE_DELETE, so neither delete nor rename is possible; the test asserts a non-zero exit, the named message, and that every other name still resolves to the current image while the held one does not.

wpm.* → 59 passed, 0 failed (the full filter).

Also in this PR (second commit)

  • The detached helper now has a log. Its stdout/stderr were discarded, so a failure inside apply_update produced no output anywhere. It writes to <root>\.wpm\logs\self-update-<stamp>-<pid>.log, the newest three are kept, and the "update staged" message names the file.
  • The links are verified after the swap. finish_update rebuilds them, re-reads the family, retries once, and reports the names that still point at the previous image — previously a partial relink exited 0.
  • wpm links verify reports by path every command link that does not run the installed winuxcmd.exe; wpm links rebuild --force (already there) replaces them.

Test: wpm.links_verify_names_stale_command_links (a clean installation verifies clean; a name pointed at another image is reported by path). wpm.* 60/60; full suite 2897/2899 with the two known machine-local i18n failures.

Not in this PR

  • The strengthening of the activation spot-check (has_required_command_links compares existence, not identity) is a niubash-side follow-up.

… instead of giving up

A stale command link - one left on the previous winuxcmd.exe by an update - is
counted as a failure but never named, and `remove_link_if_safe` gives up on it
without trying anything else, so the installation keeps running the older image
for that one command and says nothing (#1206, observed as
`yes.exe` on a live install, hours after the update).

- A name that cannot be deleted is now *parked* first and linked over, the same
  move a package upgrade makes for a held payload file (#1194);
  if even the rename is refused, the message names the link and says what it
  means ("still points at the previous winuxcmd.exe") instead of leaving a bare
  count in the summary.
- The guide documents that `wpm update winuxcmd` is asynchronous: the helper
  waits for the updating process to exit (up to 30 s) before swapping the image
  and relinking, so auditing versions or links immediately after the command
  returns can legitimately show the previous build. That window cost real time
  during the investigation; `wpm links rebuild --force` recreates the links from
  the installed image at any time.

Tests: `wpm.links_rebuild_names_a_link_it_cannot_replace` holds a stale link
without share-delete (so neither delete nor rename is possible), asserts the
exit code and the named message, and that every other name still resolves to
the current image. Full wpm suite green.
…, retry once

Three gaps from #1206, all about an update that silently leaves
a command on the previous image.

- **The detached helper now has a log.** Its stdout/stderr were discarded, so a
  failure inside `apply_update` - including a relink that could not replace a
  name - produced no output anywhere. It writes to
  `<root>\.wpm\logs\self-update-<stamp>-<pid>.log`, the newest three are kept,
  and the "update staged" message names the file.
- **The links are verified after the swap.** `finish_update` rebuilds them,
  re-reads the family, retries once, and reports the names that still point at
  the previous image. Previously a partial relink exited 0.
- **`wpm links verify`** reports by path every command link that does not run
  the installed `winuxcmd.exe` - the diagnosis this whole investigation lacked;
  `wpm links rebuild --force` (already there) replaces them.

Tests: `wpm.links_verify_names_stale_command_links` (clean installation verifies
clean; one name pointed at another image is reported by path) and the earlier
`wpm.links_rebuild_names_a_link_it_cannot_replace`. `wpm.*` 60/60, full suite
2849/2849 with the two known machine-local i18n failures.
@caomengxuan666
caomengxuan666 merged commit 1f1ba28 into main Oct 17, 2026
8 checks passed
@caomengxuan666
caomengxuan666 deleted the fix/relink-diagnostics branch October 17, 2026 06:35
caomengxuan666 added a commit to unixwin/niubash that referenced this pull request Oct 18, 2026
`has_required_command_links` only asked whether `ls.exe`, `cat.exe`, `grep.exe`
and `ln.exe` exist, so a command link left on the *previous* winuxcmd.exe by an
update satisfied it forever: activation then skipped the rebuild and that one
command kept running an older build (observed as a stale `usr\bin\yes.exe` hours
after the update - unixwin/WinuxCmd#1206).

Compare identity instead: a required name must be the same file as this
installation's `winuxcmd.exe`. When it is not, activation runs
`wpm links rebuild --force` as before, which now also *names* the links it
cannot replace (unixwin/WinuxCmd#1209). A stale name therefore heals on the next
shell start instead of waiting for someone to notice.

Test updated to match the contract it is asserting: names that are not links to
the engine do not count, links to it do, and one name left on a different image
is enough to ask for a rebuild.
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