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-dms3
Commits
24f319b5
Commit
24f319b5
authored
10 years ago
by
Juan Batiz-Benet
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #268 from jbenet/config-version-init
Initialize Config Version
parents
98ebe2f3
c6b74207
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
80 additions
and
74 deletions
+80
-74
cmd/ipfs/init.go
cmd/ipfs/init.go
+1
-5
cmd/ipfs/version.go
cmd/ipfs/version.go
+4
-3
config/version.go
config/version.go
+37
-28
config/version_test.go
config/version_test.go
+6
-6
net/handshake/handshake1.go
net/handshake/handshake1.go
+2
-2
updates/updates.go
updates/updates.go
+7
-7
updates/updates_test.go
updates/updates_test.go
+23
-23
No files found.
cmd/ipfs/init.go
View file @
24f319b5
...
...
@@ -11,7 +11,6 @@ import (
config
"github.com/jbenet/go-ipfs/config"
ci
"github.com/jbenet/go-ipfs/crypto"
peer
"github.com/jbenet/go-ipfs/peer"
updates
"github.com/jbenet/go-ipfs/updates"
u
"github.com/jbenet/go-ipfs/util"
)
...
...
@@ -137,10 +136,7 @@ func initCmd(c *commander.Command, inp []string) error {
}
// tracking ipfs version used to generate the init folder and adding update checker default setting.
cfg
.
Version
=
config
.
Version
{
Check
:
"error"
,
Current
:
updates
.
Version
,
}
cfg
.
Version
=
config
.
VersionDefaultValue
()
err
=
config
.
WriteConfigFile
(
filename
,
cfg
)
if
err
!=
nil
{
...
...
This diff is collapsed.
Click to expand it.
cmd/ipfs/version.go
View file @
24f319b5
package
main
import
(
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/commander"
updates
"github.com/jbenet/go-ipfs/updates"
config
"github.com/jbenet/go-ipfs/config"
u
"github.com/jbenet/go-ipfs/util"
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/commander"
)
var
cmdIpfsVersion
=
&
commander
.
Command
{
...
...
@@ -25,6 +26,6 @@ func versionCmd(c *commander.Command, _ []string) error {
if
!
number
{
u
.
POut
(
"ipfs version "
)
}
u
.
POut
(
"%s
\n
"
,
updates
.
Version
)
u
.
POut
(
"%s
\n
"
,
config
.
Current
Version
Number
)
return
nil
}
This diff is collapsed.
Click to expand it.
config/version.go
View file @
24f319b5
...
...
@@ -7,6 +7,9 @@ import (
"time"
)
// CurrentVersionNumber is the current application's version literal
const
CurrentVersionNumber
=
"0.1.5"
// Version regulates checking if the most recent version is run
type
Version
struct
{
// Current is the ipfs version for which config was generated
...
...
@@ -42,27 +45,36 @@ const (
)
// AutoUpdateSetting implements json.Unmarshaler to check values in config
// supported values:
// "never" - do not auto-update
// "patch" - auto-update on new patch versions
// "minor" - auto-update on new minor (or patch) versions (Default)
// "major" - auto-update on any new version
type
AutoUpdateSetting
int
// AutoUpdateSetting values
const
(
AutoUpdateNever
AutoUpdateSetting
=
iota
// do not auto-update
AutoUpdatePatch
// only on new patch versions
AutoUpdateMinor
// on new minor or patch versions (Default)
AutoUpdateMajor
// on all, even Major, version changes
)
// ErrUnknownAutoUpdateSetting is returned when an unknown value is read from the config
var
ErrUnknownAutoUpdateSetting
=
errors
.
New
(
"unknown value for AutoUpdate"
)
// defaultCheckPeriod governs h
var
defaultCheckPeriod
=
time
.
Hour
*
48
// UnmarshalJSON checks the input against known strings
func
(
s
*
AutoUpdateSetting
)
UnmarshalJSON
(
in
[]
byte
)
error
{
switch
strings
.
ToLower
(
string
(
in
))
{
case
`"never"`
:
*
s
=
UpdateNever
*
s
=
Auto
UpdateNever
case
`"major"`
:
*
s
=
UpdateMajor
*
s
=
Auto
UpdateMajor
case
`"minor"`
:
*
s
=
UpdateMinor
*
s
=
Auto
UpdateMinor
case
`"patch"`
:
*
s
=
UpdatePatch
*
s
=
Auto
UpdatePatch
default
:
*
s
=
UpdateMinor
*
s
=
Auto
UpdateMinor
return
ErrUnknownAutoUpdateSetting
}
return
nil
...
...
@@ -76,32 +88,19 @@ func (s AutoUpdateSetting) MarshalJSON() ([]byte, error) {
// String converts valye to human readable string
func
(
s
AutoUpdateSetting
)
String
()
string
{
switch
s
{
case
UpdateNever
:
case
Auto
UpdateNever
:
return
"never"
case
UpdateMajor
:
case
Auto
UpdateMajor
:
return
"major"
case
UpdateMinor
:
case
Auto
UpdateMinor
:
return
"minor"
case
UpdatePatch
:
case
Auto
UpdatePatch
:
return
"patch"
default
:
return
ErrUnknownAutoUpdateSetting
.
Error
()
}
}
// ErrUnknownAutoUpdateSetting is returned when an unknown value is read from the config
var
ErrUnknownAutoUpdateSetting
=
errors
.
New
(
"unknown value for AutoUpdate"
)
const
(
UpdateMinor
AutoUpdateSetting
=
iota
// first value so that it is the zero value and thus the default
UpdatePatch
UpdateMajor
UpdateNever
)
// defaultCheckPeriod governs h
var
defaultCheckPeriod
=
time
.
Hour
*
48
func
(
v
*
Version
)
checkPeriodDuration
()
time
.
Duration
{
d
,
err
:=
strconv
.
Atoi
(
v
.
CheckPeriod
)
if
err
!=
nil
{
...
...
@@ -128,8 +127,18 @@ func RecordUpdateCheck(cfg *Config, filename string) {
if
cfg
.
Version
.
CheckPeriod
==
""
{
// CheckPeriod was not initialized for some reason (e.g. config file broken)
cf
g
.
Version
.
CheckPeriod
=
strconv
.
Itoa
(
int
(
defaultCheckPeriod
)
)
log
.
Error
(
"confi
g.Version.CheckPeriod
not set. config broken?"
)
}
WriteConfigFile
(
filename
,
cfg
)
}
// VersionDefaultValue returns the default version config value (for init).
func
VersionDefaultValue
()
Version
{
return
Version
{
Current
:
CurrentVersionNumber
,
Check
:
"error"
,
CheckPeriod
:
strconv
.
Itoa
(
int
(
defaultCheckPeriod
)),
AutoUpdate
:
AutoUpdateMinor
,
}
}
This diff is collapsed.
Click to expand it.
config/version_test.go
View file @
24f319b5
...
...
@@ -14,12 +14,12 @@ func TestAutoUpdateValues(t *testing.T) {
val
AutoUpdateSetting
err
error
}{
{
`{"hello":123}`
,
Update
Mino
r
,
nil
},
//
default
{
`{"AutoUpdate": "never"}`
,
UpdateNever
,
nil
},
{
`{"AutoUpdate": "patch"}`
,
UpdatePatch
,
nil
},
{
`{"AutoUpdate": "minor"}`
,
UpdateMinor
,
nil
},
{
`{"AutoUpdate": "major"}`
,
UpdateMajor
,
nil
},
{
`{"AutoUpdate": "blarg"}`
,
UpdateMinor
,
ErrUnknownAutoUpdateSetting
},
{
`{"hello":123}`
,
Auto
Update
Neve
r
,
nil
},
//
zero value
{
`{"AutoUpdate": "never"}`
,
Auto
UpdateNever
,
nil
},
{
`{"AutoUpdate": "patch"}`
,
Auto
UpdatePatch
,
nil
},
{
`{"AutoUpdate": "minor"}`
,
Auto
UpdateMinor
,
nil
},
{
`{"AutoUpdate": "major"}`
,
Auto
UpdateMajor
,
nil
},
{
`{"AutoUpdate": "blarg"}`
,
Auto
UpdateMinor
,
ErrUnknownAutoUpdateSetting
},
}
for
i
,
tc
:=
range
tests
{
...
...
This diff is collapsed.
Click to expand it.
net/handshake/handshake1.go
View file @
24f319b5
...
...
@@ -4,15 +4,15 @@ import (
"errors"
"fmt"
config
"github.com/jbenet/go-ipfs/config"
pb
"github.com/jbenet/go-ipfs/net/handshake/pb"
updates
"github.com/jbenet/go-ipfs/updates"
semver
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/coreos/go-semver/semver"
)
// ipfsVersion holds the current protocol version for a client running this code
var
ipfsVersion
*
semver
.
Version
var
clientVersion
=
"go-ipfs/"
+
updates
.
Version
var
clientVersion
=
"go-ipfs/"
+
config
.
Current
Version
Number
func
init
()
{
var
err
error
...
...
This diff is collapsed.
Click to expand it.
updates/updates.go
View file @
24f319b5
...
...
@@ -5,7 +5,7 @@ import (
"os"
"time"
"github.com/jbenet/go-ipfs/config"
config
"github.com/jbenet/go-ipfs/config"
u
"github.com/jbenet/go-ipfs/util"
semver
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/coreos/go-semver/semver"
...
...
@@ -15,7 +15,7 @@ import (
const
(
// Version is the current application's version literal
Version
=
"0.1.5"
Version
=
config
.
CurrentVersionNumber
updateEndpointURL
=
"https://api.equinox.io/1/Updates"
updateAppID
=
"ap_YM8nz6rGm1UPg_bf63Lw6Vjz49"
...
...
@@ -150,7 +150,7 @@ func Apply(rel *check.Result) error {
// ShouldAutoUpdate decides wether a new version should be applied
// checks against config setting and new version string. returns false in case of error
func
ShouldAutoUpdate
(
setting
config
.
AutoUpdateSetting
,
newVer
string
)
bool
{
if
setting
==
config
.
UpdateNever
{
if
setting
==
config
.
Auto
UpdateNever
{
return
false
}
...
...
@@ -165,7 +165,7 @@ func ShouldAutoUpdate(setting config.AutoUpdateSetting, newVer string) bool {
switch
setting
{
case
config
.
UpdatePatch
:
case
config
.
Auto
UpdatePatch
:
if
n
[
0
]
<
c
[
0
]
{
return
false
}
...
...
@@ -176,14 +176,14 @@ func ShouldAutoUpdate(setting config.AutoUpdateSetting, newVer string) bool {
return
n
[
2
]
>
c
[
2
]
case
config
.
UpdateMinor
:
case
config
.
Auto
UpdateMinor
:
if
n
[
0
]
!=
c
[
0
]
{
return
false
}
return
n
[
1
]
>
c
[
1
]
||
(
n
[
1
]
==
c
[
1
]
&&
n
[
2
]
>
c
[
2
])
case
config
.
UpdateMajor
:
case
config
.
Auto
UpdateMajor
:
for
i
:=
0
;
i
<
3
;
i
++
{
if
n
[
i
]
<
c
[
i
]
{
return
false
...
...
@@ -222,7 +222,7 @@ func CliCheckForUpdates(cfg *config.Config, confFile string) error {
// there is an update available
// if we autoupdate
if
cfg
.
Version
.
AutoUpdate
!=
config
.
UpdateNever
{
if
cfg
.
Version
.
AutoUpdate
!=
config
.
Auto
UpdateNever
{
// and we should auto update
if
ShouldAutoUpdate
(
cfg
.
Version
.
AutoUpdate
,
u
.
Version
)
{
log
.
Noticef
(
"Applying update %s"
,
u
.
Version
)
...
...
This diff is collapsed.
Click to expand it.
updates/updates_test.go
View file @
24f319b5
...
...
@@ -21,29 +21,29 @@ func TestShouldAutoUpdate(t *testing.T) {
currV
,
newV
string
should
bool
}{
{
config
.
UpdateNever
,
"0.0.1"
,
"1.0.0"
,
false
},
{
config
.
UpdateNever
,
"0.0.1"
,
"0.1.0"
,
false
},
{
config
.
UpdateNever
,
"0.0.1"
,
"0.0.1"
,
false
},
{
config
.
UpdateNever
,
"0.0.1"
,
"0.0.2"
,
false
},
{
config
.
UpdatePatch
,
"0.0.1"
,
"1.0.0"
,
false
},
{
config
.
UpdatePatch
,
"0.0.1"
,
"0.1.0"
,
false
},
{
config
.
UpdatePatch
,
"0.0.1"
,
"0.0.1"
,
false
},
{
config
.
UpdatePatch
,
"0.0.2"
,
"0.0.1"
,
false
},
{
config
.
UpdatePatch
,
"0.0.1"
,
"0.0.2"
,
true
},
{
config
.
UpdateMinor
,
"0.1.1"
,
"1.0.0"
,
false
},
{
config
.
UpdateMinor
,
"0.1.1"
,
"0.2.0"
,
true
},
{
config
.
UpdateMinor
,
"0.1.1"
,
"0.1.2"
,
true
},
{
config
.
UpdateMinor
,
"0.2.1"
,
"0.1.9"
,
false
},
{
config
.
UpdateMinor
,
"0.1.2"
,
"0.1.1"
,
false
},
{
config
.
UpdateMajor
,
"1.0.0"
,
"2.0.0"
,
true
},
{
config
.
UpdateMajor
,
"1.0.0"
,
"1.1.0"
,
true
},
{
config
.
UpdateMajor
,
"1.0.0"
,
"1.0.1"
,
true
},
{
config
.
UpdateMajor
,
"2.0.0"
,
"1.0.0"
,
false
},
// don't downgrade
{
config
.
UpdateMajor
,
"2.5.0"
,
"2.4.0"
,
false
},
{
config
.
UpdateMajor
,
"2.0.2"
,
"2.0.1"
,
false
},
{
config
.
Auto
UpdateNever
,
"0.0.1"
,
"1.0.0"
,
false
},
{
config
.
Auto
UpdateNever
,
"0.0.1"
,
"0.1.0"
,
false
},
{
config
.
Auto
UpdateNever
,
"0.0.1"
,
"0.0.1"
,
false
},
{
config
.
Auto
UpdateNever
,
"0.0.1"
,
"0.0.2"
,
false
},
{
config
.
Auto
UpdatePatch
,
"0.0.1"
,
"1.0.0"
,
false
},
{
config
.
Auto
UpdatePatch
,
"0.0.1"
,
"0.1.0"
,
false
},
{
config
.
Auto
UpdatePatch
,
"0.0.1"
,
"0.0.1"
,
false
},
{
config
.
Auto
UpdatePatch
,
"0.0.2"
,
"0.0.1"
,
false
},
{
config
.
Auto
UpdatePatch
,
"0.0.1"
,
"0.0.2"
,
true
},
{
config
.
Auto
UpdateMinor
,
"0.1.1"
,
"1.0.0"
,
false
},
{
config
.
Auto
UpdateMinor
,
"0.1.1"
,
"0.2.0"
,
true
},
{
config
.
Auto
UpdateMinor
,
"0.1.1"
,
"0.1.2"
,
true
},
{
config
.
Auto
UpdateMinor
,
"0.2.1"
,
"0.1.9"
,
false
},
{
config
.
Auto
UpdateMinor
,
"0.1.2"
,
"0.1.1"
,
false
},
{
config
.
Auto
UpdateMajor
,
"1.0.0"
,
"2.0.0"
,
true
},
{
config
.
Auto
UpdateMajor
,
"1.0.0"
,
"1.1.0"
,
true
},
{
config
.
Auto
UpdateMajor
,
"1.0.0"
,
"1.0.1"
,
true
},
{
config
.
Auto
UpdateMajor
,
"2.0.0"
,
"1.0.0"
,
false
},
// don't downgrade
{
config
.
Auto
UpdateMajor
,
"2.5.0"
,
"2.4.0"
,
false
},
{
config
.
Auto
UpdateMajor
,
"2.0.2"
,
"2.0.1"
,
false
},
}
for
i
,
tc
:=
range
tests
{
...
...
This diff is collapsed.
Click to expand it.
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