mirror of
https://github.com/ipfs/kubo.git
synced 2026-02-24 11:57:44 +08:00
Merge pull request #3517 from ipfs/fix/dag-get-accept-paths
dag/get: accept paths and not just cids
This commit is contained in:
commit
a15360f349
@ -6,6 +6,7 @@ import (
|
||||
"strings"
|
||||
|
||||
cmds "github.com/ipfs/go-ipfs/commands"
|
||||
path "github.com/ipfs/go-ipfs/path"
|
||||
|
||||
node "gx/ipfs/QmRSU5EqqWVZSNdbU51yXmVoF1uNw3JgTNB6RaiL7DZM16/go-ipld-node"
|
||||
ipldcbor "gx/ipfs/QmbuuwTd9x4NReZ7sxtiKk7wFcfDUo54MfWBdtF5MRCPGR/go-ipld-cbor"
|
||||
@ -105,7 +106,7 @@ var DagGetCmd = &cmds.Command{
|
||||
`,
|
||||
},
|
||||
Arguments: []cmds.Argument{
|
||||
cmds.StringArg("cid", true, false, "The cid of the object to get").EnableStdin(),
|
||||
cmds.StringArg("ref", true, false, "The object to get").EnableStdin(),
|
||||
},
|
||||
Run: func(req cmds.Request, res cmds.Response) {
|
||||
n, err := req.InvocContext().GetNode()
|
||||
@ -114,13 +115,13 @@ var DagGetCmd = &cmds.Command{
|
||||
return
|
||||
}
|
||||
|
||||
c, err := cid.Decode(req.Arguments()[0])
|
||||
p, err := path.ParsePath(req.Arguments()[0])
|
||||
if err != nil {
|
||||
res.SetError(err, cmds.ErrNormal)
|
||||
return
|
||||
}
|
||||
|
||||
obj, err := n.DAG.Get(req.Context(), c)
|
||||
obj, err := n.Resolver.ResolvePath(req.Context(), p)
|
||||
if err != nil {
|
||||
res.SetError(err, cmds.ErrNormal)
|
||||
return
|
||||
|
||||
@ -59,6 +59,15 @@ test_dag_cmd() {
|
||||
echo "{\"data\":\"CAISB2Zvb2JhcgoYBw==\",\"links\":[]}" > dag_get_pb_exp &&
|
||||
test_cmp dag_get_pb_exp dag_get_pb_out
|
||||
'
|
||||
|
||||
test_expect_success "can call dag get with a path" '
|
||||
ipfs dag get $IPLDHASH/cats/0 > cat_out
|
||||
'
|
||||
|
||||
test_expect_success "output looks correct" '
|
||||
echo "{\"data\":\"CAISBGZvbwoYBA==\",\"links\":[]}" > cat_exp &&
|
||||
test_cmp cat_exp cat_out
|
||||
'
|
||||
}
|
||||
|
||||
# should work offline
|
||||
|
||||
Loading…
Reference in New Issue
Block a user