Skip to content

Commit

Permalink
fix offline full path resolution bug
Browse files Browse the repository at this point in the history
  • Loading branch information
whyrusleeping committed May 21, 2015
1 parent 5853eac commit 1babd9d
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
2 changes: 1 addition & 1 deletion core/pathresolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ var ErrNoNamesys = errors.New(
// entries and returning the final merkledage node. Effectively
// enables /ipns/, /dns/, etc. in commands.
func Resolve(ctx context.Context, n *IpfsNode, p path.Path) (*merkledag.Node, error) {
if strings.HasPrefix(p.String(), "/") {
if strings.HasPrefix(p.String(), "/ipns") {
// namespaced path (/ipfs/..., /ipns/..., etc.)

This comment has been minimized.

Copy link
@wking

wking May 21, 2015

Contributor

Probably use "/ipns/" (with the trailing slash) in the conditional.

I'd prefer:

if strings.HasPrefix(p.String(), "/") && !strings.HasPrefix(p.String(), "/ipfs/")

so we can eventually support other protocols besides the current “try all our resolvers” logic we bind to /ipns/…. For example, early passes in #1208 had the DNS link stuff under /dns/…. That was too much to bite off in #1208, but I still think we'll end up with an explicit-protocol system like that eventually, and I want to keep that door easy to re-open when we do decide to move in that direction.

Drop /ipfs/ from this comment to catch up with the condition change. Since this reduces our resolved protocols to just the multi-protocol /ipns/, maybe rephrase the comment to:

// namespaced non-/ipfs/ path (e.g. /ipns/...)

On the other hand, I really want to roll the pathresolver logic into the recursive namesys helper, since resolving and parsing paths really has very little to do with how your entries are stored. That's a bigger refactoring, so I don't mind tearing up a bit of IPFS special-casing here when I get around to writing it up ;).

// TODO(cryptix): we sould be able to query the local cache for the path
if n.Namesys == nil {
Expand Down
34 changes: 34 additions & 0 deletions test/sharness/t0041-add-cat-offline.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/sh
#
# Copyright (c) 2014 Jeromy Johnson
# MIT Licensed; see the LICENSE file in this repository.
#

test_description="Test add and cat commands"

. lib/test-lib.sh

test_init_ipfs

test_expect_success "ipfs add file succeeds" '
echo "some content" > afile &&
HASH=$(ipfs add -q afile)
'

test_expect_success "ipfs cat file suceeds" '
ipfs cat $HASH > out_1
'

test_expect_success "output looks good" '
test_cmp afile out_1
'

test_expect_success "ipfs cat /ipfs/file succeeds" '
ipfs cat /ipfs/$HASH > out_2
'

test_expect_success "output looks good" '
test_cmp afile out_2
'

test_done

0 comments on commit 1babd9d

Please sign in to comment.