提交 0a0c38fb 作者: Henry

using @jbenet's industrial lipstick to clean this up

上级 0115d1e0
...@@ -5,10 +5,8 @@ import ( ...@@ -5,10 +5,8 @@ import (
"fmt" "fmt"
"os" "os"
"runtime/pprof" "runtime/pprof"
"time"
flag "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/gonuts/flag" flag "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/gonuts/flag"
check "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/inconshreveable/go-update/check"
commander "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/commander" commander "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/commander"
ma "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr" ma "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr"
...@@ -128,37 +126,8 @@ func localNode(confdir string, online bool) (*core.IpfsNode, error) { ...@@ -128,37 +126,8 @@ func localNode(confdir string, online bool) (*core.IpfsNode, error) {
return nil, err return nil, err
} }
if cfg.Version.ShouldCheckForUpdate() { if err := updates.CliCheckForUpdates(cfg, filename); err != nil {
log.Info("checking for update") return nil, err
u, err := updates.CheckForUpdate()
if err != nil {
if err != check.NoUpdateAvailable {
if cfg.Version.Check == config.CheckError {
log.Error("Error while checking for update: %v\n", err)
return nil, err
}
// when "warn" version.check mode we just show a warning message
log.Warning(err.Error())
} else { // err == check.NoUpdateAvailable
log.Notice("No update available, checked on %s", time.Now())
config.RecordUpdateCheck(cfg, filename)
}
} else { // update avail
if cfg.Version.AutoUpdate != config.UpdateNever {
if updates.ShouldAutoUpdate(cfg.Version.AutoUpdate, u.Version) {
log.Notice("Applying update %s", u.Version)
if err = updates.Apply(u); err != nil {
log.Error(err.Error())
return nil, err
}
// BUG(cryptix): no good way to restart yet. - tracking https://github.com/inconshreveable/go-update/issues/5
fmt.Println("update %v applied. please restart.", u.Version)
os.Exit(0)
}
}
}
} }
return core.NewIpfsNode(cfg, online) return core.NewIpfsNode(cfg, online)
......
...@@ -3,6 +3,7 @@ package updates ...@@ -3,6 +3,7 @@ package updates
import ( import (
"fmt" "fmt"
"os" "os"
"time"
"github.com/jbenet/go-ipfs/config" "github.com/jbenet/go-ipfs/config"
u "github.com/jbenet/go-ipfs/util" u "github.com/jbenet/go-ipfs/util"
...@@ -122,3 +123,77 @@ func ShouldAutoUpdate(setting config.AutoUpdateSetting, newVer string) bool { ...@@ -122,3 +123,77 @@ func ShouldAutoUpdate(setting config.AutoUpdateSetting, newVer string) bool {
return false return false
} }
func CliCheckForUpdates(cfg *config.Config, confFile string) error {
// if config says not to, don't check for updates
if !cfg.Version.ShouldCheckForUpdate() {
log.Info("update checking disabled.")
return nil
}
log.Info("checking for update")
u, err := CheckForUpdate()
// if there is no update available, record it, and exit.
if err == check.NoUpdateAvailable {
log.Notice("No update available, checked on %s", time.Now())
config.RecordUpdateCheck(cfg, confFile) // only record if we checked successfully.
return nil
}
// if another, unexpected error occurred, note it.
if err != nil {
if cfg.Version.Check == config.CheckError {
log.Error("Error while checking for update: %v\n", err)
return nil
}
// when "warn" version.check mode we just show a warning message
log.Warning(err.Error())
return nil
}
// there is an update available
// if we autoupdate
if cfg.Version.AutoUpdate != config.UpdateNever {
// and we should auto update
if ShouldAutoUpdate(cfg.Version.AutoUpdate, u.Version) {
log.Notice("Applying update %s", u.Version)
if err = Apply(u); err != nil {
log.Error(err.Error())
return nil
}
// BUG(cryptix): no good way to restart yet. - tracking https://github.com/inconshreveable/go-update/issues/5
fmt.Println("update %v applied. please restart.", u.Version)
os.Exit(0)
}
}
// autoupdate did not exit, so regular notices.
switch cfg.Version.Check {
case config.CheckError:
return fmt.Errorf(errShouldUpdate, Version, u.Version)
case config.CheckWarn:
// print the warning
fmt.Printf("New version available: %s", u.Version)
default: // ignore
}
return nil
}
var errShouldUpdate = `
Your go-ipfs version is: %s
There is a new version available: %s
Since this is alpha software, it is strongly recommended you update.
To update, run:
ipfs update apply
To disable this notice, run:
ipfs config Version.Check warn
`
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论