@cryptotaxi247 / kubo / commits / 3ec5c678a

fix(updates): record the occurrence of the auto-update check

This may have been failing before.

Brian Tiger Chow committed Jan 12, 2015 at 19:34 UTC 3ec5c678aeb07e3239fb2ee0b443b0208e1ba641
2 files changed +28 -19
repo/fsrepo/serialize.go
-16
@@ -6,7 +6,6 @@ import (
6 "io"
7 "os"
8 "path/filepath"
9 - "time"
9
10 "github.com/jbenet/go-ipfs/repo/config"
11 "github.com/jbenet/go-ipfs/util"
@@ -93,18 +92,3 @@ func load(filename string) (*config.Config, error) {
92
93 return &cfg, err
94 }
96 -
97 -// RecordUpdateCheck is called to record that an update check was performed,
98 -// showing that the running version is the most recent one.
99 -//
100 -// DEPRECATED
101 -func RecordUpdateCheck(cfg *config.Config, filename string) {
102 - cfg.Version.CheckDate = time.Now()
103 -
104 - if cfg.Version.CheckPeriod == "" {
105 - // CheckPeriod was not initialized for some reason (e.g. config file broken)
106 - log.Error("config.Version.CheckPeriod not set. config broken?")
107 - }
108 -
109 - writeConfigFile(filename, cfg)
110 -}
updates/updates.go
+28 -3
@@ -1,6 +1,7 @@
1 package updates
2
3 import (
4 + "errors"
5 "fmt"
6 "os"
7 "time"
@@ -197,7 +198,7 @@ func ShouldAutoUpdate(setting config.AutoUpdateSetting, newVer string) bool {
198 }
199
200 // CliCheckForUpdates is the automatic update check from the commandline.
200 -func CliCheckForUpdates(cfg *config.Config, confFile string) error {
201 +func CliCheckForUpdates(cfg *config.Config, repoPath string) error {
202
203 // if config says not to, don't check for updates
204 if !cfg.Version.ShouldCheckForUpdate() {
@@ -207,10 +208,22 @@ func CliCheckForUpdates(cfg *config.Config, confFile string) error {
208
209 log.Info("checking for update")
210 u, err := CheckForUpdate()
210 - // if there is no update available, record it, and exit.
211 + // if there is no update available, record it, and exit. NB: only record
212 + // if we checked successfully.
213 if err == ErrNoUpdateAvailable {
214 log.Noticef("No update available, checked on %s", time.Now())
213 - fsrepo.RecordUpdateCheck(cfg, confFile) // only record if we checked successfully.
215 + r := fsrepo.At(repoPath)
216 + if err := r.Open(); err != nil {
217 + return err
218 + }
219 + if err := recordUpdateCheck(cfg); err != nil {
220 + return err
221 + }
222 + // NB: r's Config may be newer than cfg. This overwrites regardless.
223 + r.SetConfig(cfg)
224 + if err := r.Close(); err != nil {
225 + return err
226 + }
227 return nil
228 }
229
@@ -276,3 +289,15 @@ To disable this notice, run:
289 ipfs config Version.Check warn
290
291 `
292 +
293 +// recordUpdateCheck is called to record that an update check was performed,
294 +// showing that the running version is the most recent one.
295 +func recordUpdateCheck(cfg *config.Config) error {
296 + cfg.Version.CheckDate = time.Now()
297 +
298 + if cfg.Version.CheckPeriod == "" {
299 + // CheckPeriod was not initialized for some reason (e.g. config file broken)
300 + return errors.New("config.Version.CheckPeriod not set. config broken?")
301 + }
302 + return nil
303 +}