mirror of
https://github.com/ipfs/kubo.git
synced 2025-06-20 19:19:06 +08:00
removed duplicate logic
This commit is contained in:
@ -145,19 +145,11 @@ func localNode(confdir string, online bool) (*core.IpfsNode, error) {
|
|||||||
if updates.ShouldAutoUpdate(cfg.Version.AutoUpdate, u.Version) {
|
if updates.ShouldAutoUpdate(cfg.Version.AutoUpdate, u.Version) {
|
||||||
log.Notice("Applying update %s", u.Version)
|
log.Notice("Applying update %s", u.Version)
|
||||||
|
|
||||||
if err = updates.AbleToApply(); err != nil {
|
if err = updates.Apply(u); 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)
|
|
||||||
}
|
|
||||||
log.Error(err.Error())
|
log.Error(err.Error())
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// BUG(cryptix): no good way to restart yet. - tracking https://github.com/inconshreveable/go-update/issues/5
|
// 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)
|
fmt.Println("update %v applied. please restart.", u.Version)
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
|
@ -24,17 +24,9 @@ func UpdateApply(n *core.IpfsNode, args []string, opts map[string]interface{}, o
|
|||||||
}
|
}
|
||||||
fmt.Fprintln(out, "New Version:", u.Version)
|
fmt.Fprintln(out, "New Version:", u.Version)
|
||||||
|
|
||||||
if err = updates.AbleToApply(); err != nil {
|
if err = updates.Apply(u); 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)
|
|
||||||
}
|
|
||||||
fmt.Fprint(out, err.Error())
|
fmt.Fprint(out, err.Error())
|
||||||
return err
|
return fmt.Errorf("Couldn't apply update: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Fprintln(out, "Updated applied! Shutting down.")
|
fmt.Fprintln(out, "Updated applied! Shutting down.")
|
||||||
|
@ -57,9 +57,22 @@ func CheckForUpdate() (*check.Result, error) {
|
|||||||
return param.CheckForUpdate(updateEndpointURL, up)
|
return param.CheckForUpdate(updateEndpointURL, up)
|
||||||
}
|
}
|
||||||
|
|
||||||
// AbleToApply cheks if the running process is able to update itself
|
// Apply cheks if the running process is able to update itself
|
||||||
func AbleToApply() error {
|
// and than updates to the passed release
|
||||||
return update.New().CanUpdate()
|
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
|
// ShouldAutoUpdate decides wether a new version should be applied
|
||||||
|
Reference in New Issue
Block a user