diff --git a/cmd/ipfs/ipfs.go b/cmd/ipfs/ipfs.go index 63c476f2f..c2d9984c8 100644 --- a/cmd/ipfs/ipfs.go +++ b/cmd/ipfs/ipfs.go @@ -145,19 +145,11 @@ func localNode(confdir string, online bool) (*core.IpfsNode, error) { if updates.ShouldAutoUpdate(cfg.Version.AutoUpdate, u.Version) { log.Notice("Applying update %s", u.Version) - if err = updates.AbleToApply(); err != nil { - log.Error("Can't apply update: %v", err) - return nil, err - } - - if err, errRecover := u.Update(); err != nil { - err = fmt.Errorf("Update failed: %v\n", err) - if errRecover != nil { - err = fmt.Errorf("%s\nRecovery failed! Cause: %v\nYou may need to recover manually", err, errRecover) - } + if err = updates.Apply(u); err != nil { log.Error(err.Error()) return nil, err } + // BUG(cryptix): no good way to restart yet. - tracking https://github.com/inconshreveable/go-update/issues/5 fmt.Println("update %v applied. please restart.", u.Version) os.Exit(0) diff --git a/core/commands/update.go b/core/commands/update.go index 16e2f82d4..95a4f8a44 100644 --- a/core/commands/update.go +++ b/core/commands/update.go @@ -24,17 +24,9 @@ func UpdateApply(n *core.IpfsNode, args []string, opts map[string]interface{}, o } fmt.Fprintln(out, "New Version:", u.Version) - if err = updates.AbleToApply(); err != nil { - return fmt.Errorf("Can't apply update: %v", err) - } - - if err, errRecover := u.Update(); err != nil { - err = fmt.Errorf("Update failed: %v\n", err) - if errRecover != nil { - err = fmt.Errorf("%s\nRecovery failed! Cause: %v\nYou may need to recover manually", err, errRecover) - } + if err = updates.Apply(u); err != nil { fmt.Fprint(out, err.Error()) - return err + return fmt.Errorf("Couldn't apply update: %v", err) } fmt.Fprintln(out, "Updated applied! Shutting down.") diff --git a/updates/updates.go b/updates/updates.go index eb11ad186..d016afc2d 100644 --- a/updates/updates.go +++ b/updates/updates.go @@ -57,9 +57,22 @@ func CheckForUpdate() (*check.Result, error) { return param.CheckForUpdate(updateEndpointURL, up) } -// AbleToApply cheks if the running process is able to update itself -func AbleToApply() error { - return update.New().CanUpdate() +// Apply cheks if the running process is able to update itself +// and than updates to the passed release +func Apply(rel *check.Result) error { + if err := update.New().CanUpdate(); err != nil { + return err + } + + if err, errRecover := rel.Update(); err != nil { + err = fmt.Errorf("Update failed: %v\n", err) + if errRecover != nil { + err = fmt.Errorf("%s\nRecovery failed! Cause: %v\nYou may need to recover manually", err, errRecover) + } + return err + } + + return nil } // ShouldAutoUpdate decides wether a new version should be applied