Skip to content

Commit

Permalink
core/commands/unixfs/ls: Use a stringified type name
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
wking committed Jun 13, 2015
1 parent 0577286 commit e5f3ae9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
9 changes: 5 additions & 4 deletions core/commands/unixfs/ls.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
type LsLink struct {
Name, Hash string
Size uint64
Type unixfspb.Data_DataType
Type string
}

type LsObject struct {
Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/sharness/t0200-unixfs-ls.sh
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ test_ls_cmd() {
"Name": "/ipfs/QmR3jhV4XpxxPjPT3Y8vNnWvWNvakdcT3H6vqpRBsX1MLy/1024",
"Hash": "QmbQBUSRL9raZtNXfpTDeaxQapibJEG6qEY8WqAN22aUzd",
"Size": 1024,
"Type": 2
"Type": "File"
}
]
}
Expand Down

0 comments on commit e5f3ae9

Please sign in to comment.