From 9c5304a21de66fa8f1eae715e8218396b31d18d6 Mon Sep 17 00:00:00 2001 From: Adin Schmahmann Date: Wed, 4 Nov 2020 21:14:00 -0500 Subject: [PATCH] fix: ipfs dag export uses the CoreAPI and respects the offline flag --- core/commands/dag/dag.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/core/commands/dag/dag.go b/core/commands/dag/dag.go index 24e40d83059..42bd3fe71c4 100644 --- a/core/commands/dag/dag.go +++ b/core/commands/dag/dag.go @@ -550,7 +550,7 @@ The output of blocks happens in strict DAG-traversal, first-seen, order. ) } - node, err := cmdenv.GetNode(env) + api, err := cmdenv.GetApi(env, req) if err != nil { return err } @@ -588,7 +588,7 @@ The output of blocks happens in strict DAG-traversal, first-seen, order. req.Context, mdag.NewSession( req.Context, - node.DAG, + api.Dag(), ), []cid.Cid{c}, pipeW, @@ -606,9 +606,16 @@ The output of blocks happens in strict DAG-traversal, first-seen, order. // minimal user friendliness if err != nil && - !node.IsOnline && err == ipld.ErrNotFound { - err = fmt.Errorf("%s (currently offline, perhaps retry after attaching to the network)", err) + explicitOffline, _ := req.Options["offline"].(bool) + if explicitOffline { + err = fmt.Errorf("%s (currently offline, perhaps retry without the offline flag)", err) + } else { + node, envErr := cmdenv.GetNode(env) + if envErr == nil && !node.IsOnline { + err = fmt.Errorf("%s (currently offline, perhaps retry after attaching to the network)", err) + } + } } return err