1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-06-19 18:05:32 +08:00

removed duplicate logic

This commit is contained in:
Henry
2014-10-20 19:01:50 +02:00
parent 46dc322f82
commit cb73ea7ba4
3 changed files with 20 additions and 23 deletions

View File

@ -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)

View File

@ -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.")

View File

@ -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