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

Commit

Permalink
Retry on openApplication error (darwin); More error logging (#4)
Browse files Browse the repository at this point in the history
* Retry on openApplication error (darwin); More error logging
* Retry more times (to overcome Gatekeeper issue)
  • Loading branch information
gabriel committed Apr 12, 2016
1 parent 1fe330b commit 6bcce92
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 13 deletions.
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
25 changes: 20 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,23 @@ 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("Open error: %s; %s", err, string(out))
}
return nil
}
for i := 0; i < 10; i++ {
err := tryOpen()
if err == nil {
break
}
u.log.Errorf("Open error (trying again in a second): %s", err)
time.Sleep(1 * time.Second)
}
return nil
}

func (u *Updater) applyUpdate(localPath string) (err error) {
Expand All @@ -82,9 +97,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

0 comments on commit 6bcce92

Please sign in to comment.