From 3ec5c678aeb07e3239fb2ee0b443b0208e1ba641 Mon Sep 17 00:00:00 2001 From: Brian Tiger Chow Date: Mon, 12 Jan 2015 19:34:11 -0800 Subject: [PATCH] fix(updates): record the occurrence of the auto-update check This may have been failing before. --- repo/fsrepo/serialize.go | 16 ---------------- updates/updates.go | 31 ++++++++++++++++++++++++++++--- 2 files changed, 28 insertions(+), 19 deletions(-) diff --git a/repo/fsrepo/serialize.go b/repo/fsrepo/serialize.go index 598941f78..9e291f586 100644 --- a/repo/fsrepo/serialize.go +++ b/repo/fsrepo/serialize.go @@ -6,7 +6,6 @@ import ( "io" "os" "path/filepath" - "time" "github.com/jbenet/go-ipfs/repo/config" "github.com/jbenet/go-ipfs/util" @@ -93,18 +92,3 @@ func load(filename string) (*config.Config, error) { return &cfg, err } - -// RecordUpdateCheck is called to record that an update check was performed, -// showing that the running version is the most recent one. -// -// DEPRECATED -func RecordUpdateCheck(cfg *config.Config, filename string) { - cfg.Version.CheckDate = time.Now() - - if cfg.Version.CheckPeriod == "" { - // CheckPeriod was not initialized for some reason (e.g. config file broken) - log.Error("config.Version.CheckPeriod not set. config broken?") - } - - writeConfigFile(filename, cfg) -} diff --git a/updates/updates.go b/updates/updates.go index 19fd123b3..9236ec316 100644 --- a/updates/updates.go +++ b/updates/updates.go @@ -1,6 +1,7 @@ package updates import ( + "errors" "fmt" "os" "time" @@ -197,7 +198,7 @@ func ShouldAutoUpdate(setting config.AutoUpdateSetting, newVer string) bool { } // CliCheckForUpdates is the automatic update check from the commandline. -func CliCheckForUpdates(cfg *config.Config, confFile string) error { +func CliCheckForUpdates(cfg *config.Config, repoPath string) error { // if config says not to, don't check for updates if !cfg.Version.ShouldCheckForUpdate() { @@ -207,10 +208,22 @@ func CliCheckForUpdates(cfg *config.Config, confFile string) error { log.Info("checking for update") u, err := CheckForUpdate() - // if there is no update available, record it, and exit. + // if there is no update available, record it, and exit. NB: only record + // if we checked successfully. if err == ErrNoUpdateAvailable { log.Noticef("No update available, checked on %s", time.Now()) - fsrepo.RecordUpdateCheck(cfg, confFile) // only record if we checked successfully. + r := fsrepo.At(repoPath) + if err := r.Open(); err != nil { + return err + } + if err := recordUpdateCheck(cfg); err != nil { + return err + } + // NB: r's Config may be newer than cfg. This overwrites regardless. + r.SetConfig(cfg) + if err := r.Close(); err != nil { + return err + } return nil } @@ -276,3 +289,15 @@ To disable this notice, run: ipfs config Version.Check warn ` + +// recordUpdateCheck is called to record that an update check was performed, +// showing that the running version is the most recent one. +func recordUpdateCheck(cfg *config.Config) error { + cfg.Version.CheckDate = time.Now() + + if cfg.Version.CheckPeriod == "" { + // CheckPeriod was not initialized for some reason (e.g. config file broken) + return errors.New("config.Version.CheckPeriod not set. config broken?") + } + return nil +}