From f2aad399ff8e36ad0578d49eea1ee59f51c034dc Mon Sep 17 00:00:00 2001 From: umbynos Date: Tue, 5 Jan 2021 14:55:21 +0100 Subject: [PATCH 1/5] fix strange temp binary file behavior: if the binary ends with -temp gets restarted all over --- main.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index d3cb56b8c..be8c4f5c3 100755 --- a/main.go +++ b/main.go @@ -132,12 +132,13 @@ func main() { // If the executable is temporary, copy it to the full path, then restart if strings.Contains(path, "-temp") { - err := copyExe(path, updater.BinPath(path)) + newPath := updater.BinPath(path) + err := copyExe(path, newPath) if err != nil { panic(err) } - Systray.Restart() + Systray.Update(newPath) } else { // Otherwise copy to a path with -temp suffix err := copyExe(path, updater.TempPath(path)) From 1c168a80d34c0f527c13fe86867e23f4ff286258 Mon Sep 17 00:00:00 2001 From: umbynos Date: Tue, 5 Jan 2021 15:00:28 +0100 Subject: [PATCH 2/5] add some useful logs --- main.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/main.go b/main.go index be8c4f5c3..217bf86ef 100755 --- a/main.go +++ b/main.go @@ -135,6 +135,7 @@ func main() { newPath := updater.BinPath(path) err := copyExe(path, newPath) if err != nil { + log.Println("Copy error: ", err) panic(err) } @@ -153,10 +154,12 @@ func main() { func copyExe(from, to string) error { data, err := ioutil.ReadFile(from) if err != nil { + log.Println("Cannot read file: ", from) return err } err = ioutil.WriteFile(to, data, 0755) if err != nil { + log.Println("Cannot write file: ", to) return err } return nil From 0910bcba49226765218f172e5bd60f6f1964f156 Mon Sep 17 00:00:00 2001 From: umbynos Date: Tue, 5 Jan 2021 15:01:20 +0100 Subject: [PATCH 3/5] Systray.Start() was called even if the program have to restart --- main.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/main.go b/main.go index 217bf86ef..231f5dc48 100755 --- a/main.go +++ b/main.go @@ -146,9 +146,8 @@ func main() { if err != nil { panic(err) } + Systray.Start() } - - Systray.Start() } func copyExe(from, to string) error { From cbd9df5789c0bb97f5420750e0e580c2cae474ab Mon Sep 17 00:00:00 2001 From: umbynos Date: Tue, 5 Jan 2021 15:42:17 +0100 Subject: [PATCH 4/5] added useful prints --- systray/systray.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/systray/systray.go b/systray/systray.go index 8ef805789..a79b19d52 100644 --- a/systray/systray.go +++ b/systray/systray.go @@ -26,14 +26,15 @@ type Systray struct { // it works by finding the executable path and launching it before quitting func (s *Systray) Restart() { - fmt.Println(s.path) - fmt.Println(osext.Executable()) if s.path == "" { + fmt.Println("Update binary path not set") var err error s.path, err = osext.Executable() if err != nil { fmt.Printf("Error getting exe path using osext lib. err: %v\n", err) } + } else { + fmt.Println("Starting updated binary: ", s.path) } // Trim newlines (needed on osx) From 53ac2514283d33c7a5a79b3b862bf5f56ab8ba38 Mon Sep 17 00:00:00 2001 From: umbynos Date: Tue, 5 Jan 2021 15:47:56 +0100 Subject: [PATCH 5/5] replace fmt with a proper logger --- systray/systray.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/systray/systray.go b/systray/systray.go index a79b19d52..7b3f9f5db 100644 --- a/systray/systray.go +++ b/systray/systray.go @@ -5,6 +5,8 @@ import ( "os/exec" "strings" + log "github.com/sirupsen/logrus" + "github.com/kardianos/osext" ) @@ -27,14 +29,14 @@ type Systray struct { func (s *Systray) Restart() { if s.path == "" { - fmt.Println("Update binary path not set") + log.Println("Update binary path not set") var err error s.path, err = osext.Executable() if err != nil { - fmt.Printf("Error getting exe path using osext lib. err: %v\n", err) + log.Printf("Error getting exe path using osext lib. err: %v\n", err) } } else { - fmt.Println("Starting updated binary: ", s.path) + log.Println("Starting updated binary: ", s.path) } // Trim newlines (needed on osx) @@ -51,7 +53,7 @@ func (s *Systray) Restart() { cmd := exec.Command(s.path, args...) err := cmd.Start() if err != nil { - fmt.Printf("Error restarting process: %v\n", err) + log.Printf("Error restarting process: %v\n", err) return }