Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-unixfs
Commits
0a0c38fb
Commit
0a0c38fb
authored
Oct 20, 2014
by
Henry
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
using @jbenet's industrial lipstick to clean this up
parent
0115d1e0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
77 additions
and
33 deletions
+77
-33
cmd/ipfs/ipfs.go
cmd/ipfs/ipfs.go
+2
-33
updates/updates.go
updates/updates.go
+75
-0
No files found.
cmd/ipfs/ipfs.go
View file @
0a0c38fb
...
...
@@ -5,10 +5,8 @@ import (
"fmt"
"os"
"runtime/pprof"
"time"
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"
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) {
return
nil
,
err
}
if
cfg
.
Version
.
ShouldCheckForUpdate
()
{
log
.
Info
(
"checking for update"
)
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
)
}
}
}
if
err
:=
updates
.
CliCheckForUpdates
(
cfg
,
filename
);
err
!=
nil
{
return
nil
,
err
}
return
core
.
NewIpfsNode
(
cfg
,
online
)
...
...
updates/updates.go
View file @
0a0c38fb
...
...
@@ -3,6 +3,7 @@ package updates
import
(
"fmt"
"os"
"time"
"github.com/jbenet/go-ipfs/config"
u
"github.com/jbenet/go-ipfs/util"
...
...
@@ -122,3 +123,77 @@ func ShouldAutoUpdate(setting config.AutoUpdateSetting, newVer string) bool {
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
`
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment