Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
6ba45221
提交
6ba45221
authored
11月 04, 2014
作者:
Juan Batiz-Benet
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
config/version: Update_ -> AutoUpdate_
上级
b1958be8
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
57 行增加
和
61 行删除
+57
-61
version.go
config/version.go
+23
-27
version_test.go
config/version_test.go
+6
-6
updates.go
updates/updates.go
+5
-5
updates_test.go
updates/updates_test.go
+23
-23
没有找到文件。
config/version.go
浏览文件 @
6ba45221
...
...
@@ -42,27 +42,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 +85,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
{
...
...
config/version_test.go
浏览文件 @
6ba45221
...
...
@@ -14,12 +14,12 @@ func TestAutoUpdateValues(t *testing.T) {
val
AutoUpdateSetting
err
error
}{
{
`{"hello":123}`
,
UpdateMinor
,
nil
},
// default
{
`{"AutoUpdate": "never"}`
,
UpdateNever
,
nil
},
{
`{"AutoUpdate": "patch"}`
,
UpdatePatch
,
nil
},
{
`{"AutoUpdate": "minor"}`
,
UpdateMinor
,
nil
},
{
`{"AutoUpdate": "major"}`
,
UpdateMajor
,
nil
},
{
`{"AutoUpdate": "blarg"}`
,
UpdateMinor
,
ErrUnknownAutoUpdateSetting
},
{
`{"hello":123}`
,
AutoUpdateNever
,
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
{
...
...
updates/updates.go
浏览文件 @
6ba45221
...
...
@@ -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
)
...
...
updates/updates_test.go
浏览文件 @
6ba45221
...
...
@@ -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
{
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论