mirror of
https://github.com/ipfs/kubo.git
synced 2026-03-01 14:28:02 +08:00
Add flag to ls to not resolve type of subnodes (#2824)
* Disable resolving of the typ by default in ls Add option to resolve type using ls but set it to false by default. License: MIT Signed-off-by: Jakub Sztandera <kubuxu@protonmail.ch> * Make ipfs ls show type if it is avaliable locally License: MIT Signed-off-by: Jakub Sztandera <kubuxu@protonmail.ch> * Make resolve-type default to true License: MIT Signed-off-by: Jakub Sztandera <kubuxu@protonmail.ch>
This commit is contained in:
parent
7fa88fd941
commit
d72c9fcd3e
@ -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"
|
||||
@ -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()
|
||||
@ -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
|
||||
@ -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())
|
||||
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 && resolve {
|
||||
linkNode, err = link.GetNode(req.Context(), node.DAG)
|
||||
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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user