From 30531ca60240d687c6a83233c6cdc21761899788 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Fri, 10 Feb 2023 11:33:13 +0100 Subject: [PATCH 1/2] Renamed function for clarity --- main.go | 4 ++-- update.go | 2 +- updater/updater.go | 10 +++++----- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/main.go b/main.go index 943cfdf79..d5b379d89 100755 --- a/main.go +++ b/main.go @@ -153,7 +153,7 @@ func main() { if src, err := os.Executable(); err != nil { panic(err) } else if strings.Contains(src, "-temp") { - newPath := updater.BinPath(src) + newPath := updater.RemoveTempSuffixFromPath(src) if err := copyExe(src, newPath); err != nil { log.Println("Copy error: ", err) panic(err) @@ -161,7 +161,7 @@ func main() { Systray.Update(newPath) } else { // Otherwise copy to a path with -temp suffix - if err := copyExe(src, updater.TempPath(src)); err != nil { + if err := copyExe(src, updater.AddTempSuffixToPath(src)); err != nil { panic(err) } Systray.Start() diff --git a/update.go b/update.go index af86df7a3..5ea4d0446 100644 --- a/update.go +++ b/update.go @@ -61,7 +61,7 @@ func updateHandler(c *gin.Context) { return } - path = updater.TempPath(path) + path = updater.AddTempSuffixToPath(path) c.JSON(200, gin.H{"success": "Please wait a moment while the agent reboots itself"}) Systray.Update(path) diff --git a/updater/updater.go b/updater/updater.go index b04d43a7a..bfffe601d 100644 --- a/updater/updater.go +++ b/updater/updater.go @@ -68,8 +68,8 @@ var errHashMismatch = errors.New("new file hash mismatch after patch") var errDiffURLUndefined = errors.New("DiffURL is not defined, I cannot fetch and apply patch, reverting to full bin") var up = update.New() -// TempPath generates a temporary path for the executable (adding "-temp") -func TempPath(path string) string { +// AddTempSuffixToPath adds the "-temp" suffix to the path to an executable file (a ".exe" extension is replaced with "-temp.exe") +func AddTempSuffixToPath(path string) string { if filepath.Ext(path) == "exe" { path = strings.Replace(path, ".exe", "-temp.exe", -1) } else { @@ -79,8 +79,8 @@ func TempPath(path string) string { return path } -// BinPath generates the proper path for a temporary executable (removing "-temp") -func BinPath(path string) string { +// RemoveTempSuffixFromPath removes "-temp" suffix from the path to an executable file (a "-temp.exe" extension is replaced with ".exe") +func RemoveTempSuffixFromPath(path string) string { return strings.Replace(path, "-temp", "", -1) } @@ -234,7 +234,7 @@ func (u *Updater) update() error { return err } - path = TempPath(path) + path = AddTempSuffixToPath(path) old, err := os.Open(path) if err != nil { From ca9c9fb0329b54b9b7b6da206bfbcc0c0eecd8dd Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Fri, 27 Jan 2023 11:54:12 +0100 Subject: [PATCH 2/2] Renamed method for clarity --- main.go | 2 +- systray/systray.go | 4 ++-- update.go | 3 ++- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/main.go b/main.go index d5b379d89..1cd386e07 100755 --- a/main.go +++ b/main.go @@ -158,7 +158,7 @@ func main() { log.Println("Copy error: ", err) panic(err) } - Systray.Update(newPath) + Systray.RestartWith(newPath) } else { // Otherwise copy to a path with -temp suffix if err := copyExe(src, updater.AddTempSuffixToPath(src)); err != nil { diff --git a/systray/systray.go b/systray/systray.go index f3593c4b4..85656bbc9 100644 --- a/systray/systray.go +++ b/systray/systray.go @@ -92,8 +92,8 @@ func (s *Systray) Resume() { s.Restart() } -// Update restarts the program with the given path -func (s *Systray) Update(path string) { +// RestartWith restarts the program with the given path +func (s *Systray) RestartWith(path string) { s.path = path s.Restart() } diff --git a/update.go b/update.go index 5ea4d0446..377f5e353 100644 --- a/update.go +++ b/update.go @@ -64,5 +64,6 @@ func updateHandler(c *gin.Context) { path = updater.AddTempSuffixToPath(path) c.JSON(200, gin.H{"success": "Please wait a moment while the agent reboots itself"}) - Systray.Update(path) + + Systray.RestartWith(path) }