Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
ce62bed8
提交
ce62bed8
authored
7月 14, 2017
作者:
Kevin Atkinson
提交者:
Jeromy
9月 03, 2017
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Write the spec file during initialization only.
License: MIT Signed-off-by:
Kevin Atkinson
<
k@kevina.org
>
上级
d64ab3ce
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
36 行增加
和
28 行删除
+36
-28
datastores.go
repo/fsrepo/datastores.go
+6
-3
fsrepo.go
repo/fsrepo/fsrepo.go
+29
-24
fsrepo_test.go
repo/fsrepo/fsrepo_test.go
+1
-1
没有找到文件。
repo/fsrepo/datastores.go
浏览文件 @
ce62bed8
...
...
@@ -31,14 +31,17 @@ type DatastoreConfig interface {
Create
(
path
string
)
(
repo
.
Datastore
,
error
)
}
func
(
spec
DiskSpec
)
String
()
string
{
func
(
spec
DiskSpec
)
Bytes
()
[]
byte
{
b
,
err
:=
json
.
Marshal
(
spec
)
if
err
!=
nil
{
// should not happen
panic
(
err
)
}
b
=
bytes
.
TrimSpace
(
b
)
return
string
(
b
)
return
bytes
.
TrimSpace
(
b
)
}
func
(
spec
DiskSpec
)
String
()
string
{
return
string
(
spec
.
Bytes
())
}
var
datastores
map
[
string
]
ConfigFromMap
...
...
repo/fsrepo/fsrepo.go
浏览文件 @
ce62bed8
...
...
@@ -240,9 +240,29 @@ func initConfig(path string, conf *config.Config) error {
if
err
:=
serialize
.
WriteConfigFile
(
configFilename
,
conf
);
err
!=
nil
{
return
err
}
return
nil
}
func
initSpec
(
path
string
,
conf
map
[
string
]
interface
{})
error
{
fn
,
err
:=
config
.
Path
(
path
,
SpecFn
)
if
err
!=
nil
{
return
err
}
if
util
.
FileExists
(
fn
)
{
return
nil
}
dsc
,
err
:=
AnyDatastoreConfig
(
conf
)
if
err
!=
nil
{
return
err
}
bytes
:=
dsc
.
DiskSpec
()
.
Bytes
()
return
ioutil
.
WriteFile
(
fn
,
bytes
,
0600
)
}
// Init initializes a new FSRepo at the given path with the provided config.
// TODO add support for custom datastores.
func
Init
(
repoPath
string
,
conf
*
config
.
Config
)
error
{
...
...
@@ -260,6 +280,10 @@ func Init(repoPath string, conf *config.Config) error {
return
err
}
if
err
:=
initSpec
(
repoPath
,
conf
.
Datastore
.
Spec
);
err
!=
nil
{
return
err
}
if
err
:=
mfsr
.
RepoPath
(
repoPath
)
.
WriteVersion
(
RepoVersion
);
err
!=
nil
{
return
err
}
...
...
@@ -370,19 +394,13 @@ func (r *FSRepo) openDatastore() error {
spec
:=
dsc
.
DiskSpec
()
oldSpec
,
err
:=
r
.
readSpec
()
if
err
==
nil
{
if
oldSpec
!=
spec
.
String
()
{
return
fmt
.
Errorf
(
"Datastore configuration of '%s' does not match what is on disk '%s'"
,
oldSpec
,
spec
.
String
())
}
}
else
if
os
.
IsNotExist
(
err
)
{
err
:=
r
.
writeSpec
(
spec
.
String
())
if
err
!=
nil
{
return
err
}
}
else
{
if
err
!=
nil
{
return
err
}
if
oldSpec
!=
spec
.
String
()
{
return
fmt
.
Errorf
(
"Datastore configuration of '%s' does not match what is on disk '%s'"
,
oldSpec
,
spec
.
String
())
}
d
,
err
:=
dsc
.
Create
(
r
.
path
)
if
err
!=
nil
{
...
...
@@ -411,19 +429,6 @@ func (r *FSRepo) readSpec() (string, error) {
return
strings
.
TrimSpace
(
string
(
b
)),
nil
}
func
(
r
*
FSRepo
)
writeSpec
(
spec
string
)
error
{
fn
,
err
:=
config
.
Path
(
r
.
path
,
SpecFn
)
if
err
!=
nil
{
return
err
}
b
:=
[]
byte
(
spec
)
err
=
ioutil
.
WriteFile
(
fn
,
b
,
0600
)
if
err
!=
nil
{
return
err
}
return
nil
}
// Close closes the FSRepo, releasing held resources.
func
(
r
*
FSRepo
)
Close
()
error
{
packageLock
.
Lock
()
...
...
repo/fsrepo/fsrepo_test.go
浏览文件 @
ce62bed8
...
...
@@ -25,7 +25,7 @@ func TestInitIdempotence(t *testing.T) {
t
.
Parallel
()
path
:=
testRepoPath
(
""
,
t
)
for
i
:=
0
;
i
<
10
;
i
++
{
assert
.
Nil
(
Init
(
path
,
&
config
.
Config
{}),
t
,
"multiple calls to init should succeed"
)
assert
.
Nil
(
Init
(
path
,
&
config
.
Config
{
Datastore
:
config
.
DefaultDatastoreConfig
()
}),
t
,
"multiple calls to init should succeed"
)
}
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论