From 233c39ff6220695d70213d8a5dde3d0936a5194c Mon Sep 17 00:00:00 2001 From: Etienne Laurin Date: Sun, 12 Apr 2015 16:16:10 +0000 Subject: [PATCH] publish by path --- core/commands/publish.go | 28 +++++++++++++++++------- test/sharness/lib/test-lib-hashes.sh | 1 + test/sharness/t0100-name.sh | 32 +++++++++++++++++++++++----- 3 files changed, 48 insertions(+), 13 deletions(-) diff --git a/core/commands/publish.go b/core/commands/publish.go index c5db0fbac..43dabd15e 100644 --- a/core/commands/publish.go +++ b/core/commands/publish.go @@ -12,6 +12,7 @@ import ( core "github.com/ipfs/go-ipfs/core" nsys "github.com/ipfs/go-ipfs/namesys" crypto "github.com/ipfs/go-ipfs/p2p/crypto" + path "github.com/ipfs/go-ipfs/path" u "github.com/ipfs/go-ipfs/util" ) @@ -32,12 +33,12 @@ default value of is your own identity public key. Examples: -Publish a to your identity name: +Publish an to your identity name: - > ipfs name publish QmatmE9msSfkKxoffpHwNLNKgwZG8eT9Bud6YoPab52vpy + > ipfs name publish /ipfs/QmatmE9msSfkKxoffpHwNLNKgwZG8eT9Bud6YoPab52vpy published name QmbCMUZw6JFeZ7Wp9jkzbye3Fzp2GGcPgC3nmeUjfVF87n to QmatmE9msSfkKxoffpHwNLNKgwZG8eT9Bud6YoPab52vpy -Publish a to another public key: +Publish an to another public key (not implemented): > ipfs name publish QmbCMUZw6JFeZ7Wp9jkzbye3Fzp2GGcPgC3nmeUjfVF87n QmatmE9msSfkKxoffpHwNLNKgwZG8eT9Bud6YoPab52vpy published name QmbCMUZw6JFeZ7Wp9jkzbye3Fzp2GGcPgC3nmeUjfVF87n to QmatmE9msSfkKxoffpHwNLNKgwZG8eT9Bud6YoPab52vpy @@ -71,21 +72,32 @@ Publish a to another public key: return } - // name := "" - ref := "" + var pstr string switch len(args) { case 2: // name = args[0] - ref = args[1] + pstr = args[1] res.SetError(errors.New("keychains not yet implemented"), cmds.ErrNormal) case 1: // name = n.Identity.ID.String() - ref = args[0] + pstr = args[0] + } + + node, err := n.Resolver.ResolvePath(path.FromString(pstr)) + if err != nil { + res.SetError(fmt.Errorf("failed to resolve path: %v", err), cmds.ErrNormal) + return + } + + key, err := node.Key() + if err != nil { + res.SetError(err, cmds.ErrNormal) + return } // TODO n.Keychain.Get(name).PrivKey - output, err := publish(n, n.PrivateKey, ref) + output, err := publish(n, n.PrivateKey, key.Pretty()) if err != nil { res.SetError(err, cmds.ErrNormal) return diff --git a/test/sharness/lib/test-lib-hashes.sh b/test/sharness/lib/test-lib-hashes.sh index 0683b04ee..ae3b1f1ae 100644 --- a/test/sharness/lib/test-lib-hashes.sh +++ b/test/sharness/lib/test-lib-hashes.sh @@ -2,4 +2,5 @@ # thus they can be defined + changed in one place HASH_WELCOME_DOCS="Qmcqtw8FfrVSBaRmbWwHxt3AuySBhJLcvmFYi3Lbc4xnwj" +HASH_HELP_PAGE="QmY5heUM5qgRubMDD1og9fhCPA6QdkMp3QCwd4s7gJsyE7" HASH_EMPTY_DIR="QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn" diff --git a/test/sharness/t0100-name.sh b/test/sharness/t0100-name.sh index 4c2fc8555..da995403d 100755 --- a/test/sharness/t0100-name.sh +++ b/test/sharness/t0100-name.sh @@ -10,24 +10,46 @@ test_description="Test ipfs repo operations" test_init_ipfs +# test publishing a hash + test_expect_success "'ipfs name publish' succeeds" ' PEERID=`ipfs id -format=""` && - HASH=QmYpv2VEsxzTTXRYX3PjDg961cnJE3kY1YDXLycHGQ3zZB && - ipfs name publish $HASH > publish_out + ipfs name publish "$HASH_WELCOME_DOCS" >publish_out ' test_expect_success "publish output looks good" ' - echo Published name $PEERID to $HASH > expected1 && + echo "Published name $PEERID to $HASH_WELCOME_DOCS" >expected1 && test_cmp publish_out expected1 ' test_expect_success "'ipfs name resolve' succeeds" ' - ipfs name resolve $PEERID > output + ipfs name resolve "$PEERID" >output ' test_expect_success "resolve output looks good" ' - printf "%s" $HASH > expected2 && + printf "%s" "$HASH_WELCOME_DOCS" >expected2 && test_cmp output expected2 ' +# now test with a path + +test_expect_success "'ipfs name publish' succeeds" ' + PEERID=`ipfs id -format=""` && + ipfs name publish "/ipfs/$HASH_WELCOME_DOCS/help" >publish_out +' + +test_expect_success "publish a path looks good" ' + echo "Published name $PEERID to $HASH_HELP_PAGE" >expected3 && + test_cmp publish_out expected3 +' + +test_expect_success "'ipfs name resolve' succeeds" ' + ipfs name resolve "$PEERID" >output +' + +test_expect_success "resolve output looks good" ' + printf "%s" "$HASH_HELP_PAGE" >expected4 && + test_cmp output expected4 +' + test_done