Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
d1b6ccaa
提交
d1b6ccaa
authored
2月 02, 2019
作者:
Łukasz Magiera
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
coreapi: stream only ls, handle storting in command
License: MIT Signed-off-by:
Łukasz Magiera
<
magik6k@gmail.com
>
上级
73f1e2db
隐藏空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
9 行增加
和
53 行删除
+9
-53
ls.go
core/commands/ls.go
+6
-6
unixfs.go
core/coreapi/interface/options/unixfs.go
+0
-14
unixfs.go
core/coreapi/interface/tests/unixfs.go
+1
-20
unixfs.go
core/coreapi/interface/unixfs.go
+2
-1
unixfs.go
core/coreapi/unixfs.go
+0
-12
没有找到文件。
core/commands/ls.go
浏览文件 @
d1b6ccaa
...
@@ -4,6 +4,7 @@ import (
...
@@ -4,6 +4,7 @@ import (
"fmt"
"fmt"
"io"
"io"
"os"
"os"
"sort"
"text/tabwriter"
"text/tabwriter"
cmdenv
"github.com/ipfs/go-ipfs/core/commands/cmdenv"
cmdenv
"github.com/ipfs/go-ipfs/core/commands/cmdenv"
...
@@ -112,6 +113,10 @@ The JSON output contains type information.
...
@@ -112,6 +113,10 @@ The JSON output contains type information.
return
nil
return
nil
},
func
(
i
int
)
{
},
func
(
i
int
)
{
// after each dir
// after each dir
sort
.
Slice
(
outputLinks
,
func
(
i
,
j
int
)
bool
{
return
outputLinks
[
i
]
.
Name
<
outputLinks
[
j
]
.
Name
})
output
[
i
]
=
LsObject
{
output
[
i
]
=
LsObject
{
Hash
:
paths
[
i
],
Hash
:
paths
[
i
],
Links
:
outputLinks
,
Links
:
outputLinks
,
...
@@ -131,7 +136,6 @@ The JSON output contains type information.
...
@@ -131,7 +136,6 @@ The JSON output contains type information.
}
}
results
,
err
:=
api
.
Unixfs
()
.
Ls
(
req
.
Context
,
p
,
results
,
err
:=
api
.
Unixfs
()
.
Ls
(
req
.
Context
,
p
,
options
.
Unixfs
.
Async
(
stream
),
options
.
Unixfs
.
ResolveType
(
resolveType
),
options
.
Unixfs
.
ResolveType
(
resolveType
),
options
.
Unixfs
.
ResolveSize
(
resolveSize
))
options
.
Unixfs
.
ResolveSize
(
resolveSize
))
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -156,11 +160,7 @@ The JSON output contains type information.
...
@@ -156,11 +160,7 @@ The JSON output contains type information.
}
}
dirDone
(
i
)
dirDone
(
i
)
}
}
if
err
:=
done
();
err
!=
nil
{
return
done
()
return
err
}
return
nil
},
},
PostRun
:
cmds
.
PostRunMap
{
PostRun
:
cmds
.
PostRunMap
{
cmds
.
CLI
:
func
(
res
cmds
.
Response
,
re
cmds
.
ResponseEmitter
)
error
{
cmds
.
CLI
:
func
(
res
cmds
.
Response
,
re
cmds
.
ResponseEmitter
)
error
{
...
...
core/coreapi/interface/options/unixfs.go
浏览文件 @
d1b6ccaa
...
@@ -43,8 +43,6 @@ type UnixfsAddSettings struct {
...
@@ -43,8 +43,6 @@ type UnixfsAddSettings struct {
}
}
type
UnixfsLsSettings
struct
{
type
UnixfsLsSettings
struct
{
Async
bool
ResolveType
bool
ResolveType
bool
ResolveSize
bool
ResolveSize
bool
}
}
...
@@ -132,8 +130,6 @@ func UnixfsAddOptions(opts ...UnixfsAddOption) (*UnixfsAddSettings, cid.Prefix,
...
@@ -132,8 +130,6 @@ func UnixfsAddOptions(opts ...UnixfsAddOption) (*UnixfsAddSettings, cid.Prefix,
func
UnixfsLsOptions
(
opts
...
UnixfsLsOption
)
(
*
UnixfsLsSettings
,
error
)
{
func
UnixfsLsOptions
(
opts
...
UnixfsLsOption
)
(
*
UnixfsLsSettings
,
error
)
{
options
:=
&
UnixfsLsSettings
{
options
:=
&
UnixfsLsSettings
{
Async
:
true
,
ResolveSize
:
true
,
ResolveSize
:
true
,
ResolveType
:
true
,
ResolveType
:
true
,
}
}
...
@@ -317,16 +313,6 @@ func (unixfsOpts) Nocopy(enable bool) UnixfsAddOption {
...
@@ -317,16 +313,6 @@ func (unixfsOpts) Nocopy(enable bool) UnixfsAddOption {
}
}
}
}
// Async tells ls to return results as soon as they are available, which can be
// useful for listing HAMT directories. When this option is set to true returned
// results won't be returned in order
func
(
unixfsOpts
)
Async
(
async
bool
)
UnixfsLsOption
{
return
func
(
settings
*
UnixfsLsSettings
)
error
{
settings
.
Async
=
async
return
nil
}
}
func
(
unixfsOpts
)
ResolveSize
(
resolve
bool
)
UnixfsLsOption
{
func
(
unixfsOpts
)
ResolveSize
(
resolve
bool
)
UnixfsLsOption
{
return
func
(
settings
*
UnixfsLsSettings
)
error
{
return
func
(
settings
*
UnixfsLsSettings
)
error
{
settings
.
ResolveSize
=
resolve
settings
.
ResolveSize
=
resolve
...
...
core/coreapi/interface/tests/unixfs.go
浏览文件 @
d1b6ccaa
...
@@ -749,7 +749,7 @@ func (tp *provider) TestLs(t *testing.T) {
...
@@ -749,7 +749,7 @@ func (tp *provider) TestLs(t *testing.T) {
t
.
Error
(
err
)
t
.
Error
(
err
)
}
}
links
,
err
:=
api
.
Unixfs
()
.
Ls
(
ctx
,
p
,
options
.
Unixfs
.
Async
(
false
)
)
links
,
err
:=
api
.
Unixfs
()
.
Ls
(
ctx
,
p
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Error
(
err
)
t
.
Error
(
err
)
}
}
...
@@ -767,25 +767,6 @@ func (tp *provider) TestLs(t *testing.T) {
...
@@ -767,25 +767,6 @@ func (tp *provider) TestLs(t *testing.T) {
if
_
,
ok
:=
<-
links
;
ok
{
if
_
,
ok
:=
<-
links
;
ok
{
t
.
Errorf
(
"didn't expect a second link"
)
t
.
Errorf
(
"didn't expect a second link"
)
}
}
links
,
err
=
api
.
Unixfs
()
.
Ls
(
ctx
,
p
,
options
.
Unixfs
.
Async
(
true
))
if
err
!=
nil
{
t
.
Error
(
err
)
}
link
=
(
<-
links
)
.
Link
if
link
.
Size
!=
23
{
t
.
Fatalf
(
"expected size = 23, got %d"
,
link
.
Size
)
}
if
link
.
Name
!=
"name-of-file"
{
t
.
Fatalf
(
"expected name = name-of-file, got %s"
,
link
.
Name
)
}
if
link
.
Cid
.
String
()
!=
"QmX3qQVKxDGz3URVC3861Z3CKtQKGBn6ffXRBBWGMFz9Lr"
{
t
.
Fatalf
(
"expected cid = QmX3qQVKxDGz3URVC3861Z3CKtQKGBn6ffXRBBWGMFz9Lr, got %s"
,
link
.
Cid
)
}
if
_
,
ok
:=
<-
links
;
ok
{
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
浏览文件 @
d1b6ccaa
...
@@ -38,6 +38,7 @@ type UnixfsAPI interface {
...
@@ -38,6 +38,7 @@ type UnixfsAPI interface {
// to operations performed on the returned file
// to operations performed on the returned file
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. Links aren't guaranteed to be
// returned in order
Ls
(
context
.
Context
,
Path
,
...
options
.
UnixfsLsOption
)
(
<-
chan
LsLink
,
error
)
Ls
(
context
.
Context
,
Path
,
...
options
.
UnixfsLsOption
)
(
<-
chan
LsLink
,
error
)
}
}
core/coreapi/unixfs.go
浏览文件 @
d1b6ccaa
...
@@ -167,10 +167,6 @@ func (api *UnixfsAPI) Ls(ctx context.Context, p coreiface.Path, opts ...options.
...
@@ -167,10 +167,6 @@ func (api *UnixfsAPI) Ls(ctx context.Context, p coreiface.Path, opts ...options.
return
nil
,
err
return
nil
,
err
}
}
if
!
settings
.
Async
{
return
uses
.
lsFromDir
(
ctx
,
dir
,
settings
)
}
return
uses
.
lsFromLinksAsync
(
ctx
,
dir
,
settings
)
return
uses
.
lsFromLinksAsync
(
ctx
,
dir
,
settings
)
}
}
...
@@ -234,14 +230,6 @@ func (api *UnixfsAPI) lsFromLinksAsync(ctx context.Context, dir uio.Directory, s
...
@@ -234,14 +230,6 @@ func (api *UnixfsAPI) lsFromLinksAsync(ctx context.Context, dir uio.Directory, s
return
out
,
nil
return
out
,
nil
}
}
func
(
api
*
UnixfsAPI
)
lsFromDir
(
ctx
context
.
Context
,
dir
uio
.
Directory
,
settings
*
options
.
UnixfsLsSettings
)
(
<-
chan
coreiface
.
LsLink
,
error
)
{
l
,
err
:=
dir
.
Links
(
ctx
)
if
err
!=
nil
{
return
nil
,
err
}
return
api
.
lsFromLinks
(
ctx
,
l
,
settings
)
}
func
(
api
*
UnixfsAPI
)
lsFromLinks
(
ctx
context
.
Context
,
ndlinks
[]
*
ipld
.
Link
,
settings
*
options
.
UnixfsLsSettings
)
(
<-
chan
coreiface
.
LsLink
,
error
)
{
func
(
api
*
UnixfsAPI
)
lsFromLinks
(
ctx
context
.
Context
,
ndlinks
[]
*
ipld
.
Link
,
settings
*
options
.
UnixfsLsSettings
)
(
<-
chan
coreiface
.
LsLink
,
error
)
{
links
:=
make
(
chan
coreiface
.
LsLink
,
len
(
ndlinks
))
links
:=
make
(
chan
coreiface
.
LsLink
,
len
(
ndlinks
))
for
_
,
l
:=
range
ndlinks
{
for
_
,
l
:=
range
ndlinks
{
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论