Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
8f1fd2fc
提交
8f1fd2fc
authored
10月 20, 2014
作者:
Henry
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
ShouldAutoUpdate function
上级
7ddf3836
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
99 行增加
和
1 行删除
+99
-1
version.go
config/version.go
+1
-0
updates.go
updates/updates.go
+49
-0
updates_test.go
updates/updates_test.go
+49
-1
没有找到文件。
config/version.go
浏览文件 @
8f1fd2fc
...
...
@@ -44,6 +44,7 @@ const (
)
// supported Version.AutoUpdate values
// BUG(cryptix): make this a custom type that implements json.Unmarshaller() to verify values
const
(
UpdateNever
=
"never"
UpdatePatch
=
"patch"
...
...
updates/updates.go
浏览文件 @
8f1fd2fc
...
...
@@ -4,6 +4,7 @@ import (
"fmt"
"os"
"github.com/jbenet/go-ipfs/config"
u
"github.com/jbenet/go-ipfs/util"
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/coreos/go-semver/semver"
...
...
@@ -60,3 +61,51 @@ func CheckForUpdate() (*check.Result, error) {
func
AbleToApply
()
error
{
return
update
.
New
()
.
CanUpdate
()
}
// 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
,
newVer
string
)
bool
{
if
setting
==
config
.
UpdateNever
{
return
false
}
nv
,
err
:=
semver
.
NewVersion
(
newVer
)
if
err
!=
nil
{
log
.
Error
(
"could not parse version string: %s"
,
err
)
return
false
}
n
:=
nv
.
Slice
()
c
:=
currentVersion
.
Slice
()
switch
setting
{
case
config
.
UpdatePatch
:
if
n
[
0
]
<
c
[
0
]
{
return
false
}
if
n
[
1
]
<
c
[
1
]
{
return
false
}
return
n
[
2
]
>
c
[
2
]
case
config
.
UpdateMinor
:
if
n
[
0
]
!=
c
[
0
]
{
return
false
}
return
n
[
1
]
>
c
[
1
]
||
(
n
[
1
]
==
c
[
1
]
&&
n
[
2
]
>
c
[
2
])
case
config
.
UpdateMajor
:
for
i
:=
0
;
i
<
3
;
i
++
{
if
n
[
i
]
<
c
[
i
]
{
return
false
}
}
return
true
}
return
false
}
updates/updates_test.go
浏览文件 @
8f1fd2fc
package
updates
import
"testing"
import
(
"testing"
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/coreos/go-semver/semver"
"github.com/jbenet/go-ipfs/config"
)
// TestParseVersion just makes sure that we dont commit a bad version number
func
TestParseVersion
(
t
*
testing
.
T
)
{
...
...
@@ -9,3 +14,46 @@ func TestParseVersion(t *testing.T) {
t
.
Fatal
(
err
)
}
}
func
TestShouldAutoUpdate
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
setting
,
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
},
}
for
i
,
tc
:=
range
tests
{
var
err
error
currentVersion
,
err
=
semver
.
NewVersion
(
tc
.
currV
)
if
err
!=
nil
{
t
.
Fatalf
(
"Could not parse test version: %v"
,
err
)
}
if
tc
.
should
!=
ShouldAutoUpdate
(
tc
.
setting
,
tc
.
newV
)
{
t
.
Fatalf
(
"#%d failed for %+v"
,
i
,
tc
)
}
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论