From 31115f51a0fe623bdaced276c5abb6ec19330040 Mon Sep 17 00:00:00 2001 From: rht Date: Sat, 31 Oct 2015 10:48:55 +0700 Subject: [PATCH] Allow `ipfs cat` on ipns path License: MIT Signed-off-by: rht --- core/commands/cat.go | 7 +++++++ core/coreunix/cat.go | 3 +-- test/sharness/t0100-name.sh | 6 ++++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/core/commands/cat.go b/core/commands/cat.go index 389e1b4c2..2860fcc6d 100644 --- a/core/commands/cat.go +++ b/core/commands/cat.go @@ -31,6 +31,13 @@ it contains. return } + if !node.OnlineMode() { + if err := node.SetupOfflineRouting(); err != nil { + res.SetError(err, cmds.ErrNormal) + return + } + } + readers, length, err := cat(req.Context(), node, req.Arguments()) if err != nil { res.SetError(err, cmds.ErrNormal) diff --git a/core/coreunix/cat.go b/core/coreunix/cat.go index 1138bf68a..ca621e061 100644 --- a/core/coreunix/cat.go +++ b/core/coreunix/cat.go @@ -8,8 +8,7 @@ import ( ) func Cat(ctx context.Context, n *core.IpfsNode, pstr string) (*uio.DagReader, error) { - p := path.FromString(pstr) - dagNode, err := n.Resolver.ResolvePath(ctx, p) + dagNode, err := core.Resolve(ctx, n, path.Path(pstr)) if err != nil { return nil, err } diff --git a/test/sharness/t0100-name.sh b/test/sharness/t0100-name.sh index 8b2ebc427..f4c2cf269 100755 --- a/test/sharness/t0100-name.sh +++ b/test/sharness/t0100-name.sh @@ -54,6 +54,12 @@ test_expect_success "resolve output looks good" ' test_cmp expected4 output ' +test_expect_success "ipfs cat on published content succeeds" ' + ipfs cat "/ipfs/$HASH_WELCOME_DOCS/help" >expected && + ipfs cat "/ipns/$PEERID" >actual && + test_cmp expected actual +' + # publish with an explicit node ID test_expect_failure "'ipfs name publish ' succeeds" '