Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,15 +153,15 @@ 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)
}
Systray.Update(newPath)
Systray.RestartWith(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()
Expand Down
4 changes: 2 additions & 2 deletions systray/systray.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
5 changes: 3 additions & 2 deletions update.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,9 @@ 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)

Systray.RestartWith(path)
}
10 changes: 5 additions & 5 deletions updater/updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
}

Expand Down Expand Up @@ -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 {
Expand Down