Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
4bbd0018
提交
4bbd0018
authored
5月 13, 2017
作者:
Kevin Atkinson
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
adder: add support for specifying the hash function
License: MIT Signed-off-by:
Kevin Atkinson
<
k@kevina.org
>
上级
e23dbd29
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
36 行增加
和
0 行删除
+36
-0
add.go
core/commands/add.go
+18
-0
t0040-add-and-cat.sh
test/sharness/t0040-add-and-cat.sh
+18
-0
没有找到文件。
core/commands/add.go
浏览文件 @
4bbd0018
...
@@ -4,6 +4,7 @@ import (
...
@@ -4,6 +4,7 @@ import (
"errors"
"errors"
"fmt"
"fmt"
"io"
"io"
"strings"
bstore
"github.com/ipfs/go-ipfs/blocks/blockstore"
bstore
"github.com/ipfs/go-ipfs/blocks/blockstore"
blockservice
"github.com/ipfs/go-ipfs/blockservice"
blockservice
"github.com/ipfs/go-ipfs/blockservice"
...
@@ -17,6 +18,7 @@ import (
...
@@ -17,6 +18,7 @@ import (
mfs
"github.com/ipfs/go-ipfs/mfs"
mfs
"github.com/ipfs/go-ipfs/mfs"
ft
"github.com/ipfs/go-ipfs/unixfs"
ft
"github.com/ipfs/go-ipfs/unixfs"
mh
"gx/ipfs/QmVGtdTZdTFaLsaj2RwdVG8jcjNNcp1DE914DKZ2kHmXHw/go-multihash"
u
"gx/ipfs/QmWbjfz3u6HkAdPh34dgPchGbQjob6LXLhAeCGii2TX69n/go-ipfs-util"
u
"gx/ipfs/QmWbjfz3u6HkAdPh34dgPchGbQjob6LXLhAeCGii2TX69n/go-ipfs-util"
"gx/ipfs/QmeWjRodbcZFKe5tMN7poEx3izym6osrLSnTLf9UjJZBbs/pb"
"gx/ipfs/QmeWjRodbcZFKe5tMN7poEx3izym6osrLSnTLf9UjJZBbs/pb"
)
)
...
@@ -39,6 +41,7 @@ const (
...
@@ -39,6 +41,7 @@ const (
noCopyOptionName
=
"nocopy"
noCopyOptionName
=
"nocopy"
fstoreCacheOptionName
=
"fscache"
fstoreCacheOptionName
=
"fscache"
cidVersionOptionName
=
"cid-version"
cidVersionOptionName
=
"cid-version"
hashOptionName
=
"hash"
)
)
const
adderOutChanSize
=
8
const
adderOutChanSize
=
8
...
@@ -90,6 +93,7 @@ You can now refer to the added file in a gateway, like so:
...
@@ -90,6 +93,7 @@ You can now refer to the added file in a gateway, like so:
cmds
.
BoolOption
(
noCopyOptionName
,
"Add the file using filestore. (experimental)"
),
cmds
.
BoolOption
(
noCopyOptionName
,
"Add the file using filestore. (experimental)"
),
cmds
.
BoolOption
(
fstoreCacheOptionName
,
"Check the filestore for pre-existing blocks. (experimental)"
),
cmds
.
BoolOption
(
fstoreCacheOptionName
,
"Check the filestore for pre-existing blocks. (experimental)"
),
cmds
.
IntOption
(
cidVersionOptionName
,
"Cid version. Non-zero value will change default of 'raw-leaves' to true. (experimental)"
)
.
Default
(
0
),
cmds
.
IntOption
(
cidVersionOptionName
,
"Cid version. Non-zero value will change default of 'raw-leaves' to true. (experimental)"
)
.
Default
(
0
),
cmds
.
StringOption
(
hashOptionName
,
"Hash function to use. Will set Cid version to 1 if used. (experimental)"
)
.
Default
(
"sha2-256"
),
},
},
PreRun
:
func
(
req
cmds
.
Request
)
error
{
PreRun
:
func
(
req
cmds
.
Request
)
error
{
quiet
,
_
,
_
:=
req
.
Option
(
quietOptionName
)
.
Bool
()
quiet
,
_
,
_
:=
req
.
Option
(
quietOptionName
)
.
Bool
()
...
@@ -164,6 +168,7 @@ You can now refer to the added file in a gateway, like so:
...
@@ -164,6 +168,7 @@ You can now refer to the added file in a gateway, like so:
nocopy
,
_
,
_
:=
req
.
Option
(
noCopyOptionName
)
.
Bool
()
nocopy
,
_
,
_
:=
req
.
Option
(
noCopyOptionName
)
.
Bool
()
fscache
,
_
,
_
:=
req
.
Option
(
fstoreCacheOptionName
)
.
Bool
()
fscache
,
_
,
_
:=
req
.
Option
(
fstoreCacheOptionName
)
.
Bool
()
cidVer
,
_
,
_
:=
req
.
Option
(
cidVersionOptionName
)
.
Int
()
cidVer
,
_
,
_
:=
req
.
Option
(
cidVersionOptionName
)
.
Int
()
hashFunStr
,
hfset
,
_
:=
req
.
Option
(
hashOptionName
)
.
String
()
if
nocopy
&&
!
cfg
.
Experimental
.
FilestoreEnabled
{
if
nocopy
&&
!
cfg
.
Experimental
.
FilestoreEnabled
{
res
.
SetError
(
errors
.
New
(
"filestore is not enabled, see https://git.io/vy4XN"
),
res
.
SetError
(
errors
.
New
(
"filestore is not enabled, see https://git.io/vy4XN"
),
...
@@ -180,6 +185,10 @@ You can now refer to the added file in a gateway, like so:
...
@@ -180,6 +185,10 @@ You can now refer to the added file in a gateway, like so:
return
return
}
}
if
hfset
&&
cidVer
==
0
{
cidVer
=
1
}
if
cidVer
>=
1
&&
!
rbset
{
if
cidVer
>=
1
&&
!
rbset
{
rawblks
=
true
rawblks
=
true
}
}
...
@@ -190,6 +199,15 @@ You can now refer to the added file in a gateway, like so:
...
@@ -190,6 +199,15 @@ You can now refer to the added file in a gateway, like so:
return
return
}
}
hashFunCode
,
ok
:=
mh
.
Names
[
strings
.
ToLower
(
hashFunStr
)]
if
!
ok
{
res
.
SetError
(
fmt
.
Errorf
(
"unrecognized hash function: %s"
,
strings
.
ToLower
(
hashFunStr
)),
cmds
.
ErrNormal
)
return
}
prefix
.
MhType
=
hashFunCode
prefix
.
MhLength
=
-
1
if
hash
{
if
hash
{
nilnode
,
err
:=
core
.
NewNode
(
n
.
Context
(),
&
core
.
BuildCfg
{
nilnode
,
err
:=
core
.
NewNode
(
n
.
Context
(),
&
core
.
BuildCfg
{
//TODO: need this to be true or all files
//TODO: need this to be true or all files
...
...
test/sharness/t0040-add-and-cat.sh
浏览文件 @
4bbd0018
...
@@ -403,6 +403,10 @@ MARS="zdj7WWx6fGNrNGkdpkuTAxCjKbQ1pPtarqA6VQhedhLTZu34J"
...
@@ -403,6 +403,10 @@ MARS="zdj7WWx6fGNrNGkdpkuTAxCjKbQ1pPtarqA6VQhedhLTZu34J"
VENUS
=
"zdj7WbB1BUF8WejmVpQCmMLd1RbPnxJtvAj1Lep6eTmXRFbrz"
VENUS
=
"zdj7WbB1BUF8WejmVpQCmMLd1RbPnxJtvAj1Lep6eTmXRFbrz"
add_directory
'--cid-version=1 --raw-leaves=false'
add_directory
'--cid-version=1 --raw-leaves=false'
PLANETS
=
"zDMZof1kqxDAx9myQbXsyWwyWP9qRPsXsWH7XuTz6isT7Rh1S6nM"
MARS
=
"zCT5htkdz1ZBHYVQXFQn51ngPXLVqaHSWoae87V1d6e9qWpSAjXw"
VENUS
=
"zCT5htke5JcdoMM4WhmUKXWf2QC3TnQToqGZHH1WsZERv6kPhFPg"
add_directory
'--hash=blake2b-256'
test_expect_success
"'ipfs add -rn' succeeds"
'
test_expect_success
"'ipfs add -rn' succeeds"
'
mkdir -p mountdir/moons/jupiter &&
mkdir -p mountdir/moons/jupiter &&
...
@@ -446,12 +450,26 @@ test_add_cat_5MB --cid-version=1 "zdj7WiiaedqVBXjX4SNqx3jfuZideDqdLYnDzCDJ66JDMK
...
@@ -446,12 +450,26 @@ test_add_cat_5MB --cid-version=1 "zdj7WiiaedqVBXjX4SNqx3jfuZideDqdLYnDzCDJ66JDMK
# format (i.e. not raw)
# format (i.e. not raw)
test_add_cat_5MB
'--cid-version=1 --raw-leaves=false'
"zdj7WfgEsj897BBZj2mcfsRLhaPZcCixPV2G7DkWgF1Wdr64P"
test_add_cat_5MB
'--cid-version=1 --raw-leaves=false'
"zdj7WfgEsj897BBZj2mcfsRLhaPZcCixPV2G7DkWgF1Wdr64P"
# note: --hash=blake2b-256 implies --cid-version=1 which implies --raw-leaves=true
# the specified hash represents the leaf nodes stored as raw leaves and
# encoded with the blake2b-256 hash funtion
test_add_cat_5MB
'--hash=blake2b-256'
"zDMZof1kuxn7ebvKyvmkYLPvocSvFYxxAWT1yQBN1wWiXXr7w5mY"
# the specified hash represents the leaf nodes stored as protoful nodes and
# encoded with the blake2b-256 hash funtion
test_add_cat_5MB
'--hash=blake2b-256 --raw-leaves=false'
"zDMZof1krz3SFTyhboRyWZyUP2qNgVdn9wjtaX211aHJ8WgeyT9v"
test_add_cat_expensive
""
"QmU9SWAPPmNEKZB8umYMmjYvN7VyHqABNvdA6GUi4MMEz3"
test_add_cat_expensive
""
"QmU9SWAPPmNEKZB8umYMmjYvN7VyHqABNvdA6GUi4MMEz3"
# note: the specified hash implies that internal nodes are stored
# note: the specified hash implies that internal nodes are stored
# using CidV1 and leaves are stored using raw blocks
# using CidV1 and leaves are stored using raw blocks
test_add_cat_expensive
"--cid-version=1"
"zdj7WcatQrtuE4WMkS4XsfsMixuQN2po4irkYhqxeJyW1wgCq"
test_add_cat_expensive
"--cid-version=1"
"zdj7WcatQrtuE4WMkS4XsfsMixuQN2po4irkYhqxeJyW1wgCq"
# note: --hash=blake2b-256 implies --cid-version=1 which implies --raw-leaves=true
# the specified hash represents the leaf nodes stored as raw leaves and
# encoded with the blake2b-256 hash funtion
test_add_cat_expensive
'--hash=blake2b-256'
"zDMZof1kwndounDzQCANUHjiE3zt1mPEgx7RE3JTHoZrRRa79xcv"
test_add_named_pipe
" Post http://
$API_ADDR
/api/v0/add?encoding=json&progress=true&r=true&stream-channels=true:"
test_add_named_pipe
" Post http://
$API_ADDR
/api/v0/add?encoding=json&progress=true&r=true&stream-channels=true:"
test_add_pwd_is_symlink
test_add_pwd_is_symlink
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论