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

Add flag to ls to not resolve type of subnodes #2824

Merged
merged 3 commits into from
Jun 28, 2016
Merged
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
47 changes: 38 additions & 9 deletions core/commands/ls.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"io"
"text/tabwriter"

key "github.com/ipfs/go-ipfs/blocks/key"
cmds "github.com/ipfs/go-ipfs/commands"
core "github.com/ipfs/go-ipfs/core"
merkledag "github.com/ipfs/go-ipfs/merkledag"
Expand Down Expand Up @@ -45,6 +46,7 @@ format:
},
Options: []cmds.Option{
cmds.BoolOption("headers", "v", "Print table headers (Hash, Size, Name).").Default(false),
cmds.BoolOption("resolve-type", "Resolve linked objects to find out their types.").Default(true),
},
Run: func(req cmds.Request, res cmds.Response) {
node, err := req.InvocContext().GetNode()
Expand All @@ -59,6 +61,12 @@ format:
return
}

resolve, _, err := req.Option("resolve-type").Bool()
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
}

paths := req.Arguments()

var dagnodes []*merkledag.Node
Expand All @@ -79,21 +87,42 @@ format:
}
for j, link := range dagnode.Links {
var linkNode *merkledag.Node
linkNode, err = link.GetNode(req.Context(), node.DAG)
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
t := unixfspb.Data_DataType(-1)
linkKey := key.Key(link.Hash)
if ok, err := node.Blockstore.Has(linkKey); ok && err == nil {
b, err := node.Blockstore.Get(linkKey)
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
}
linkNode, err = merkledag.DecodeProtobuf(b.Data())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok wat-- all this merkledag code shouldnt have to be out here. this should all be handled by util functions in either unixfs or some other package. this is leaking abstractions out

if err != nil {
res.SetError(err, cmds.ErrNormal)
return
}
}

if linkNode == nil && resolve {
linkNode, err = link.GetNode(req.Context(), node.DAG)
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
}
}
d, err := unixfs.FromBytes(linkNode.Data)
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
if linkNode != nil {
d, err := unixfs.FromBytes(linkNode.Data)
if err != nil {
res.SetError(err, cmds.ErrNormal)
return
}

t = d.GetType()
}
output[i].Links[j] = LsLink{
Name: link.Name,
Hash: link.Hash.B58String(),
Size: link.Size,
Type: d.GetType(),
Type: t,
}
}
}
Expand Down