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: W. Trevor King <wking@tremily.us>
W. Trevor King committed
Jun 10, 2015 at 06:58 UTC
f0a0ac1b8351812dcb6ee97d3c72a51cd95578d4
2 files changed
+6
-5
core/commands/unixfs/ls.go
+5
-4
@@ -19,7 +19,7 @@ import (
19
type LsLink struct {
20
Name, Hash string
21
Size uint64
22
- Type unixfspb.Data_DataType
22
+ Type string
23
}
24
25
type LsObject struct {
@@ -88,7 +88,7 @@ directories, the child size is the IPFS link size.
88
output[i].Links = []LsLink{LsLink{
89
Name: fpath,
90
Hash: key.String(),
91
- Type: t,
91
+ Type: t.String(),
92
Size: unixFSNode.GetFilesize(),
93
}}
94
case unixfspb.Data_Directory:
@@ -106,12 +106,13 @@ directories, the child size is the IPFS link size.
106
res.SetError(err, cmds.ErrNormal)
107
return
108
}
109
+ t := d.GetType()
110
lsLink := LsLink{
111
Name: link.Name,
112
Hash: link.Hash.B58String(),
112
- Type: d.GetType(),
113
+ Type: t.String(),
114
}
114
- if lsLink.Type == unixfspb.Data_File {
115
+ if t == unixfspb.Data_File {
116
lsLink.Size = d.GetFilesize()
117
} else {
118
lsLink.Size = link.Size
test/sharness/t0200-unixfs-ls.sh
+1
-1
@@ -88,7 +88,7 @@ test_ls_cmd() {
88
"Name": "/ipfs/QmR3jhV4XpxxPjPT3Y8vNnWvWNvakdcT3H6vqpRBsX1MLy/1024",
89
"Hash": "QmbQBUSRL9raZtNXfpTDeaxQapibJEG6qEY8WqAN22aUzd",
90
"Size": 1024,
91
- "Type": 2
91
+ "Type": "File"
92
}
93
]
94
}