@cryptotaxi247 / kubo / commits / 233c39ff6

publish by path

Etienne Laurin committed Apr 12, 2015 at 16:16 UTC 233c39ff6220695d70213d8a5dde3d0936a5194c
3 files changed +48 -13
core/commands/publish.go
+20 -8
@@ -12,6 +12,7 @@ import (
12 core "github.com/ipfs/go-ipfs/core"
13 nsys "github.com/ipfs/go-ipfs/namesys"
14 crypto "github.com/ipfs/go-ipfs/p2p/crypto"
15 + path "github.com/ipfs/go-ipfs/path"
16 u "github.com/ipfs/go-ipfs/util"
17 )
18
@@ -32,12 +33,12 @@ default value of <name> is your own identity public key.
33
34 Examples:
35
35 -Publish a <ref> to your identity name:
36 +Publish an <ipfs-path> to your identity name:
37
37 - > ipfs name publish QmatmE9msSfkKxoffpHwNLNKgwZG8eT9Bud6YoPab52vpy
38 + > ipfs name publish /ipfs/QmatmE9msSfkKxoffpHwNLNKgwZG8eT9Bud6YoPab52vpy
39 published name QmbCMUZw6JFeZ7Wp9jkzbye3Fzp2GGcPgC3nmeUjfVF87n to QmatmE9msSfkKxoffpHwNLNKgwZG8eT9Bud6YoPab52vpy
40
40 -Publish a <ref> to another public key:
41 +Publish an <ipfs-path> to another public key (not implemented):
42
43 > ipfs name publish QmbCMUZw6JFeZ7Wp9jkzbye3Fzp2GGcPgC3nmeUjfVF87n QmatmE9msSfkKxoffpHwNLNKgwZG8eT9Bud6YoPab52vpy
44 published name QmbCMUZw6JFeZ7Wp9jkzbye3Fzp2GGcPgC3nmeUjfVF87n to QmatmE9msSfkKxoffpHwNLNKgwZG8eT9Bud6YoPab52vpy
@@ -71,21 +72,32 @@ Publish a <ref> to another public key:
72 return
73 }
74
74 - // name := ""
75 - ref := ""
75 + var pstr string
76
77 switch len(args) {
78 case 2:
79 // name = args[0]
80 - ref = args[1]
80 + pstr = args[1]
81 res.SetError(errors.New("keychains not yet implemented"), cmds.ErrNormal)
82 case 1:
83 // name = n.Identity.ID.String()
84 - ref = args[0]
84 + pstr = args[0]
85 + }
86 +
87 + node, err := n.Resolver.ResolvePath(path.FromString(pstr))
88 + if err != nil {
89 + res.SetError(fmt.Errorf("failed to resolve path: %v", err), cmds.ErrNormal)
90 + return
91 + }
92 +
93 + key, err := node.Key()
94 + if err != nil {
95 + res.SetError(err, cmds.ErrNormal)
96 + return
97 }
98
99 // TODO n.Keychain.Get(name).PrivKey
88 - output, err := publish(n, n.PrivateKey, ref)
100 + output, err := publish(n, n.PrivateKey, key.Pretty())
101 if err != nil {
102 res.SetError(err, cmds.ErrNormal)
103 return
test/sharness/lib/test-lib-hashes.sh
+1
@@ -2,4 +2,5 @@
2 # thus they can be defined + changed in one place
3
4 HASH_WELCOME_DOCS="Qmcqtw8FfrVSBaRmbWwHxt3AuySBhJLcvmFYi3Lbc4xnwj"
5 +HASH_HELP_PAGE="QmY5heUM5qgRubMDD1og9fhCPA6QdkMp3QCwd4s7gJsyE7"
6 HASH_EMPTY_DIR="QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn"
test/sharness/t0100-name.sh
+27 -5
@@ -10,24 +10,46 @@ test_description="Test ipfs repo operations"
10
11 test_init_ipfs
12
13 +# test publishing a hash
14 +
15 test_expect_success "'ipfs name publish' succeeds" '
16 PEERID=`ipfs id -format="<id>"` &&
15 - HASH=QmYpv2VEsxzTTXRYX3PjDg961cnJE3kY1YDXLycHGQ3zZB &&
16 - ipfs name publish $HASH > publish_out
17 + ipfs name publish "$HASH_WELCOME_DOCS" >publish_out
18 '
19
20 test_expect_success "publish output looks good" '
20 - echo Published name $PEERID to $HASH > expected1 &&
21 + echo "Published name $PEERID to $HASH_WELCOME_DOCS" >expected1 &&
22 test_cmp publish_out expected1
23 '
24
25 test_expect_success "'ipfs name resolve' succeeds" '
25 - ipfs name resolve $PEERID > output
26 + ipfs name resolve "$PEERID" >output
27 '
28
29 test_expect_success "resolve output looks good" '
29 - printf "%s" $HASH > expected2 &&
30 + printf "%s" "$HASH_WELCOME_DOCS" >expected2 &&
31 test_cmp output expected2
32 '
33
34 +# now test with a path
35 +
36 +test_expect_success "'ipfs name publish' succeeds" '
37 + PEERID=`ipfs id -format="<id>"` &&
38 + ipfs name publish "/ipfs/$HASH_WELCOME_DOCS/help" >publish_out
39 +'
40 +
41 +test_expect_success "publish a path looks good" '
42 + echo "Published name $PEERID to $HASH_HELP_PAGE" >expected3 &&
43 + test_cmp publish_out expected3
44 +'
45 +
46 +test_expect_success "'ipfs name resolve' succeeds" '
47 + ipfs name resolve "$PEERID" >output
48 +'
49 +
50 +test_expect_success "resolve output looks good" '
51 + printf "%s" "$HASH_HELP_PAGE" >expected4 &&
52 + test_cmp output expected4
53 +'
54 +
55 test_done