Răsfoiți Sursa

fix(upgrader): adjust old executable path handling for Windows in commit restart process

Jacky 14 ore în urmă
părinte
comite
e69911f97d
2 a modificat fișierele cu 9 adăugiri și 10 ștergeri
  1. 5 5
      internal/upgrader/test_commit_restart.go
  2. 4 5
      internal/upgrader/upgrade.go

+ 5 - 5
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)

+ 4 - 5
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)