From 6f8e93b31f0c302be38fdbfc73ae2aa3938979e6 Mon Sep 17 00:00:00 2001 From: Corey Butler <770982+coreybutler@users.noreply.github.com> Date: Tue, 24 Nov 2026 09:09:35 -0600 Subject: [PATCH] fix: skip install reshim hard-fail in link mode finalizeInstallShims always ran reshim and rolled back installs when shim links failed, even when OperatingMode=link (which does not need package-manager proxy shims on PATH). Signed-off-by: Corey Butler <770982+coreybutler@users.noreply.github.com> --- src/installer/reshim.go | 39 ++++++++++++++++++------------ src/installer/reshim_test.go | 47 ++++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+), 15 deletions(-) diff --git a/src/installer/reshim.go b/src/installer/reshim.go index 0b12c8e..954462f 100644 --- a/src/installer/reshim.go +++ b/src/installer/reshim.go @@ -5,6 +5,7 @@ import ( "common/settings" "fmt" "os" + "strings" "nvm/bootstrap" ) @@ -21,30 +22,33 @@ Hard links require .shim and proxy.exe on the same volume; symlinks need Developer Mode or the Create symbolic links privilege. Try one of: - 1) Keep Node storage on the same drive as NVM, for example: - nvm config set root=%LOCALAPPDATA%\Author Software\nvm\installs + 1) Enable Developer Mode (symlink privilege), then: + nvm reshim --force + https://docs.nvm-windows.com/features/modes 2) Switch to link mode: nvm config set mode=link nvm use link - 3) Enable Developer Mode (symlink privilege): - https://docs.nvm-windows.com/features/modes `) } -// finalizeInstallShims runs reshim after version installs, discarding backups only -// on success. On failure it rolls back newly installed dirs and hard-fails. +// finalizeInstallShims runs reshim after version installs in shim mode, +// discarding backups only on success. On failure it rolls back newly installed +// dirs and hard-fails. Link mode skips reshim here — ActivateVersion points +// .nodejs at .link/nodejs and does not require package-manager proxy shims. func finalizeInstallShims(txns []*Transaction, status *Status, modulesInstalled bool, hadInstalledVersions bool) error { if status.TotalInstalled > 0 || modulesInstalled { - // Reshim before discarding install backups / activating, so a broken - // shim set can roll back newly installed version dirs. - if err := runReshim(); err != nil { - _ = notify.HelpEnablingSymlinks(settings.AppId) - printShimLinkGuidance() - status.Cancel("Installation rolled back: shim links could not be created.") - for _, txn := range txns { - rollbackCanceledInstall(txn, status) + if operatingInShimMode() { + // Reshim before discarding install backups / activating, so a broken + // shim set can roll back newly installed version dirs. + if err := runReshim(); err != nil { + _ = notify.HelpEnablingSymlinks(settings.AppId) + printShimLinkGuidance() + status.Cancel("Installation rolled back: shim links could not be created.") + for _, txn := range txns { + rollbackCanceledInstall(txn, status) + } + return status.Abort(fmt.Errorf("reshim failed: %w", err)) } - return status.Abort(fmt.Errorf("reshim failed: %w", err)) } discardInstallBackups(txns) @@ -61,6 +65,11 @@ func finalizeInstallShims(txns []*Transaction, status *Status, modulesInstalled return nil } +func operatingInShimMode() bool { + mode := strings.TrimSpace(strings.ToLower(settings.Global().Mode)) + return mode == "" || mode == "shim" +} + func discardInstallBackups(txns []*Transaction) { for _, txn := range txns { if txn != nil && txn.installBackup != "" && !txn.backupDiscarded { diff --git a/src/installer/reshim_test.go b/src/installer/reshim_test.go index 230f7d5..5ab2c3c 100644 --- a/src/installer/reshim_test.go +++ b/src/installer/reshim_test.go @@ -159,6 +159,10 @@ func TestReshimWrapsUtilityFailure(t *testing.T) { func TestFinalizeInstallShimsRollsBackOnReshimFailure(t *testing.T) { setupReshimTestProfile(t) + if err := settings.Put("mode", "shim"); err != nil { + t.Fatalf("Put(mode) error = %v", err) + } + settings.Load(true) installDir := filepath.Join(t.TempDir(), "v22.0.0") if err := os.MkdirAll(installDir, 0o755); err != nil { @@ -201,3 +205,46 @@ func TestFinalizeInstallShimsRollsBackOnReshimFailure(t *testing.T) { t.Fatal("status.cancelMessage empty, want rollback cancel message") } } + +func TestFinalizeInstallShimsSkipsReshimInLinkMode(t *testing.T) { + setupReshimTestProfile(t) + if err := settings.Put("mode", "link"); err != nil { + t.Fatalf("Put(mode) error = %v", err) + } + settings.Load(true) + + installDir := filepath.Join(t.TempDir(), "v22.0.0") + if err := os.MkdirAll(installDir, 0o755); err != nil { + t.Fatalf("MkdirAll(%q) error = %v", installDir, err) + } + + orig := runReshim + t.Cleanup(func() { runReshim = orig }) + called := false + runReshim = func() error { + called = true + return fmt.Errorf("reshim should not run in link mode") + } + + status := newStatus() + status.TotalInstalled = 1 + status.Versions = []string{"22.0.0"} + status.running = true + + txn := &Transaction{ + version: "22.0.0", + installDir: installDir, + installedNew: true, + installed: false, + } + + if err := finalizeInstallShims([]*Transaction{txn}, status, false, true); err != nil { + t.Fatalf("finalizeInstallShims error = %v, want nil in link mode", err) + } + if called { + t.Fatal("runReshim was called in link mode") + } + if _, err := os.Stat(installDir); err != nil { + t.Fatalf("install dir should remain after link-mode finalize: %v", err) + } +}