Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
e49ce6c9
提交
e49ce6c9
authored
10月 02, 2017
作者:
Jeromy Johnson
提交者:
GitHub
10月 02, 2017
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #4254 from ipfs/feat/dag-batch
dag: Support multiple files in put
上级
29fa375a
f5cbc4c8
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
89 行增加
和
43 行删除
+89
-43
dag.go
core/commands/dag/dag.go
+74
-41
t0053-dag.sh
test/sharness/t0053-dag.sh
+15
-2
没有找到文件。
core/commands/dag/dag.go
浏览文件 @
e49ce6c9
...
@@ -8,11 +8,13 @@ import (
...
@@ -8,11 +8,13 @@ import (
"strings"
"strings"
cmds
"github.com/ipfs/go-ipfs/commands"
cmds
"github.com/ipfs/go-ipfs/commands"
files
"github.com/ipfs/go-ipfs/commands/files"
coredag
"github.com/ipfs/go-ipfs/core/coredag"
coredag
"github.com/ipfs/go-ipfs/core/coredag"
path
"github.com/ipfs/go-ipfs/path"
path
"github.com/ipfs/go-ipfs/path"
pin
"github.com/ipfs/go-ipfs/pin"
pin
"github.com/ipfs/go-ipfs/pin"
cid
"gx/ipfs/QmNp85zy9RLrQ5oQD4hPyS39ezrrXpcaa7R4Y9kxdWQLLQ/go-cid"
cid
"gx/ipfs/QmNp85zy9RLrQ5oQD4hPyS39ezrrXpcaa7R4Y9kxdWQLLQ/go-cid"
u
"gx/ipfs/QmSU6eubNdhXjFBJBSksTp8kv8YRub8mGAPv8tVJHmL2EU/go-ipfs-util"
mh
"gx/ipfs/QmU9a9NV9RdPNwZQDYd5uKsm6N6LJLSvLbywDDYFbaaC6P/go-multihash"
mh
"gx/ipfs/QmU9a9NV9RdPNwZQDYd5uKsm6N6LJLSvLbywDDYFbaaC6P/go-multihash"
)
)
...
@@ -53,7 +55,7 @@ into an object of the specified format.
...
@@ -53,7 +55,7 @@ into an object of the specified format.
`
,
`
,
},
},
Arguments
:
[]
cmds
.
Argument
{
Arguments
:
[]
cmds
.
Argument
{
cmds
.
FileArg
(
"object data"
,
true
,
fals
e
,
"The object to put"
)
.
EnableStdin
(),
cmds
.
FileArg
(
"object data"
,
true
,
tru
e
,
"The object to put"
)
.
EnableStdin
(),
},
},
Options
:
[]
cmds
.
Option
{
Options
:
[]
cmds
.
Option
{
cmds
.
StringOption
(
"format"
,
"f"
,
"Format that the object will be added as."
)
.
Default
(
"cbor"
),
cmds
.
StringOption
(
"format"
,
"f"
,
"Format that the object will be added as."
)
.
Default
(
"cbor"
),
...
@@ -68,12 +70,6 @@ into an object of the specified format.
...
@@ -68,12 +70,6 @@ into an object of the specified format.
return
return
}
}
fi
,
err
:=
req
.
Files
()
.
NextFile
()
if
err
!=
nil
{
res
.
SetError
(
err
,
cmds
.
ErrNormal
)
return
}
ienc
,
_
,
_
:=
req
.
Option
(
"input-enc"
)
.
String
()
ienc
,
_
,
_
:=
req
.
Option
(
"input-enc"
)
.
String
()
format
,
_
,
_
:=
req
.
Option
(
"format"
)
.
String
()
format
,
_
,
_
:=
req
.
Option
(
"format"
)
.
String
()
hash
,
_
,
err
:=
req
.
Option
(
"hash"
)
.
String
()
hash
,
_
,
err
:=
req
.
Option
(
"hash"
)
.
String
()
...
@@ -96,56 +92,93 @@ into an object of the specified format.
...
@@ -96,56 +92,93 @@ into an object of the specified format.
}
}
}
}
if
dopin
{
outChan
:=
make
(
chan
interface
{},
8
)
defer
n
.
Blockstore
.
PinLock
()
.
Unlock
()
res
.
SetOutput
((
<-
chan
interface
{})(
outChan
))
}
nds
,
err
:=
coredag
.
ParseInputs
(
ienc
,
format
,
fi
,
mhType
,
-
1
)
addAllAndPin
:=
func
(
f
files
.
File
)
error
{
if
err
!=
nil
{
cids
:=
cid
.
NewSet
()
res
.
SetError
(
err
,
cmds
.
ErrNormal
)
b
:=
n
.
DAG
.
Batch
()
return
}
if
len
(
nds
)
==
0
{
res
.
SetError
(
fmt
.
Errorf
(
"no node returned from ParseInputs"
),
cmds
.
ErrNormal
)
return
}
b
:=
n
.
DAG
.
Batch
()
for
{
for
_
,
nd
:=
range
nds
{
file
,
err
:=
f
.
NextFile
()
_
,
err
:=
b
.
Add
(
nd
)
if
err
==
io
.
EOF
{
if
err
!=
nil
{
// Finished the list of files.
res
.
SetError
(
err
,
cmds
.
ErrNormal
)
break
return
}
else
if
err
!=
nil
{
return
err
}
nds
,
err
:=
coredag
.
ParseInputs
(
ienc
,
format
,
file
,
mhType
,
-
1
)
if
err
!=
nil
{
return
err
}
if
len
(
nds
)
==
0
{
return
fmt
.
Errorf
(
"no node returned from ParseInputs"
)
}
for
_
,
nd
:=
range
nds
{
_
,
err
:=
b
.
Add
(
nd
)
if
err
!=
nil
{
return
err
}
}
cid
:=
nds
[
0
]
.
Cid
()
cids
.
Add
(
cid
)
outChan
<-
&
OutputObject
{
Cid
:
cid
}
}
}
}
if
err
:=
b
.
Commit
();
err
!=
nil
{
if
err
:=
b
.
Commit
();
err
!=
nil
{
res
.
SetError
(
err
,
cmds
.
ErrNormal
)
return
err
return
}
}
root
:=
nds
[
0
]
.
Cid
()
if
dopin
{
if
dopin
{
defer
n
.
Blockstore
.
PinLock
()
.
Unlock
()
n
.
Pinning
.
PinWithMode
(
root
,
pin
.
Recursive
)
err
:=
n
.
Pinning
.
Flush
()
cids
.
ForEach
(
func
(
c
*
cid
.
Cid
)
error
{
if
err
!=
nil
{
n
.
Pinning
.
PinWithMode
(
c
,
pin
.
Recursive
)
res
.
SetError
(
err
,
cmds
.
ErrNormal
)
return
nil
return
})
err
:=
n
.
Pinning
.
Flush
()
if
err
!=
nil
{
return
err
}
}
}
return
nil
}
}
res
.
SetOutput
(
&
OutputObject
{
Cid
:
root
})
go
func
()
{
defer
close
(
outChan
)
if
err
:=
addAllAndPin
(
req
.
Files
());
err
!=
nil
{
res
.
SetError
(
err
,
cmds
.
ErrNormal
)
return
}
}()
},
},
Type
:
OutputObject
{},
Type
:
OutputObject
{},
Marshalers
:
cmds
.
MarshalerMap
{
Marshalers
:
cmds
.
MarshalerMap
{
cmds
.
Text
:
func
(
res
cmds
.
Response
)
(
io
.
Reader
,
error
)
{
cmds
.
Text
:
func
(
res
cmds
.
Response
)
(
io
.
Reader
,
error
)
{
o
obj
,
ok
:=
res
.
Output
()
.
(
*
OutputObject
)
o
utChan
,
ok
:=
res
.
Output
()
.
(
<-
chan
interface
{}
)
if
!
ok
{
if
!
ok
{
return
nil
,
fmt
.
Errorf
(
"expected a different object in marshaler"
)
return
nil
,
u
.
ErrCast
()
}
marshal
:=
func
(
v
interface
{})
(
io
.
Reader
,
error
)
{
obj
,
ok
:=
v
.
(
*
OutputObject
)
if
!
ok
{
return
nil
,
u
.
ErrCast
()
}
return
strings
.
NewReader
(
obj
.
Cid
.
String
()
+
"
\n
"
),
nil
}
}
return
strings
.
NewReader
(
oobj
.
Cid
.
String
()),
nil
return
&
cmds
.
ChannelMarshaler
{
Channel
:
outChan
,
Marshaler
:
marshal
,
Res
:
res
,
},
nil
},
},
},
},
}
}
...
...
test/sharness/t0053-dag.sh
浏览文件 @
e49ce6c9
...
@@ -153,7 +153,7 @@ test_dag_cmd() {
...
@@ -153,7 +153,7 @@ test_dag_cmd() {
'
'
test_expect_success
"dag put with dag-pb works output looks good"
'
test_expect_success
"dag put with dag-pb works output looks good"
'
printf
$HASH > dag_put_exp &&
echo
$HASH > dag_put_exp &&
test_cmp dag_put_exp dag_put_out
test_cmp dag_put_exp dag_put_out
'
'
...
@@ -163,7 +163,20 @@ test_dag_cmd() {
...
@@ -163,7 +163,20 @@ test_dag_cmd() {
'
'
test_expect_success
"dag put with dag-pb works output looks good"
'
test_expect_success
"dag put with dag-pb works output looks good"
'
printf $HASH > dag_put_exp &&
echo $HASH > dag_put_exp &&
test_cmp dag_put_exp dag_put_out
'
test_expect_success
"dag put multiple files"
'
printf {\"foo\":\"bar\"} > a.json &&
printf {\"foo\":\"baz\"} > b.json &&
ipfs dag put a.json b.json > dag_put_out
'
test_expect_success
"dag put multiple files output looks good"
'
echo zdpuAoKMEvka7gKGSjF9B3of1F5gE5MyMMywxTC13wCmouQrf > dag_put_exp &&
echo zdpuAogmDEvpvGjMFsNTGDEU1JMYe6v69oxR8nG81EurmGHMj >> dag_put_exp &&
test_cmp dag_put_exp dag_put_out
test_cmp dag_put_exp dag_put_out
'
'
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论