Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
4909c5a5
提交
4909c5a5
authored
1月 23, 2018
作者:
Steven Allen
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
correctly handle add flag constraints
License: MIT Signed-off-by:
Steven Allen
<
steven@stebalien.com
>
上级
fcef972c
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
57 行增加
和
18 行删除
+57
-18
add.go
core/commands/add.go
+57
-18
没有找到文件。
core/commands/add.go
浏览文件 @
4909c5a5
...
...
@@ -114,11 +114,11 @@ You can now check what blocks have been created by:
cmdkit
.
BoolOption
(
hiddenOptionName
,
"H"
,
"Include files that are hidden. Only takes effect on recursive add."
),
cmdkit
.
StringOption
(
chunkerOptionName
,
"s"
,
"Chunking algorithm, size-[bytes] or rabin-[min]-[avg]-[max]"
)
.
WithDefault
(
"size-262144"
),
cmdkit
.
BoolOption
(
pinOptionName
,
"Pin this object when adding."
)
.
WithDefault
(
true
),
cmdkit
.
BoolOption
(
rawLeavesOptionName
,
"Use raw blocks for leaf nodes. (experimental)"
),
cmdkit
.
BoolOption
(
noCopyOptionName
,
"Add the file using filestore. (experimental)"
),
cmdkit
.
BoolOption
(
rawLeavesOptionName
,
"Use raw blocks for leaf nodes.
Implies CIDv1, defaults to on if CIDv1 is enabled.
(experimental)"
),
cmdkit
.
BoolOption
(
noCopyOptionName
,
"Add the file using filestore.
Implies raw-leaves.
(experimental)"
),
cmdkit
.
BoolOption
(
fstoreCacheOptionName
,
"Check the filestore for pre-existing blocks. (experimental)"
),
cmdkit
.
IntOption
(
cidVersionOptionName
,
"C
id version. Non-zero value will change default of 'raw-leaves' to true. (experimental)"
)
.
WithDefault
(
0
),
cmdkit
.
StringOption
(
hashOptionName
,
"Hash function to use.
Will set Cid version to 1 if used
. (experimental)"
)
.
WithDefault
(
"sha2-256"
),
cmdkit
.
IntOption
(
cidVersionOptionName
,
"C
ID version. Defaults to 0 unless an option that depends on CIDv1 is passed. (experimental)"
),
cmdkit
.
StringOption
(
hashOptionName
,
"Hash function to use.
Implies CIDv1 if not sha2-256
. (experimental)"
)
.
WithDefault
(
"sha2-256"
),
},
PreRun
:
func
(
req
*
cmds
.
Request
,
env
cmds
.
Environment
)
error
{
quiet
,
_
:=
req
.
Options
[
quietOptionName
]
.
(
bool
)
...
...
@@ -170,31 +170,70 @@ You can now check what blocks have been created by:
rawblks
,
rbset
:=
req
.
Options
[
rawLeavesOptionName
]
.
(
bool
)
nocopy
,
_
:=
req
.
Options
[
noCopyOptionName
]
.
(
bool
)
fscache
,
_
:=
req
.
Options
[
fstoreCacheOptionName
]
.
(
bool
)
cidVer
,
_
:=
req
.
Options
[
cidVersionOptionName
]
.
(
int
)
hashFunStr
,
hfset
:=
req
.
Options
[
hashOptionName
]
.
(
string
)
cidVer
,
cidVerSet
:=
req
.
Options
[
cidVersionOptionName
]
.
(
int
)
hashFunStr
,
_
:=
req
.
Options
[
hashOptionName
]
.
(
string
)
// Given the following constraints:
//
// nocopy -> filestoreEnabled
// nocopy -> rawblocks
// rawblocks -> cidv1
// (hash != sha2-256) -> cidv1
//
// We solve for the values of rawblocks and cidv1 in the
// following order of preference:
//
// 1. If cidv1 isn't fixed, set it to false and try solving.
// 2. If rawblocks isn't fixed, set it to true and try solving.
//
// If neither solution works, give up (we have a conflict).
// nocopy -> filestorEnabled
if
nocopy
&&
!
cfg
.
Experimental
.
FilestoreEnabled
{
res
.
SetError
(
errors
.
New
(
"filestore is not enabled, see https://git.io/vy4XN"
),
cmdkit
.
ErrClient
)
return
}
if
hfset
&&
hashFunStr
!=
"sha2-256"
&&
cidVer
==
0
{
cidVer
=
1
}
if
cidVer
>
0
&&
!
rbset
{
// nocopy -> rawblocks
if
nocopy
&&
!
rawblks
{
// fixed?
if
rbset
{
res
.
SetError
(
fmt
.
Errorf
(
"nocopy option requires '--raw-leaves' to be enabled as well"
),
cmdkit
.
ErrNormal
,
)
return
}
// No, satisfy mandatory constraint.
rawblks
=
true
}
// if rawblocks is not explicitly set but nocopy is, set rawblocks
if
nocopy
&&
!
rbset
{
rawblks
=
true
if
!
cidVerSet
{
// Default to CIDv0 if possible.
// Conditions: no raw blocks, sha2-256
if
hashFunStr
==
"sha2-256"
&&
!
rawblks
{
cidVer
=
0
}
else
{
cidVer
=
1
}
}
else
if
cidVer
==
0
{
// CIDv0 *was* set...
if
hashFunStr
!=
"sha2-256"
{
res
.
SetError
(
errors
.
New
(
"CIDv0 only supports sha2-256"
),
cmdkit
.
ErrClient
)
return
}
else
if
rawblks
{
res
.
SetError
(
errors
.
New
(
"CIDv0 incompatible with raw-leaves and/or nocopy"
),
cmdkit
.
ErrClient
,
)
return
}
}
if
nocopy
&&
!
rawblks
{
res
.
SetError
(
fmt
.
Errorf
(
"nocopy option requires '--raw-leaves' to be enabled as well"
),
cmdkit
.
ErrNormal
)
r
eturn
// cidV1 -> raw blocks (by default)
if
cidVer
>
0
&&
!
rbset
{
r
awblks
=
true
}
prefix
,
err
:=
dag
.
PrefixForCidVersion
(
cidVer
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论