Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix "ipfs ls" to once again work on arbitrary dag objects. #4184

Merged
merged 2 commits into from
Aug 31, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
2 changes: 1 addition & 1 deletion namesys/publisher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import (
path "github.com/ipfs/go-ipfs/path"
mockrouting "github.com/ipfs/go-ipfs/routing/mock"
dshelp "github.com/ipfs/go-ipfs/thirdparty/ds-help"
testutil "github.com/ipfs/go-ipfs/thirdparty/testutil"

ds "gx/ipfs/QmVSase1JP7cq9QkPT46oNwdp9pT6kBkG3oqS14y3QcZjG/go-datastore"
dssync "gx/ipfs/QmVSase1JP7cq9QkPT46oNwdp9pT6kBkG3oqS14y3QcZjG/go-datastore/sync"
ma "gx/ipfs/QmXY77cVe7rVRQXZZQRioukUM7aRW3BTcAgJe12MCtb3Ji/go-multiaddr"
peer "gx/ipfs/QmXYjuNuxVzXKJCfWasQk1RqkhVLDM9jtUKhqc2WPQmFSB/go-libp2p-peer"
testutil "gx/ipfs/QmZJD56ZWLViJAVkvLc7xbbDerHzUMLr2X4fLRYfbxZWDN/go-testutil"
ci "gx/ipfs/QmaPbCnUMBohSGo3KnxEa2bHqyJVVeEEcwtqJAYxerieBo/go-libp2p-crypto"
)

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