@cryptotaxi247 / kubo / commits / e3255f46e

address comments from CR

Jeromy committed Apr 19, 2015 at 11:17 UTC e3255f46e1461df9db0540d82a0b46f79cad1771
3 files changed +21 -8
core/commands/publish.go
+7 -1
@@ -107,9 +107,15 @@ Publish an <ipfs-path> to another public key (not implemented):
107 }
108
109 func publish(n *core.IpfsNode, k crypto.PrivKey, ref path.Path) (*IpnsEntry, error) {
110 + // First, verify the path exists
111 + _, err := n.Resolver.ResolvePath(ref)
112 + if err != nil {
113 + return nil, err
114 + }
115 +
116 pub := nsys.NewRoutingPublisher(n.Routing)
117
112 - err := pub.Publish(n.Context(), k, ref)
118 + err = pub.Publish(n.Context(), k, ref)
119 if err != nil {
120 return nil, err
121 }
core/corehttp/ipns_hostname.go
+2 -2
@@ -19,8 +19,8 @@ func IPNSHostnameOption() ServeOption {
19 defer cancel()
20
21 host := strings.SplitN(r.Host, ":", 2)[0]
22 - if k, err := n.Namesys.Resolve(ctx, host); err == nil {
23 - r.URL.Path = "/ipfs/" + k.String() + r.URL.Path
22 + if p, err := n.Namesys.Resolve(ctx, host); err == nil {
23 + r.URL.Path = "/ipfs/" + p.String() + r.URL.Path
24 }
25 childMux.ServeHTTP(w, r)
26 })
path/path.go
+12 -5
@@ -49,11 +49,13 @@ func FromSegments(seg ...string) Path {
49 }
50
51 func ParsePath(txt string) (Path, error) {
52 - kp, err := ParseKeyToPath(txt)
53 - if err == nil {
54 - return kp, nil
55 - }
52 parts := strings.Split(txt, "/")
53 + if len(parts) == 1 {
54 + kp, err := ParseKeyToPath(txt)
55 + if err == nil {
56 + return kp, nil
57 + }
58 + }
59 if len(parts) < 3 {
60 return "", ErrBadPath
61 }
@@ -66,7 +68,7 @@ func ParsePath(txt string) (Path, error) {
68 return "", ErrBadPath
69 }
70
69 - _, err = ParseKeyToPath(parts[2])
71 + _, err := ParseKeyToPath(parts[2])
72 if err != nil {
73 return "", err
74 }
@@ -86,3 +88,8 @@ func ParseKeyToPath(txt string) (Path, error) {
88 }
89 return FromKey(u.Key(chk)), nil
90 }
91 +
92 +func (p *Path) IsValid() error {
93 + _, err := ParsePath(p.String())
94 + return err
95 +}