Skip to content

Commit 936b6c8

Browse files
committed
Fix temp binary not starting correclty (#583)
* fix strange temp binary file behavior: if the binary ends with -temp gets restarted all over * add some useful logs * Systray.Start() was called even if the program have to restart * added useful prints * replace fmt with a proper logger
1 parent 45a2de6 commit 936b6c8

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

Diff for: main.go

+7-4
Original file line numberDiff line numberDiff line change
@@ -132,30 +132,33 @@ func main() {
132132

133133
// If the executable is temporary, copy it to the full path, then restart
134134
if strings.Contains(path, "-temp") {
135-
err := copyExe(path, updater.BinPath(path))
135+
newPath := updater.BinPath(path)
136+
err := copyExe(path, newPath)
136137
if err != nil {
138+
log.Println("Copy error: ", err)
137139
panic(err)
138140
}
139141

140-
Systray.Restart()
142+
Systray.Update(newPath)
141143
} else {
142144
// Otherwise copy to a path with -temp suffix
143145
err := copyExe(path, updater.TempPath(path))
144146
if err != nil {
145147
panic(err)
146148
}
149+
Systray.Start()
147150
}
148-
149-
Systray.Start()
150151
}
151152

152153
func copyExe(from, to string) error {
153154
data, err := ioutil.ReadFile(from)
154155
if err != nil {
156+
log.Println("Cannot read file: ", from)
155157
return err
156158
}
157159
err = ioutil.WriteFile(to, data, 0755)
158160
if err != nil {
161+
log.Println("Cannot write file: ", to)
159162
return err
160163
}
161164
return nil

Diff for: systray/systray.go

+7-4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import (
55
"os/exec"
66
"strings"
77

8+
log "github.com/sirupsen/logrus"
9+
810
"github.com/kardianos/osext"
911
)
1012

@@ -26,14 +28,15 @@ type Systray struct {
2628
// it works by finding the executable path and launching it before quitting
2729
func (s *Systray) Restart() {
2830

29-
fmt.Println(s.path)
30-
fmt.Println(osext.Executable())
3131
if s.path == "" {
32+
log.Println("Update binary path not set")
3233
var err error
3334
s.path, err = osext.Executable()
3435
if err != nil {
35-
fmt.Printf("Error getting exe path using osext lib. err: %v\n", err)
36+
log.Printf("Error getting exe path using osext lib. err: %v\n", err)
3637
}
38+
} else {
39+
log.Println("Starting updated binary: ", s.path)
3740
}
3841

3942
// Trim newlines (needed on osx)
@@ -50,7 +53,7 @@ func (s *Systray) Restart() {
5053
cmd := exec.Command(s.path, args...)
5154
err := cmd.Start()
5255
if err != nil {
53-
fmt.Printf("Error restarting process: %v\n", err)
56+
log.Printf("Error restarting process: %v\n", err)
5457
return
5558
}
5659

0 commit comments

Comments
 (0)