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