Use core path resolver for 'resolve command' [1]
[1] https://github.com/ipfs/go-ipfs/commit/172eeb87fa2301d7f52c5ecb28f37f5d06126c29 License: MIT Signed-off-by: rht <rhtbot@gmail.com>
rht committed
Oct 13, 2015 at 16:14 UTC
2e0c072dac3b0d08ac3abe3bc1af5d2850caa677
1 file changed
+20
-30
core/commands/resolve.go
+20
-30
@@ -4,9 +4,8 @@ import (
4
"io"
5
"strings"
6
7
- context "github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
7
cmds "github.com/ipfs/go-ipfs/commands"
9
- namesys "github.com/ipfs/go-ipfs/namesys"
8
+ "github.com/ipfs/go-ipfs/core"
9
path "github.com/ipfs/go-ipfs/path"
10
u "github.com/ipfs/go-ipfs/util"
11
)
@@ -79,33 +78,38 @@ Resolve the value of an IPFS DAG path:
78
79
name := req.Arguments()[0]
80
recursive, _, _ := req.Option("recursive").Bool()
82
- depth := 1
83
- if recursive {
84
- depth = namesys.DefaultDepthLimit
81
+
82
+ // the case when ipns is resolved step by step
83
+ if strings.HasPrefix(name, "/ipns/") && !recursive {
84
+ p, err := n.Namesys.ResolveN(req.Context(), name, 1)
85
+ if err != nil {
86
+ res.SetError(err, cmds.ErrNormal)
87
+ return
88
+ }
89
+ res.SetOutput(&ResolvedPath{p})
90
+ return
91
}
92
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, "/") {
91
- p, err = path.ParsePath(name)
92
- } else {
93
- p, err = n.Namesys.ResolveN(req.Context(), name, depth)
93
+ // else, ipfs path or ipns with recursive flag
94
+ p, err := path.ParsePath(name)
95
+ if err != nil {
96
+ res.SetError(err, cmds.ErrNormal)
97
+ return
98
}
99
+
100
+ node, err := core.Resolve(req.Context(), n, p)
101
if err != nil {
102
res.SetError(err, cmds.ErrNormal)
103
return
104
}
105
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)
106
+ key, err := node.Key()
107
if err != nil {
108
res.SetError(err, cmds.ErrNormal)
109
return
110
}
111
108
- res.SetOutput(&ResolvedPath{output})
112
+ res.SetOutput(&ResolvedPath{path.FromKey(key)})
113
},
114
Marshalers: cmds.MarshalerMap{
115
cmds.Text: func(res cmds.Response) (io.Reader, error) {
@@ -118,17 +122,3 @@ Resolve the value of an IPFS DAG path:
122
},
123
Type: ResolvedPath{},
124
}
121
-
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
126
- }
127
-
128
- key, err := node.Key()
129
- if err != nil {
130
- return "", err
131
- }
132
-
133
- return path.FromKey(key), nil
134
-}