Skip to content

Commit

Permalink
Fix "ipfs ls" to once again work on arbitrary dag objects.
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Kevin Atkinson <[email protected]>
  • Loading branch information
kevina committed Aug 30, 2017
1 parent d50a2b5 commit d90a07f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
15 changes: 10 additions & 5 deletions core/commands/ls.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,20 @@ The JSON output contains type information.
output := make([]LsObject, len(req.Arguments()))
for i, dagnode := range dagnodes {
dir, err := uio.NewDirectoryFromNode(nd.DAG, dagnode)
if err != nil {
if err != nil && err != uio.ErrNotADir {
res.SetError(err, cmds.ErrNormal)
return
}

links, err := dir.Links(req.Context())
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
var links []*node.Link
if dir == nil {
links = dagnode.Links()
} else {
links, err = dir.Links(req.Context())
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
}
}

output[i] = LsObject{
Expand Down
13 changes: 13 additions & 0 deletions test/sharness/t0045-ls.sh
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,28 @@ test_ls_cmd_raw_leaves() {
'
}

test_ls_object() {
test_expect_success "ipfs add medium size file then 'ipfs ls' works as expected" '
random 500000 2 > somefile &&
HASH=$(ipfs add somefile -q) &&
echo "QmPrM8S5T7Q3M8DQvQMS7m41m3Aq4jBjzAzvky5fH3xfr4 262158 " > ls-expect &&
echo "QmdaAntAzQqqVMo4B8V69nkQd5d918YjHXUe2oF6hr72ri 237870 " >> ls-expect &&
ipfs ls $HASH > ls-actual &&
test_cmp ls-actual ls-expect
'
}

# should work offline
test_ls_cmd
test_ls_cmd_raw_leaves
test_ls_object

# should work online
test_launch_ipfs_daemon
test_ls_cmd
test_ls_cmd_raw_leaves
test_kill_ipfs_daemon
test_ls_object

#
# test for ls --resolve-type=false
Expand Down

0 comments on commit d90a07f

Please sign in to comment.