Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
6cc0903d
提交
6cc0903d
authored
1月 02, 2017
作者:
Kevin Atkinson
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix "ipfs ls" so it works correctly with raw leaves.
License: MIT Signed-off-by:
Kevin Atkinson
<
k@kevina.org
>
上级
3526c26f
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
32 行增加
和
30 行删除
+32
-30
ls.go
core/commands/ls.go
+19
-30
t0045-ls.sh
test/sharness/t0045-ls.sh
+13
-0
没有找到文件。
core/commands/ls.go
浏览文件 @
6cc0903d
...
@@ -6,8 +6,10 @@ import (
...
@@ -6,8 +6,10 @@ import (
"io"
"io"
"text/tabwriter"
"text/tabwriter"
blockservice
"github.com/ipfs/go-ipfs/blockservice"
cmds
"github.com/ipfs/go-ipfs/commands"
cmds
"github.com/ipfs/go-ipfs/commands"
core
"github.com/ipfs/go-ipfs/core"
core
"github.com/ipfs/go-ipfs/core"
offline
"github.com/ipfs/go-ipfs/exchange/offline"
merkledag
"github.com/ipfs/go-ipfs/merkledag"
merkledag
"github.com/ipfs/go-ipfs/merkledag"
path
"github.com/ipfs/go-ipfs/path"
path
"github.com/ipfs/go-ipfs/path"
unixfs
"github.com/ipfs/go-ipfs/unixfs"
unixfs
"github.com/ipfs/go-ipfs/unixfs"
...
@@ -71,6 +73,13 @@ The JSON output contains type information.
...
@@ -71,6 +73,13 @@ The JSON output contains type information.
return
return
}
}
dserv
:=
nd
.
DAG
if
!
resolve
{
offlineexch
:=
offline
.
Exchange
(
nd
.
Blockstore
)
bserv
:=
blockservice
.
New
(
nd
.
Blockstore
,
offlineexch
)
dserv
=
merkledag
.
NewDAGService
(
bserv
)
}
paths
:=
req
.
Arguments
()
paths
:=
req
.
Arguments
()
var
dagnodes
[]
node
.
Node
var
dagnodes
[]
node
.
Node
...
@@ -101,39 +110,19 @@ The JSON output contains type information.
...
@@ -101,39 +110,19 @@ The JSON output contains type information.
Links
:
make
([]
LsLink
,
len
(
dagnode
.
Links
())),
Links
:
make
([]
LsLink
,
len
(
dagnode
.
Links
())),
}
}
for
j
,
link
:=
range
dagnode
.
Links
()
{
for
j
,
link
:=
range
dagnode
.
Links
()
{
var
linkNode
*
merkledag
.
ProtoNode
t
:=
unixfspb
.
Data_DataType
(
-
1
)
t
:=
unixfspb
.
Data_DataType
(
-
1
)
linkKey
:=
link
.
Cid
if
ok
,
err
:=
nd
.
Blockstore
.
Has
(
linkKey
);
ok
&&
err
==
nil
{
b
,
err
:=
nd
.
Blockstore
.
Get
(
linkKey
)
if
err
!=
nil
{
res
.
SetError
(
err
,
cmds
.
ErrNormal
)
return
}
linkNode
,
err
=
merkledag
.
DecodeProtobuf
(
b
.
RawData
())
if
err
!=
nil
{
res
.
SetError
(
err
,
cmds
.
ErrNormal
)
return
}
}
if
linkNode
==
nil
&&
resolve
{
nd
,
err
:=
link
.
GetNode
(
req
.
Context
(),
nd
.
DAG
)
if
err
!=
nil
{
res
.
SetError
(
err
,
cmds
.
ErrNormal
)
return
}
pbnd
,
ok
:=
nd
.
(
*
merkledag
.
ProtoNode
)
linkNode
,
err
:=
link
.
GetNode
(
req
.
Context
(),
dserv
)
if
!
ok
{
if
err
==
merkledag
.
ErrNotFound
&&
!
resolve
{
res
.
SetError
(
merkledag
.
ErrNotProtobuf
,
cmds
.
ErrNormal
)
// not an error
return
linkNode
=
nil
}
}
else
if
err
!=
nil
{
res
.
SetError
(
err
,
cmds
.
ErrNormal
)
linkNode
=
pbnd
return
}
}
if
linkNode
!=
nil
{
d
,
err
:=
unixfs
.
FromBytes
(
linkNode
.
Data
())
if
pn
,
ok
:=
linkNode
.
(
*
merkledag
.
ProtoNode
);
ok
{
d
,
err
:=
unixfs
.
FromBytes
(
pn
.
Data
())
if
err
!=
nil
{
if
err
!=
nil
{
res
.
SetError
(
err
,
cmds
.
ErrNormal
)
res
.
SetError
(
err
,
cmds
.
ErrNormal
)
return
return
...
...
test/sharness/t0045-ls.sh
浏览文件 @
6cc0903d
...
@@ -90,12 +90,25 @@ test_ls_cmd() {
...
@@ -90,12 +90,25 @@ test_ls_cmd() {
'
'
}
}
test_ls_cmd_raw_leaves
()
{
test_expect_success
"'ipfs add -r --raw-leaves' then 'ipfs ls' works as expected"
'
mkdir -p somedir &&
echo bar > somedir/foo &&
ipfs add --raw-leaves -r somedir/ > /dev/null &&
ipfs ls QmThNTdtKaVoCVrYmM5EBS6U3S5vfKFue2TxbxxAxRcKKE > ls-actual
echo "zb2rhf6GzX4ckKZtjy8yy8iyq1KttCrRyqDedD6xubhY3sw2F 4 foo" > ls-expect
test_cmp ls-actual ls-expect
'
}
# should work offline
# should work offline
test_ls_cmd
test_ls_cmd
test_ls_cmd_raw_leaves
# should work online
# should work online
test_launch_ipfs_daemon
test_launch_ipfs_daemon
test_ls_cmd
test_ls_cmd
test_ls_cmd_raw_leaves
test_kill_ipfs_daemon
test_kill_ipfs_daemon
test_done
test_done
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论