Skip to content

Commit

Permalink
chore(cmds): dag import: use ipld legacy decode
Browse files Browse the repository at this point in the history
  • Loading branch information
schomatis authored and hacdias committed Oct 13, 2022
1 parent b5fe824 commit e48626f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
5 changes: 3 additions & 2 deletions core/commands/dag/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
}
Expand Down
10 changes: 10 additions & 0 deletions test/sharness/t0054-dag-car-import-export.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit e48626f

Please sign in to comment.