From e69911f97d3d153f736f548184aa1ab83db14b8c Mon Sep 17 00:00:00 2001 From: Jacky Date: Mon, 5 May 2025 13:57:56 +0000 Subject: [PATCH] fix(upgrader): adjust old executable path handling for Windows in commit restart process --- internal/upgrader/test_commit_restart.go | 10 +++++----- internal/upgrader/upgrade.go | 9 ++++----- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/internal/upgrader/test_commit_restart.go b/internal/upgrader/test_commit_restart.go index a3695930..ce148820 100644 --- a/internal/upgrader/test_commit_restart.go +++ b/internal/upgrader/test_commit_restart.go @@ -19,7 +19,10 @@ func (u *Upgrader) TestCommitAndRestart() error { testBinaryPath := filepath.Join(exDir, "nginx-ui.test") // Create temporary old file path - oldExe := filepath.Join(exDir, ".nginx-ui.old."+strconv.FormatInt(time.Now().Unix(), 10)) + oldExe := "" + if runtime.GOOS == "windows" { + oldExe = filepath.Join(exDir, ".nginx-ui.old."+strconv.FormatInt(time.Now().Unix(), 10)) + } // Setup update options opts := selfupdate.Options{ @@ -85,10 +88,7 @@ func (u *Upgrader) TestCommitAndRestart() error { return err } - if runtime.GOOS != "windows" { - _ = os.Remove(oldExe) - _ = os.Remove(testBinaryPath) - } + _ = os.Remove(testBinaryPath) // Wait for file to be written time.Sleep(1 * time.Second) diff --git a/internal/upgrader/upgrade.go b/internal/upgrader/upgrade.go index dd3754c7..9f08af19 100644 --- a/internal/upgrader/upgrade.go +++ b/internal/upgrader/upgrade.go @@ -218,7 +218,10 @@ func (u *Upgrader) PerformCoreUpgrade(tarPath string) (err error) { } defer updateInProgress.Store(false) - oldExe := filepath.Join(filepath.Dir(u.ExPath), ".nginx-ui.old."+strconv.FormatInt(time.Now().Unix(), 10)) + oldExe := "" + if runtime.GOOS != "windows" { + oldExe = filepath.Join(filepath.Dir(u.ExPath), ".nginx-ui.old."+strconv.FormatInt(time.Now().Unix(), 10)) + } opts := selfupdate.Options{ OldSavePath: oldExe, @@ -272,10 +275,6 @@ func (u *Upgrader) PerformCoreUpgrade(tarPath string) (err error) { return err } - if runtime.GOOS != "windows" { - _ = os.Remove(oldExe) - } - // wait for the file to be written time.Sleep(1 * time.Second)