From 4b7a867e9298ece5b784feba284e834ab5609ef3 Mon Sep 17 00:00:00 2001 From: Jeromy Date: Sun, 19 Apr 2015 11:17:06 -0700 Subject: [PATCH] address comments from CR --- core/commands/publish.go | 8 +++++++- core/corehttp/ipns_hostname.go | 4 ++-- path/path.go | 17 ++++++++++++----- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/core/commands/publish.go b/core/commands/publish.go index 03f24dcdb81..bef930bd929 100644 --- a/core/commands/publish.go +++ b/core/commands/publish.go @@ -107,9 +107,15 @@ Publish an to another public key (not implemented): } func publish(n *core.IpfsNode, k crypto.PrivKey, ref path.Path) (*IpnsEntry, error) { + // First, verify the path exists + _, err := n.Resolver.ResolvePath(ref) + if err != nil { + return nil, err + } + pub := nsys.NewRoutingPublisher(n.Routing) - err := pub.Publish(n.Context(), k, ref) + err = pub.Publish(n.Context(), k, ref) if err != nil { return nil, err } diff --git a/core/corehttp/ipns_hostname.go b/core/corehttp/ipns_hostname.go index abfcf4a638a..7361001d1e4 100644 --- a/core/corehttp/ipns_hostname.go +++ b/core/corehttp/ipns_hostname.go @@ -19,8 +19,8 @@ func IPNSHostnameOption() ServeOption { defer cancel() host := strings.SplitN(r.Host, ":", 2)[0] - if k, err := n.Namesys.Resolve(ctx, host); err == nil { - r.URL.Path = "/ipfs/" + k.String() + r.URL.Path + if p, err := n.Namesys.Resolve(ctx, host); err == nil { + r.URL.Path = "/ipfs/" + p.String() + r.URL.Path } childMux.ServeHTTP(w, r) }) diff --git a/path/path.go b/path/path.go index f7d4e43ff3e..e61a061930f 100644 --- a/path/path.go +++ b/path/path.go @@ -49,11 +49,13 @@ func FromSegments(seg ...string) Path { } func ParsePath(txt string) (Path, error) { - kp, err := ParseKeyToPath(txt) - if err == nil { - return kp, nil - } parts := strings.Split(txt, "/") + if len(parts) == 1 { + kp, err := ParseKeyToPath(txt) + if err == nil { + return kp, nil + } + } if len(parts) < 3 { return "", ErrBadPath } @@ -66,7 +68,7 @@ func ParsePath(txt string) (Path, error) { return "", ErrBadPath } - _, err = ParseKeyToPath(parts[2]) + _, err := ParseKeyToPath(parts[2]) if err != nil { return "", err } @@ -86,3 +88,8 @@ func ParseKeyToPath(txt string) (Path, error) { } return FromKey(u.Key(chk)), nil } + +func (p *Path) IsValid() error { + _, err := ParsePath(p.String()) + return err +}