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

This may have been failing before.
This commit is contained in:
Brian Tiger Chow 2015-01-12 19:34:11 -08:00
parent 899c419ac3
commit 3ec5c678ae
2 changed files with 28 additions and 19 deletions

View File

@ -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)
}

View File

@ -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
}