@cryptotaxi247 / kubo / commits / 3a2b83d90

resolve cmd: Fully resolve IPFS paths after resolving IPNS names

License: MIT Signed-off-by: Matt Bell <mappum@gmail.com>

Matt Bell committed Sep 6, 2015 at 16:00 UTC 3a2b83d904c51aebabf78de048cdf6651d7af279
1 file changed +14 -14
core/commands/resolve.go
+14 -14
@@ -4,8 +4,8 @@ import (
4 "io"
5 "strings"
6
7 - cmds "github.com/ipfs/go-ipfs/commands"
7 context "github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
8 + cmds "github.com/ipfs/go-ipfs/commands"
9 namesys "github.com/ipfs/go-ipfs/namesys"
10 path "github.com/ipfs/go-ipfs/path"
11 u "github.com/ipfs/go-ipfs/util"
@@ -84,17 +84,22 @@ Resolve the value of an IPFS DAG path:
84 depth = namesys.DefaultDepthLimit
85 }
86
87 + // for /ipfs/ paths, just parse the path
88 + // for /ipns/ paths, resolve into a /ipfs/ path
89 + var p path.Path
90 if strings.HasPrefix(name, "/ipfs/") || !strings.HasPrefix(name, "/") {
88 - resolved, err := resolveIpfsPath(req.Context(), n.Resolver, name)
89 - if err != nil {
90 - res.SetError(err, cmds.ErrNormal)
91 - return
92 - }
93 - res.SetOutput(&ResolvedPath{resolved})
91 + p, err = path.ParsePath(name)
92 + } else {
93 + p, err = n.Namesys.ResolveN(req.Context(), name, depth)
94 + }
95 + if err != nil {
96 + res.SetError(err, cmds.ErrNormal)
97 return
98 }
99
97 - output, err := n.Namesys.ResolveN(req.Context(), name, depth)
100 + // now fully resolve the /ipfs/ path
101 + // (walk DAG links if there is a path of link names)
102 + output, err := resolveIpfsPath(req.Context(), n.Resolver, p)
103 if err != nil {
104 res.SetError(err, cmds.ErrNormal)
105 return
@@ -114,12 +119,7 @@ Resolve the value of an IPFS DAG path:
119 Type: ResolvedPath{},
120 }
121
117 -func resolveIpfsPath (ctx context.Context, r *path.Resolver, name string) (path.Path, error) {
118 - p, err := path.ParsePath(name)
119 - if err != nil {
120 - return "", err
121 - }
122 -
122 +func resolveIpfsPath(ctx context.Context, r *path.Resolver, p path.Path) (path.Path, error) {
123 node, err := r.ResolvePath(ctx, p)
124 if err != nil {
125 return "", err