Skip to content

Commit 6cd874f

Browse files
committed
ensure the process is stopped
1 parent a1c8dfa commit 6cd874f

1 file changed

Lines changed: 14 additions & 3 deletions

File tree

updater/main.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"path/filepath"
1212
"runtime"
1313
"strings"
14+
"time"
1415
)
1516

1617
const (
@@ -104,7 +105,6 @@ func stopProcess(processName string) error {
104105
}
105106

106107
func updateFromBinaries(osType string) {
107-
108108
binaries := []string{"backend-windows-64.exe", "backend-linux-64", "backend-macos-64", "backend-macos-m1-64"}
109109
for _, binary := range binaries {
110110
if _, err := os.Stat("./" + binary); err == nil {
@@ -122,11 +122,22 @@ func updateFromBinaries(osType string) {
122122
fmt.Fprintf(os.Stderr, "Error stopping process %s: %v\n", binary, err)
123123
os.Exit(1)
124124
}
125+
time.Sleep(500 * time.Millisecond) // waits 1/2 second to ensure the process is stopped
125126
}
126127

127128
fmt.Printf("Deleting old binary: %s\n", binary)
128-
if err := os.Remove("./" + binary); err != nil {
129-
fmt.Fprintf(os.Stderr, "Error deleting old binary: %v\n", err)
129+
deleted := false
130+
for i := 0; i < 5; i++ {
131+
if err := os.Remove("./" + binary); err == nil {
132+
deleted = true
133+
break
134+
} else {
135+
fmt.Printf("Retrying delete (%d/5)...\n", i+1)
136+
time.Sleep(300 * time.Millisecond)
137+
}
138+
}
139+
if !deleted {
140+
fmt.Fprintf(os.Stderr, "Error deleting old binary after multiple attempts.\n")
130141
os.Exit(1)
131142
}
132143
}

0 commit comments

Comments
 (0)