Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
5d9651a3
Unverified
提交
5d9651a3
authored
4月 25, 2019
作者:
Steven Allen
提交者:
GitHub
4月 25, 2019
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #6255 from ipfs/fix/add-many
add: Fix adding multiple files
上级
c1bc202f
ac51d299
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
62 行增加
和
46 行删除
+62
-46
add.go
core/commands/add.go
+52
-46
t0040-add-and-cat.sh
test/sharness/t0040-add-and-cat.sh
+10
-0
没有找到文件。
core/commands/add.go
浏览文件 @
5d9651a3
...
...
@@ -181,24 +181,12 @@ You can now check what blocks have been created by:
return
err
}
events
:=
make
(
chan
interface
{},
adderOutChanSize
)
var
toadd
files
.
Node
=
req
.
Files
name
:=
""
if
!
wrap
{
it
:=
req
.
Files
.
Entries
()
if
!
it
.
Next
()
{
err
:=
it
.
Err
()
if
err
==
nil
{
return
fmt
.
Errorf
(
"expected a file argument"
)
}
return
err
}
toadd
=
it
.
Node
()
name
=
it
.
Name
()
toadd
:=
req
.
Files
if
wrap
{
toadd
=
files
.
NewSliceDirectory
([]
files
.
DirEntry
{
files
.
FileEntry
(
""
,
req
.
Files
),
})
}
_
,
dir
:=
toadd
.
(
files
.
Directory
)
opts
:=
[]
options
.
UnixfsAddOption
{
options
.
Unixfs
.
Hash
(
hashFunCode
),
...
...
@@ -215,7 +203,6 @@ You can now check what blocks have been created by:
options
.
Unixfs
.
Progress
(
progress
),
options
.
Unixfs
.
Silent
(
silent
),
options
.
Unixfs
.
Events
(
events
),
}
if
cidVerSet
{
...
...
@@ -230,42 +217,61 @@ You can now check what blocks have been created by:
opts
=
append
(
opts
,
options
.
Unixfs
.
Layout
(
options
.
TrickleLayout
))
}
errCh
:=
make
(
chan
error
,
1
)
go
func
()
{
var
err
error
defer
func
()
{
errCh
<-
err
}()
defer
close
(
events
)
_
,
err
=
api
.
Unixfs
()
.
Add
(
req
.
Context
,
toadd
,
opts
...
)
}()
for
event
:=
range
events
{
output
,
ok
:=
event
.
(
*
coreiface
.
AddEvent
)
if
!
ok
{
return
errors
.
New
(
"unknown event type"
)
}
opts
=
append
(
opts
,
nil
)
// events option placeholder
h
:=
""
if
output
.
Path
!=
nil
{
h
=
enc
.
Encode
(
output
.
Path
.
Cid
())
}
var
added
int
addit
:=
toadd
.
Entries
()
for
addit
.
Next
()
{
_
,
dir
:=
addit
.
Node
()
.
(
files
.
Directory
)
errCh
:=
make
(
chan
error
,
1
)
events
:=
make
(
chan
interface
{},
adderOutChanSize
)
opts
[
len
(
opts
)
-
1
]
=
options
.
Unixfs
.
Events
(
events
)
go
func
()
{
var
err
error
defer
close
(
events
)
_
,
err
=
api
.
Unixfs
()
.
Add
(
req
.
Context
,
addit
.
Node
(),
opts
...
)
errCh
<-
err
}()
for
event
:=
range
events
{
output
,
ok
:=
event
.
(
*
coreiface
.
AddEvent
)
if
!
ok
{
return
errors
.
New
(
"unknown event type"
)
}
h
:=
""
if
output
.
Path
!=
nil
{
h
=
enc
.
Encode
(
output
.
Path
.
Cid
())
}
if
!
dir
&&
addit
.
Name
()
!=
""
{
output
.
Name
=
addit
.
Name
()
}
else
{
output
.
Name
=
path
.
Join
(
addit
.
Name
(),
output
.
Name
)
}
if
!
dir
&&
name
!=
""
{
output
.
Name
=
name
}
else
{
output
.
Name
=
path
.
Join
(
name
,
output
.
Name
)
if
err
:=
res
.
Emit
(
&
AddEvent
{
Name
:
output
.
Name
,
Hash
:
h
,
Bytes
:
output
.
Bytes
,
Size
:
output
.
Size
,
});
err
!=
nil
{
return
err
}
}
if
err
:=
res
.
Emit
(
&
AddEvent
{
Name
:
output
.
Name
,
Hash
:
h
,
Bytes
:
output
.
Bytes
,
Size
:
output
.
Size
,
});
err
!=
nil
{
if
err
:=
<-
errCh
;
err
!=
nil
{
return
err
}
added
++
}
return
<-
errCh
if
added
==
0
{
return
fmt
.
Errorf
(
"expected a file argument"
)
}
return
nil
},
PostRun
:
cmds
.
PostRunMap
{
cmds
.
CLI
:
func
(
res
cmds
.
Response
,
re
cmds
.
ResponseEmitter
)
error
{
...
...
test/sharness/t0040-add-and-cat.sh
浏览文件 @
5d9651a3
...
...
@@ -325,6 +325,16 @@ test_add_cat_file() {
test_cmp expected actual
'
test_expect_success
"ipfs add with multiple files succeeds"
'
echo "Helloo Worlds!" >mountdir/hello2.txt &&
ipfs add mountdir/hello.txt mountdir/hello2.txt >actual
'
test_expect_success
"ipfs add with multiple files output looks good"
'
echo "added QmVr26fY1tKyspEJBniVhqxQeEjhF78XerGiqWAwraVLQH hello.txt" >expected &&
echo "added Qmf35k66MZNW2GijohUmXQEWKZU4cCGTCwK6idfnt152wJ hello2.txt" >> expected &&
test_cmp expected actual
'
}
test_add_cat_5MB
()
{
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论