Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
G
go-ipfs
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
jihao
go-ipfs
Commits
759437e0
提交
759437e0
authored
3月 10, 2015
作者:
Henry
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
ls: introduce specific output types (removes IsDir from object plumbing commands)
上级
e0cf24bf
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
34 行增加
和
25 行删除
+34
-25
ls.go
core/commands/ls.go
+20
-24
object.go
core/commands/object.go
+14
-1
没有找到文件。
core/commands/ls.go
浏览文件 @
759437e0
...
...
@@ -13,19 +13,19 @@ import (
unixfspb
"github.com/jbenet/go-ipfs/unixfs/pb"
)
type
Link
struct
{
type
L
sL
ink
struct
{
Name
,
Hash
string
Size
uint64
IsDir
bool
Type
unixfspb
.
Data_DataType
}
type
Object
struct
{
type
Ls
Object
struct
{
Hash
string
Links
[]
Link
Links
[]
L
sL
ink
}
type
LsOutput
struct
{
Objects
[]
Object
Objects
[]
Ls
Object
}
var
LsCmd
=
&
cmds
.
Command
{
...
...
@@ -61,11 +61,11 @@ it contains, with the following format:
dagnodes
=
append
(
dagnodes
,
dagnode
)
}
output
:=
make
([]
Object
,
len
(
req
.
Arguments
()))
output
:=
make
([]
Ls
Object
,
len
(
req
.
Arguments
()))
for
i
,
dagnode
:=
range
dagnodes
{
output
[
i
]
=
Object
{
output
[
i
]
=
Ls
Object
{
Hash
:
paths
[
i
],
Links
:
make
([]
Link
,
len
(
dagnode
.
Links
)),
Links
:
make
([]
L
sL
ink
,
len
(
dagnode
.
Links
)),
}
for
j
,
link
:=
range
dagnode
.
Links
{
link
.
Node
,
err
=
link
.
GetNode
(
node
.
DAG
)
...
...
@@ -78,11 +78,11 @@ it contains, with the following format:
res
.
SetError
(
err
,
cmds
.
ErrNormal
)
return
}
output
[
i
]
.
Links
[
j
]
=
Link
{
Name
:
link
.
Name
,
Hash
:
link
.
Hash
.
B58String
(),
Size
:
link
.
Size
,
IsDir
:
d
.
GetType
()
==
unixfspb
.
Data_Directory
,
output
[
i
]
.
Links
[
j
]
=
L
sL
ink
{
Name
:
link
.
Name
,
Hash
:
link
.
Hash
.
B58String
(),
Size
:
link
.
Size
,
Type
:
d
.
GetType
()
,
}
}
}
...
...
@@ -98,7 +98,13 @@ it contains, with the following format:
if
len
(
output
)
>
1
{
fmt
.
Fprintf
(
w
,
"%s:
\n
"
,
object
.
Hash
)
}
marshalLinks
(
w
,
object
.
Links
)
fmt
.
Fprintln
(
w
,
"Hash
\t
Size
\t
Name
\t
"
)
for
_
,
link
:=
range
object
.
Links
{
if
link
.
Type
==
unixfspb
.
Data_Directory
{
link
.
Name
+=
"/"
}
fmt
.
Fprintf
(
w
,
"%s
\t
%v
\t
%s
\t\n
"
,
link
.
Hash
,
link
.
Size
,
link
.
Name
)
}
if
len
(
output
)
>
1
{
fmt
.
Fprintln
(
w
)
}
...
...
@@ -110,13 +116,3 @@ it contains, with the following format:
},
Type
:
LsOutput
{},
}
func
marshalLinks
(
w
io
.
Writer
,
links
[]
Link
)
{
fmt
.
Fprintln
(
w
,
"Hash
\t
Size
\t
Name
\t
"
)
for
_
,
link
:=
range
links
{
if
link
.
IsDir
{
link
.
Name
+=
"/"
}
fmt
.
Fprintf
(
w
,
"%s
\t
%v
\t
%s
\t\n
"
,
link
.
Hash
,
link
.
Size
,
link
.
Name
)
}
}
core/commands/object.go
浏览文件 @
759437e0
...
...
@@ -28,6 +28,16 @@ type Node struct {
Data
string
}
type
Link
struct
{
Name
,
Hash
string
Size
uint64
}
type
Object
struct
{
Hash
string
Links
[]
Link
}
var
ObjectCmd
=
&
cmds
.
Command
{
Helptext
:
cmds
.
HelpText
{
Tagline
:
"Interact with ipfs objects"
,
...
...
@@ -123,7 +133,10 @@ multihash.
object
:=
res
.
Output
()
.
(
*
Object
)
var
buf
bytes
.
Buffer
w
:=
tabwriter
.
NewWriter
(
&
buf
,
1
,
2
,
1
,
' '
,
0
)
marshalLinks
(
w
,
object
.
Links
)
fmt
.
Fprintln
(
w
,
"Hash
\t
Size
\t
Name
\t
"
)
for
_
,
link
:=
range
object
.
Links
{
fmt
.
Fprintf
(
w
,
"%s
\t
%v
\t
%s
\t\n
"
,
link
.
Hash
,
link
.
Size
,
link
.
Name
)
}
w
.
Flush
()
return
&
buf
,
nil
},
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论