Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Oct 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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