check AutoUpdate settings and apply
Henry committed
Oct 20, 2014 at 17:14 UTC
8d41021b898df35b4a5de6a0752294489f6773a2
1 file changed
+25
-1
cmd/ipfs/ipfs.go
+25
-1
@@ -128,7 +128,8 @@ func localNode(confdir string, online bool) (*core.IpfsNode, error) {
128
}
129
130
if cfg.Version.ShouldCheckForUpdate() {
131
- _, err := updates.CheckForUpdate()
131
+ log.Info("checking for update")
132
+ u, err := updates.CheckForUpdate()
133
if err != nil {
134
if err != check.NoUpdateAvailable {
135
log.Error("Error while checking for update: %v\n", err)
@@ -139,6 +140,29 @@ func localNode(confdir string, online bool) (*core.IpfsNode, error) {
140
}
141
142
config.RecordUpdateCheck(cfg, filename)
143
+
144
+ if u != nil && cfg.Version.AutoUpdate != config.UpdateNever {
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
+ }
158
+ log.Error(err.Error())
159
+ return nil, err
160
+ }
161
+ // BUG(cryptix): no good way to restart yet. - tracking https://github.com/inconshreveable/go-update/issues/5
162
+ fmt.Println("update %v applied. please restart.", u.Version)
163
+ os.Exit(0)
164
+ }
165
+ }
166
}
167
168
return core.NewIpfsNode(cfg, online)