fix(linux): the update relaunch is per-platform again
Restoring the PowerShell helper put it in update.go, which is shared — so a Linux build would have tried to run `powershell` to relaunch itself. It compiled and vetted cleanly for linux/amd64, which is exactly why it needed catching before somebody built it: the fault only shows on a real update, on a machine that has no PowerShell. scheduleRelaunch now lives in the platform files. Windows keeps the helper. Linux starts the new binary directly, which is right there and not a compromise: nothing holds an executable open while it runs, so the swap has already succeeded, and there is no mutex to race — the single-instance guard is an flock the dying process releases as it exits, and the new one waits for our pid first. The two guards were looking at the old location and had to follow: the Wait-Process/Start-Process check moves into relaunch_windows_test.go where it belongs, and TestEveryRelaunchPassesItsPid now scans updateswap_linux.go too — the direct spawn moved there, and without it the test would have gone quiet again. Checked from Windows, as BUILDING-LINUX.md says is done at every release: GOOS=linux go build ./... and go vet ./... both clean.
This commit is contained in:
@@ -1,9 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
@@ -31,28 +29,3 @@ func TestRelaunchCmdPassesItsArgumentsAndFolder(t *testing.T) {
|
||||
t.Errorf("Dir = %q, want the executable's folder", cmd.Dir)
|
||||
}
|
||||
}
|
||||
|
||||
// The update relaunch goes through a helper that OUTLIVES this process.
|
||||
//
|
||||
// Two rewrites started the new exe from here instead, and both left operators
|
||||
// with no window after an update: the launch then happens while this process is
|
||||
// still alive and still holds the mutex. The helper waits for our pid first.
|
||||
// Restored from before 0430aab and pinned here so a third rewrite has to argue
|
||||
// with the two reports rather than rediscover them.
|
||||
func TestUpdateRelaunchWaitsForUsFromOutside(t *testing.T) {
|
||||
src, err := os.ReadFile("update.go")
|
||||
if err != nil {
|
||||
t.Fatalf("read update.go: %v", err)
|
||||
}
|
||||
got := string(src)
|
||||
for _, want := range []string{"Wait-Process -Id", "Start-Process -FilePath"} {
|
||||
if !strings.Contains(got, want) {
|
||||
t.Errorf("update.go no longer contains %q — the relaunch must wait for this process from outside it", want)
|
||||
}
|
||||
}
|
||||
// Start-Process shows the new window normally. A direct exec.Command(exe…)
|
||||
// here is the shape that broke it, twice.
|
||||
if strings.Contains(got, "exec.Command(exe") {
|
||||
t.Error("update.go starts the new exe directly again")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user