Skip to content
This repository has been archived by the owner on Jan 8, 2024. It is now read-only.

Retry on openApplication error (darwin); More error logging #4

Merged
merged 4 commits into from
Apr 12, 2016
Merged
Show file tree
Hide file tree
Changes from 2 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
15 changes: 9 additions & 6 deletions updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -710,20 +710,23 @@ func (u *Updater) restart(ctx Context, updateQuitResponse keybase1.UpdateQuitRes
}

u.log.Debug("App reported its PID as %d", updateQuitResponse.Pid)
p, err := os.FindProcess(updateQuitResponse.Pid)
if err != nil {
p, perr := os.FindProcess(updateQuitResponse.Pid)
if perr != nil {
err = fmt.Errorf("Error finding process: %s", perr)
return
}
u.log.Debug("Killing app")
err = p.Kill()
if err != nil {
kerr := p.Kill()
if kerr != nil {
err = fmt.Errorf("Error killing app: %s", kerr)
return
}
didQuit = true

u.log.Debug("Opening app at %s", updateQuitResponse.ApplicationPath)
err = openApplication(updateQuitResponse.ApplicationPath)
if err != nil {
oerr := u.openApplication(updateQuitResponse.ApplicationPath)
if oerr != nil {
err = fmt.Errorf("Error opening app: %s", oerr)
return
}

Expand Down
2 changes: 1 addition & 1 deletion updater_default.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ func (u *Updater) checkPlatformSpecificUpdate(sourcePath string, destinationPath
return nil
}

func openApplication(applicationPath string) error {
func (u *Updater) openApplication(applicationPath string) error {
return fmt.Errorf("Open application not supported on this platform")
}

Expand Down
22 changes: 17 additions & 5 deletions updater_osx.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package updater

import (
"fmt"
"os"
"os/exec"
"os/user"
Expand Down Expand Up @@ -68,9 +69,20 @@ func (u *Updater) checkPlatformSpecificUpdate(sourcePath string, destinationPath
return nil
}

func openApplication(applicationPath string) error {
_, err := exec.Command("/usr/bin/open", applicationPath).Output()
return err
func (u *Updater) openApplication(applicationPath string) error {
tryOpen := func() error {
out, err := exec.Command("/usr/bin/open", applicationPath).CombinedOutput()
if err != nil {
return fmt.Errorf("%s; %s", err, string(out))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can the error message also say that open caused this problem too?

}
return nil
}
if err := tryOpen(); err != nil {
u.log.Errorf("Open error, trying again in a few seconds; %s", err)
time.Sleep(3 * time.Second)
return tryOpen()
}
return nil
}

func (u *Updater) applyUpdate(localPath string) (err error) {
Expand All @@ -82,9 +94,9 @@ func (u *Updater) applyUpdate(localPath string) (err error) {

// Update spotlight, ignore (but log) errors
u.log.Debug("Updating spotlight: %s", destinationPath)
mdimportOut, mdierr := exec.Command("/usr/bin/mdimport", destinationPath).Output()
mdimportOut, mdierr := exec.Command("/usr/bin/mdimport", destinationPath).CombinedOutput()
if mdierr != nil {
u.log.Errorf("Error trying to update spotlight: %s; %s", mdierr, mdimportOut)
u.log.Errorf("Error trying to update spotlight: %s; %s", mdierr, string(mdimportOut))
}
return
}
2 changes: 1 addition & 1 deletion updater_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func (u *Updater) checkPlatformSpecificUpdate(sourcePath string, destinationPath
return nil
}

func openApplication(applicationPath string) error {
func (u *Updater) openApplication(applicationPath string) error {
return fmt.Errorf("Open application not supported on this platform")
}

Expand Down