chore(cmds): dag import: use ipld legacy decode

This commit is contained in:
Lucas Molas 2022-08-23 12:04:07 -03:00 committed by Henrique Dias
parent b5fe824964
commit e48626f517
2 changed files with 13 additions and 2 deletions

View File

@ -8,6 +8,7 @@ import (
cid "github.com/ipfs/go-cid"
files "github.com/ipfs/go-ipfs-files"
ipld "github.com/ipfs/go-ipld-format"
ipldlegacy "github.com/ipfs/go-ipld-legacy"
iface "github.com/ipfs/interface-go-ipfs-core"
"github.com/ipfs/interface-go-ipfs-core/options"
"github.com/ipfs/kubo/core/commands/cmdenv"
@ -90,7 +91,7 @@ func dagImport(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment
if block, err := node.Blockstore.Get(req.Context, c); err != nil {
ret.PinErrorMsg = err.Error()
} else if nd, err := ipld.Decode(block); err != nil {
} else if nd, err := ipldlegacy.DecodeNode(req.Context, block); err != nil {
ret.PinErrorMsg = err.Error()
} else if err := node.Pinning.Pin(req.Context, nd, true); err != nil {
ret.PinErrorMsg = err.Error()
@ -181,7 +182,7 @@ func importWorker(req *cmds.Request, re cmds.ResponseEmitter, api iface.CoreAPI,
}
// the double-decode is suboptimal, but we need it for batching
nd, err := ipld.Decode(block)
nd, err := ipldlegacy.DecodeNode(req.Context, block)
if err != nil {
return err
}

View File

@ -263,4 +263,14 @@ test_expect_success "version 2 import output as expected" '
test_cmp_sorted version_2_import_expected version_2_import_actual
'
test_expect_success "'ipfs dag import' decode IPLD dag-json works" '
HASH=$(echo "dag-json content" | ipfs add -Q) &&
# We dont pipe because that doesnt release the repo lock
ipfs dag get $HASH > dag-json.out &&
NEW_HASH=$(ipfs dag put --store-codec dag-json dag-json.out) &&
ipfs dag export $NEW_HASH > dag-json.car &&
ipfs dag import dag-json.car &&
rm dag-json.out dag-json.car
'
test_done