Skip to content

fix(packaging): remove only the Path folder the Windows installer added - #2199

Merged
houko merged 1 commit into
nsgo-dev:mainfrom
txchen:fix/windows-owned-path
Nov 23, 2026
Merged

houko merged 1 commit into
nsgo-dev:mainfrom
txchen:fix/windows-owned-path

Conversation

@txchen

@txchen txchen commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Why

With windows.command_line, the NSIS installer adds the app's folder to the user's Path. Two cases went wrong for apps that use it:

  • If the folder was already on Path before installing, for example because the user added it, the uninstaller removed it anyway.
  • If an upgrade installed into a different folder, the old folder stayed on Path.

What changed

  • The installer records the folder it added, NsgoPathAddedDir in the app's uninstall entry, and only when the folder was not already on Path.
  • The uninstaller, an upgrade into another folder, and an upgrade that no longer sets windows.command_line remove that exact folder, and drop the record only once PowerShell reports the folder gone.
  • If removing the old folder fails, the record is kept, including past the uninstall entry's deletion, and an upgrade does not add its new folder. The next upgrade or the uninstaller tries again.
  • An uninstaller left in a folder an upgrade moved away from (InstallLocation now names another folder) removes only its own files. It leaves the active installation's registrations, shortcuts, uninstall entry and Path alone.

Scope

  • Targets: the nsgo tool (NSIS installer generation) and Windows.
  • Screenshots: none; nothing visible changes.

Tradeoffs

  • Apps without windows.command_line are affected only by the moved-folder uninstaller guard above.
  • Installations made before this change have no record, so uninstalling them leaves their folder on Path. This avoids removing an entry the installer cannot prove it added.

Blast Radius

Windows installers built by NSGo. The Path changes apply to apps that set windows.command_line; the moved-folder uninstaller guard applies to every Windows installer. Other targets are unaffected.

Verification

  • go tool nsgo check, go tool nsgo check -target windows, the changelog check and go tool nsgo test -run TestNSIS ./cmd/nsgo on macOS.

  • TestNSISCompiles now also compiles the script with windows.command_line.

  • New TestNSISPathOwnershipNative in fileassociations_windows_test.go installs and uninstalls on real Windows against the user's Path, restoring the previous value and type afterwards. It covers:

    • a pre-existing entry surviving uninstall;
    • an install that adds the folder;
    • a move that swaps the old folder for the new one;
    • an uninstaller left behind by the move that leaves Path alone;
    • an uninstall that removes the folder.

    It runs in the Windows CI job under NSGO_FILE_ASSOCIATIONS and the NSIS test selector. I could not run it locally, as I have no Windows machine.

  • The failed-removal paths have no native test, since PowerShell cannot be made to fail reliably there.

Checklist: the title is a Conventional Commit; the docs whose facts change are updated; the change has a changelog.d/ fragment; no new third-party code, assets or dependencies.

@github-actions github-actions Bot added size/M bug Something isn't working documentation Improvements or additions to documentation cli and removed bug Something isn't working labels Nov 23, 2026
@github-actions

Copy link
Copy Markdown

Thanks for your first pull request! Before it is merged:

  • Write the title as a Conventional Commit, such as fix(linux): ...; a squash merge uses it as the commit subject.
  • Run go tool nsgo check and go tool nsgo test, and say in the description what you ran on which targets and what you could not.
  • Making a change says what a pull request needs, and AGENTS.md and ARCHITECTURE.md how the code is organized.

With windows.command_line, the uninstaller removed every Path entry matching the install folder, including one the user had before installing, and an upgrade to another folder left the old one behind.

The installer now records the folder it added as NsgoPathAddedDir in the uninstall entry, only when the folder was not on Path already. An upgrade to the same folder keeps the record; an upgrade to another folder, one that drops windows.command_line, and the uninstaller remove that exact folder and drop the record only once PowerShell reports it gone. A failed removal keeps the record, past the uninstall entry's deletion, and an upgrade then leaves its own folder off Path. An uninstaller left in a folder an upgrade moved from, which InstallLocation no longer names, removes its own files alone. Installations from before the record have none, and their folder stays on Path.
@txchen
txchen force-pushed the fix/windows-owned-path branch from 30c31fb to 2421f91 Compare November 23, 2026 02:17
@github-actions github-actions Bot added the bug Something isn't working label Nov 23, 2026
@houko

houko commented Nov 23, 2026

Copy link
Copy Markdown
Collaborator

Reviewed. I traced the install, upgrade and uninstall paths through AddUserPath, RemoveOwnedPath and UserPath: the record is written only on PowerShell's exit 3 (folder newly added) and dropped only on exit 4 (folder off Path), the $R0-$R2 registers are saved around every call, and the InstallLocation guard keeps a moved-from uninstaller off the active installation's registrations. TestNSISScript and TestNSISCompiles (both with and without windows.command_line) pass with makensis 3.x on macOS, and go vet ./... passes on Linux and for GOOS=windows ./cmd/nsgo. I did not run TestNSISPathOwnershipNative on Windows; main's Windows job will run it.

One behaviour to keep in mind: an uninstaller whose uninstall entry has gone entirely (empty InstallLocation) now skips the registration and shortcut cleanup and removes only its files. Thanks for the careful change.

@houko
houko merged commit 8556e95 into nsgo-dev:main Nov 23, 2026
3 checks passed
@txchen
txchen deleted the fix/windows-owned-path branch November 23, 2026 06:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working cli documentation Improvements or additions to documentation size/M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants