removed duplicate logic
Henry committed
Oct 20, 2014 at 19:01 UTC
cb73ea7ba48bdb1ca80a2d19992579dd9f5c673f
3 files changed
+20
-23
cmd/ipfs/ipfs.go
+2
-10
@@ -145,19 +145,11 @@ func localNode(confdir string, online bool) (*core.IpfsNode, error) {
145
if updates.ShouldAutoUpdate(cfg.Version.AutoUpdate, u.Version) {
146
log.Notice("Applying update %s", u.Version)
147
148
- if err = updates.AbleToApply(); err != nil {
149
- log.Error("Can't apply update: %v", err)
150
- return nil, err
151
- }
152
-
153
- if err, errRecover := u.Update(); err != nil {
154
- err = fmt.Errorf("Update failed: %v\n", err)
155
- if errRecover != nil {
156
- err = fmt.Errorf("%s\nRecovery failed! Cause: %v\nYou may need to recover manually", err, errRecover)
157
- }
148
+ if err = updates.Apply(u); err != nil {
149
log.Error(err.Error())
150
return nil, err
151
}
152
+
153
// BUG(cryptix): no good way to restart yet. - tracking https://github.com/inconshreveable/go-update/issues/5
154
fmt.Println("update %v applied. please restart.", u.Version)
155
os.Exit(0)
core/commands/update.go
+2
-10
@@ -24,17 +24,9 @@ func UpdateApply(n *core.IpfsNode, args []string, opts map[string]interface{}, o
24
}
25
fmt.Fprintln(out, "New Version:", u.Version)
26
27
- if err = updates.AbleToApply(); err != nil {
28
- return fmt.Errorf("Can't apply update: %v", err)
29
- }
30
-
31
- if err, errRecover := u.Update(); err != nil {
32
- err = fmt.Errorf("Update failed: %v\n", err)
33
- if errRecover != nil {
34
- err = fmt.Errorf("%s\nRecovery failed! Cause: %v\nYou may need to recover manually", err, errRecover)
35
- }
27
+ if err = updates.Apply(u); err != nil {
28
fmt.Fprint(out, err.Error())
37
- return err
29
+ return fmt.Errorf("Couldn't apply update: %v", err)
30
}
31
32
fmt.Fprintln(out, "Updated applied! Shutting down.")
updates/updates.go
+16
-3
@@ -57,9 +57,22 @@ func CheckForUpdate() (*check.Result, error) {
57
return param.CheckForUpdate(updateEndpointURL, up)
58
}
59
60
-// AbleToApply cheks if the running process is able to update itself
61
-func AbleToApply() error {
62
- return update.New().CanUpdate()
60
+// Apply cheks if the running process is able to update itself
61
+// and than updates to the passed release
62
+func Apply(rel *check.Result) error {
63
+ if err := update.New().CanUpdate(); err != nil {
64
+ return err
65
+ }
66
+
67
+ if err, errRecover := rel.Update(); err != nil {
68
+ err = fmt.Errorf("Update failed: %v\n", err)
69
+ if errRecover != nil {
70
+ err = fmt.Errorf("%s\nRecovery failed! Cause: %v\nYou may need to recover manually", err, errRecover)
71
+ }
72
+ return err
73
+ }
74
+
75
+ return nil
76
}
77
78
// ShouldAutoUpdate decides wether a new version should be applied