mirror of
https://github.com/ipfs/kubo.git
synced 2025-06-26 23:53:19 +08:00
Merge pull request #4890 from ipfs/feat/fast-ls
infer type from CID when possible in ls command
This commit is contained in:
@ -18,6 +18,7 @@ import (
|
|||||||
uio "github.com/ipfs/go-ipfs/unixfs/io"
|
uio "github.com/ipfs/go-ipfs/unixfs/io"
|
||||||
unixfspb "github.com/ipfs/go-ipfs/unixfs/pb"
|
unixfspb "github.com/ipfs/go-ipfs/unixfs/pb"
|
||||||
|
|
||||||
|
cid "gx/ipfs/QmcZfnkapfECQGcLZaf9B79NRg7cRa9EnZh4LSbkCzwNvY/go-cid"
|
||||||
"gx/ipfs/QmceUdzxkimdYsgtX733uNgzf1DLHyBKN6ehGSp85ayppM/go-ipfs-cmdkit"
|
"gx/ipfs/QmceUdzxkimdYsgtX733uNgzf1DLHyBKN6ehGSp85ayppM/go-ipfs-cmdkit"
|
||||||
ipld "gx/ipfs/Qme5bWv7wtjUNGsK2BNGVUFPKiuxWrsqrtvYwCLRw8YFES/go-ipld-format"
|
ipld "gx/ipfs/Qme5bWv7wtjUNGsK2BNGVUFPKiuxWrsqrtvYwCLRw8YFES/go-ipld-format"
|
||||||
)
|
)
|
||||||
@ -134,23 +135,28 @@ The JSON output contains type information.
|
|||||||
for j, link := range links {
|
for j, link := range links {
|
||||||
t := unixfspb.Data_DataType(-1)
|
t := unixfspb.Data_DataType(-1)
|
||||||
|
|
||||||
linkNode, err := link.GetNode(req.Context(), dserv)
|
switch link.Cid.Type() {
|
||||||
if err == ipld.ErrNotFound && !resolve {
|
case cid.Raw:
|
||||||
// not an error
|
// No need to check with raw leaves
|
||||||
linkNode = nil
|
t = unixfspb.Data_File
|
||||||
} else if err != nil {
|
case cid.DagProtobuf:
|
||||||
res.SetError(err, cmdkit.ErrNormal)
|
linkNode, err := link.GetNode(req.Context(), dserv)
|
||||||
return
|
if err == ipld.ErrNotFound && !resolve {
|
||||||
}
|
// not an error
|
||||||
|
linkNode = nil
|
||||||
if pn, ok := linkNode.(*merkledag.ProtoNode); ok {
|
} else if err != nil {
|
||||||
d, err := unixfs.FromBytes(pn.Data())
|
|
||||||
if err != nil {
|
|
||||||
res.SetError(err, cmdkit.ErrNormal)
|
res.SetError(err, cmdkit.ErrNormal)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
t = d.GetType()
|
if pn, ok := linkNode.(*merkledag.ProtoNode); ok {
|
||||||
|
d, err := unixfs.FromBytes(pn.Data())
|
||||||
|
if err != nil {
|
||||||
|
res.SetError(err, cmdkit.ErrNormal)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
t = d.GetType()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
output[i].Links[j] = LsLink{
|
output[i].Links[j] = LsLink{
|
||||||
Name: link.Name,
|
Name: link.Name,
|
||||||
|
Reference in New Issue
Block a user