提交 f0a0ac1b 作者: W. Trevor King

core/commands/unixfs/ls: Use a stringified type name

This doesn't affect the text output, which was already using a
stringified name.  The earlier stringification does change the JSON
output from an enumeration integer (e.g. 2) to the string form
(e.g. "File").  If/when we transition to Merkle-object types named by
their hash, we will probably want to revisit this and pass both the
type hash and human-readable-but-collision-prone name on to clients.

License: MIT
Signed-off-by: 's avatarW. Trevor King <wking@tremily.us>
上级 c9733c5d
......@@ -19,7 +19,7 @@ import (
type LsLink struct {
Name, Hash string
Size uint64
Type unixfspb.Data_DataType
Type string
}
type LsObject struct {
......@@ -88,7 +88,7 @@ directories, the child size is the IPFS link size.
output[i].Links = []LsLink{LsLink{
Name: fpath,
Hash: key.String(),
Type: t,
Type: t.String(),
Size: unixFSNode.GetFilesize(),
}}
case unixfspb.Data_Directory:
......@@ -106,12 +106,13 @@ directories, the child size is the IPFS link size.
res.SetError(err, cmds.ErrNormal)
return
}
t := d.GetType()
lsLink := LsLink{
Name: link.Name,
Hash: link.Hash.B58String(),
Type: d.GetType(),
Type: t.String(),
}
if lsLink.Type == unixfspb.Data_File {
if t == unixfspb.Data_File {
lsLink.Size = d.GetFilesize()
} else {
lsLink.Size = link.Size
......
......@@ -88,7 +88,7 @@ test_ls_cmd() {
"Name": "/ipfs/QmR3jhV4XpxxPjPT3Y8vNnWvWNvakdcT3H6vqpRBsX1MLy/1024",
"Hash": "QmbQBUSRL9raZtNXfpTDeaxQapibJEG6qEY8WqAN22aUzd",
"Size": 1024,
"Type": 2
"Type": "File"
}
]
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论