Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
11ee7503
提交
11ee7503
authored
2月 01, 2019
作者:
Łukasz Magiera
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
coreapi: use chan for returning results in Unixfs.Ls
License: MIT Signed-off-by:
Łukasz Magiera
<
magik6k@gmail.com
>
上级
fd51d4c3
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
16 行增加
和
13 行删除
+16
-13
unixfs.go
core/coreapi/interface/tests/unixfs.go
+10
-8
unixfs.go
core/coreapi/interface/unixfs.go
+1
-1
unixfs.go
core/coreapi/unixfs.go
+5
-4
没有找到文件。
core/coreapi/interface/tests/unixfs.go
浏览文件 @
11ee7503
...
@@ -754,18 +754,20 @@ func (tp *provider) TestLs(t *testing.T) {
...
@@ -754,18 +754,20 @@ func (tp *provider) TestLs(t *testing.T) {
t
.
Error
(
err
)
t
.
Error
(
err
)
}
}
if
len
(
links
)
!=
1
{
link
:=
<-
links
t
.
Fatalf
(
"expected 1 link, got %d"
,
len
(
links
))
if
link
.
Size
!=
23
{
t
.
Fatalf
(
"expected size = 23, got %d"
,
link
.
Size
)
}
}
if
link
s
[
0
]
.
Size
!=
23
{
if
link
.
Name
!=
"name-of-file"
{
t
.
Fatalf
(
"expected
size = 23, got %d"
,
links
[
0
]
.
Siz
e
)
t
.
Fatalf
(
"expected
name = name-of-file, got %s"
,
link
.
Nam
e
)
}
}
if
link
s
[
0
]
.
Name
!=
"name-of-file
"
{
if
link
.
Cid
.
String
()
!=
"QmX3qQVKxDGz3URVC3861Z3CKtQKGBn6ffXRBBWGMFz9Lr
"
{
t
.
Fatalf
(
"expected
name = name-of-file, got %s"
,
links
[
0
]
.
Name
)
t
.
Fatalf
(
"expected
cid = QmX3qQVKxDGz3URVC3861Z3CKtQKGBn6ffXRBBWGMFz9Lr, got %s"
,
link
.
Cid
)
}
}
if
links
[
0
]
.
Cid
.
String
()
!=
"QmX3qQVKxDGz3URVC3861Z3CKtQKGBn6ffXRBBWGMFz9Lr"
{
if
_
,
ok
:=
<-
links
;
ok
{
t
.
Fatalf
(
"expected cid = QmX3qQVKxDGz3URVC3861Z3CKtQKGBn6ffXRBBWGMFz9Lr, got %s"
,
links
[
0
]
.
Cid
)
t
.
Errorf
(
"didn't expect a second link"
)
}
}
}
}
func
(
tp
*
provider
)
TestEntriesExpired
(
t
*
testing
.
T
)
{
func
(
tp
*
provider
)
TestEntriesExpired
(
t
*
testing
.
T
)
{
...
...
core/coreapi/interface/unixfs.go
浏览文件 @
11ee7503
...
@@ -31,5 +31,5 @@ type UnixfsAPI interface {
...
@@ -31,5 +31,5 @@ type UnixfsAPI interface {
Get
(
context
.
Context
,
Path
)
(
files
.
Node
,
error
)
Get
(
context
.
Context
,
Path
)
(
files
.
Node
,
error
)
// Ls returns the list of links in a directory
// Ls returns the list of links in a directory
Ls
(
context
.
Context
,
Path
)
(
[]
*
ipld
.
Link
,
error
)
Ls
(
context
.
Context
,
Path
)
(
<-
chan
*
ipld
.
Link
,
error
)
}
}
core/coreapi/unixfs.go
浏览文件 @
11ee7503
...
@@ -143,7 +143,7 @@ func (api *UnixfsAPI) Get(ctx context.Context, p coreiface.Path) (files.Node, er
...
@@ -143,7 +143,7 @@ func (api *UnixfsAPI) Get(ctx context.Context, p coreiface.Path) (files.Node, er
// Ls returns the contents of an IPFS or IPNS object(s) at path p, with the format:
// Ls returns the contents of an IPFS or IPNS object(s) at path p, with the format:
// `<link base58 hash> <link size in bytes> <link name>`
// `<link base58 hash> <link size in bytes> <link name>`
func
(
api
*
UnixfsAPI
)
Ls
(
ctx
context
.
Context
,
p
coreiface
.
Path
)
(
[]
*
ipld
.
Link
,
error
)
{
func
(
api
*
UnixfsAPI
)
Ls
(
ctx
context
.
Context
,
p
coreiface
.
Path
)
(
<-
chan
*
ipld
.
Link
,
error
)
{
dagnode
,
err
:=
api
.
core
()
.
ResolveNode
(
ctx
,
p
)
dagnode
,
err
:=
api
.
core
()
.
ResolveNode
(
ctx
,
p
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
...
@@ -164,10 +164,11 @@ func (api *UnixfsAPI) Ls(ctx context.Context, p coreiface.Path) ([]*ipld.Link, e
...
@@ -164,10 +164,11 @@ func (api *UnixfsAPI) Ls(ctx context.Context, p coreiface.Path) ([]*ipld.Link, e
return
nil
,
err
return
nil
,
err
}
}
links
:=
make
(
[]
*
ipld
.
Link
,
len
(
ndlinks
))
links
:=
make
(
chan
*
ipld
.
Link
,
len
(
ndlinks
))
for
i
,
l
:=
range
ndlinks
{
for
_
,
l
:=
range
ndlinks
{
links
[
i
]
=
&
ipld
.
Link
{
Name
:
l
.
Name
,
Size
:
l
.
Size
,
Cid
:
l
.
Cid
}
links
<-
&
ipld
.
Link
{
Name
:
l
.
Name
,
Size
:
l
.
Size
,
Cid
:
l
.
Cid
}
}
}
close
(
links
)
return
links
,
nil
return
links
,
nil
}
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论