diff --git a/core/commands/dag/dag.go b/core/commands/dag/dag.go index cdfa8ce9661f..c7a5f248261d 100644 --- a/core/commands/dag/dag.go +++ b/core/commands/dag/dag.go @@ -55,7 +55,8 @@ type ResolveOutput struct { // CarImportOutput is the output type of the 'dag import' commands type CarImportOutput struct { - Root RootMeta + BlockCount uint64 + Root *RootMeta } // RootMeta is the metadata for a root pinning response @@ -157,8 +158,9 @@ var DagResolveCmd = &cmds.Command{ } type importResult struct { - roots map[cid.Cid]struct{} - err error + blockCount uint64 + roots map[cid.Cid]struct{} + err error } // DagImportCmd is a command for importing a car to ipfs @@ -203,6 +205,11 @@ Maximum supported CAR version: 1 return nil } + if event.Root == nil { + fmt.Fprintf(w, "Imported %d blocks\n", event.BlockCount) + return nil + } + enc, err := cmdenv.GetLowLevelCidEncoder(req) if err != nil { return err diff --git a/core/commands/dag/import.go b/core/commands/dag/import.go index b83af8b911de..72723d446c50 100644 --- a/core/commands/dag/import.go +++ b/core/commands/dag/import.go @@ -55,6 +55,8 @@ func dagImport(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment return done.err } + res.Emit(&CarImportOutput{BlockCount: done.blockCount}) + // It is not guaranteed that a root in a header is actually present in the same ( or any ) // .car file. This is the case in version 1, and ideally in further versions too // Accumulate any root CID seen in a header, and supplement its actual node if/when encountered @@ -101,7 +103,7 @@ func dagImport(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment failedPins++ } - if err := res.Emit(&CarImportOutput{Root: ret}); err != nil { + if err := res.Emit(&CarImportOutput{Root: &ret}); err != nil { return err } } @@ -126,6 +128,7 @@ func importWorker(req *cmds.Request, re cmds.ResponseEmitter, api iface.CoreAPI, batch := ipld.NewBatch(req.Context, api.Dag()) roots := make(map[cid.Cid]struct{}) + var blockCount uint64 it := req.Files.Entries() for it.Next() { @@ -176,6 +179,7 @@ func importWorker(req *cmds.Request, re cmds.ResponseEmitter, api iface.CoreAPI, if err := batch.Add(req.Context, nd); err != nil { return err } + blockCount++ } return nil @@ -197,5 +201,5 @@ func importWorker(req *cmds.Request, re cmds.ResponseEmitter, api iface.CoreAPI, return } - ret <- importResult{roots: roots} + ret <- importResult{blockCount: blockCount, roots: roots} } diff --git a/test/sharness/t0054-dag-car-import-export.sh b/test/sharness/t0054-dag-car-import-export.sh index 450591ff7923..e7f8a32d4f77 100755 --- a/test/sharness/t0054-dag-car-import-export.sh +++ b/test/sharness/t0054-dag-car-import-export.sh @@ -56,14 +56,16 @@ run_online_imp_exp_tests() { reset_blockstore 1 cat > basic_import_expected <naked_root_import_json_expected <multiroot_import_json_expected < multiroot_import_json_actual @@ -182,14 +185,17 @@ test_expect_success "multiroot import expected output" ' ' +cat >pin_import_expected << EOE +{"BlockCount":1198,"Root":null} +EOE test_expect_success "pin-less import works" ' ipfs dag import --enc=json --pin-roots=false \ ../t0054-dag-car-import-export-data/lotus_devnet_genesis.car \ ../t0054-dag-car-import-export-data/lotus_testnet_export_128.car \ > no-pin_import_actual ' -test_expect_success "expected silence on --pin-roots=false" ' - test_cmp /dev/null no-pin_import_actual +test_expect_success "expected no pins on --pin-roots=false" ' + test_cmp pin_import_expected no-pin_import_actual '