Resolve '/ipfs/root/some/path' paths in 'ipfs resolve' command
License: MIT Signed-off-by: Matt Bell <mappum@gmail.com>
Matt Bell committed
Sep 6, 2015 at 12:49 UTC
eddd64119edbcaadc7e1de03e7134976bf2c8c1c
1 file changed
+30
core/commands/resolve.go
+30
@@ -5,6 +5,7 @@ import (
5
"strings"
6
7
cmds "github.com/ipfs/go-ipfs/commands"
8
+ context "github.com/ipfs/go-ipfs/Godeps/_workspace/src/golang.org/x/net/context"
9
namesys "github.com/ipfs/go-ipfs/namesys"
10
path "github.com/ipfs/go-ipfs/path"
11
u "github.com/ipfs/go-ipfs/util"
@@ -78,6 +79,16 @@ Resolve the value of another name recursively:
79
depth = namesys.DefaultDepthLimit
80
}
81
82
+ if strings.HasPrefix(name, "/ipfs/") || !strings.HasPrefix(name, "/") {
83
+ resolved, err := resolveIpfsPath(req.Context(), n.Resolver, name)
84
+ if err != nil {
85
+ res.SetError(err, cmds.ErrNormal)
86
+ return
87
+ }
88
+ res.SetOutput(&ResolvedPath{resolved})
89
+ return
90
+ }
91
+
92
output, err := n.Namesys.ResolveN(req.Context(), name, depth)
93
if err != nil {
94
res.SetError(err, cmds.ErrNormal)
@@ -97,3 +108,22 @@ Resolve the value of another name recursively:
108
},
109
Type: ResolvedPath{},
110
}
111
+
112
+func resolveIpfsPath (ctx context.Context, r *path.Resolver, name string) (path.Path, error) {
113
+ p, err := path.ParsePath(name)
114
+ if err != nil {
115
+ return "", err
116
+ }
117
+
118
+ node, err := r.ResolvePath(ctx, p)
119
+ if err != nil {
120
+ return "", err
121
+ }
122
+
123
+ key, err := node.Key()
124
+ if err != nil {
125
+ return "", err
126
+ }
127
+
128
+ return path.FromKey(key), nil
129
+}