implement path type
Jeromy committed
Jan 28, 2015 at 05:18 UTC
abb3c9c9c4ee5911bd570926e722277a49e4b3f5
18 files changed
+174
-144
core/commands/cat.go
+3
-2
@@ -5,6 +5,7 @@ import (
5
6
cmds "github.com/jbenet/go-ipfs/commands"
7
core "github.com/jbenet/go-ipfs/core"
8
+ path "github.com/jbenet/go-ipfs/path"
9
uio "github.com/jbenet/go-ipfs/unixfs/io"
10
11
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/cheggaaa/pb"
@@ -61,8 +62,8 @@ it contains.
62
func cat(node *core.IpfsNode, paths []string) ([]io.Reader, uint64, error) {
63
readers := make([]io.Reader, 0, len(paths))
64
length := uint64(0)
64
- for _, path := range paths {
65
- dagnode, err := node.Resolver.ResolvePath(path)
65
+ for _, fpath := range paths {
66
+ dagnode, err := node.Resolver.ResolvePath(path.Path(fpath))
67
if err != nil {
68
return nil, 0, err
69
}
core/commands/get.go
+5
-4
@@ -6,11 +6,12 @@ import (
6
"fmt"
7
"io"
8
"os"
9
- "path"
9
+ gopath "path"
10
"strings"
11
12
cmds "github.com/jbenet/go-ipfs/commands"
13
core "github.com/jbenet/go-ipfs/core"
14
+ path "github.com/jbenet/go-ipfs/path"
15
tar "github.com/jbenet/go-ipfs/thirdparty/tar"
16
utar "github.com/jbenet/go-ipfs/unixfs/tar"
17
@@ -77,8 +78,8 @@ may also specify the level of compression by specifying '-l=<1-9>'.
78
79
outPath, _, _ := req.Option("output").String()
80
if len(outPath) == 0 {
80
- _, outPath = path.Split(req.Arguments()[0])
81
- outPath = path.Clean(outPath)
81
+ _, outPath = gopath.Split(req.Arguments()[0])
82
+ outPath = gopath.Clean(outPath)
83
}
84
85
cmplvl, err := getCompressOptions(req)
@@ -165,5 +166,5 @@ func getCompressOptions(req cmds.Request) (int, error) {
166
}
167
168
func get(node *core.IpfsNode, p string, compression int) (io.Reader, error) {
168
- return utar.NewReader(p, node.DAG, node.Resolver, compression)
169
+ return utar.NewReader(path.Path(p), node.DAG, node.Resolver, compression)
170
}
core/commands/ls.go
+3
-2
@@ -7,6 +7,7 @@ import (
7
8
cmds "github.com/jbenet/go-ipfs/commands"
9
merkledag "github.com/jbenet/go-ipfs/merkledag"
10
+ path "github.com/jbenet/go-ipfs/path"
11
)
12
13
type Link struct {
@@ -47,8 +48,8 @@ it contains, with the following format:
48
paths := req.Arguments()
49
50
dagnodes := make([]*merkledag.Node, 0)
50
- for _, path := range paths {
51
- dagnode, err := node.Resolver.ResolvePath(path)
51
+ for _, fpath := range paths {
52
+ dagnode, err := node.Resolver.ResolvePath(path.Path(fpath))
53
if err != nil {
54
res.SetError(err, cmds.ErrNormal)
55
return
core/commands/object.go
+18
-17
@@ -14,6 +14,7 @@ import (
14
cmds "github.com/jbenet/go-ipfs/commands"
15
core "github.com/jbenet/go-ipfs/core"
16
dag "github.com/jbenet/go-ipfs/merkledag"
17
+ path "github.com/jbenet/go-ipfs/path"
18
)
19
20
// ErrObjectTooLarge is returned when too much data was read from stdin. current limit 512k
@@ -78,8 +79,8 @@ output is the raw data of the object.
79
return
80
}
81
81
- key := req.Arguments()[0]
82
- output, err := objectData(n, key)
82
+ fpath := path.Path(req.Arguments()[0])
83
+ output, err := objectData(n, fpath)
84
if err != nil {
85
res.SetError(err, cmds.ErrNormal)
86
return
@@ -108,8 +109,8 @@ multihash.
109
return
110
}
111
111
- key := req.Arguments()[0]
112
- output, err := objectLinks(n, key)
112
+ fpath := path.Path(req.Arguments()[0])
113
+ output, err := objectLinks(n, fpath)
114
if err != nil {
115
res.SetError(err, cmds.ErrNormal)
116
return
@@ -156,9 +157,9 @@ This command outputs data in the following encodings:
157
return
158
}
159
159
- key := req.Arguments()[0]
160
+ fpath := path.Path(req.Arguments()[0])
161
161
- object, err := objectGet(n, key)
162
+ object, err := objectGet(n, fpath)
163
if err != nil {
164
res.SetError(err, cmds.ErrNormal)
165
return
@@ -222,9 +223,9 @@ var objectStatCmd = &cmds.Command{
223
return
224
}
225
225
- key := req.Arguments()[0]
226
+ fpath := path.Path(req.Arguments()[0])
227
227
- object, err := objectGet(n, key)
228
+ object, err := objectGet(n, fpath)
229
if err != nil {
230
res.SetError(err, cmds.ErrNormal)
231
return
@@ -317,37 +318,37 @@ Data should be in the format specified by <encoding>.
318
}
319
320
// objectData takes a key string and writes out the raw bytes of that node (if there is one)
320
-func objectData(n *core.IpfsNode, key string) (io.Reader, error) {
321
- dagnode, err := n.Resolver.ResolvePath(key)
321
+func objectData(n *core.IpfsNode, fpath path.Path) (io.Reader, error) {
322
+ dagnode, err := n.Resolver.ResolvePath(fpath)
323
if err != nil {
324
return nil, err
325
}
326
326
- log.Debugf("objectData: found dagnode %q (# of bytes: %d - # links: %d)", key, len(dagnode.Data), len(dagnode.Links))
327
+ log.Debugf("objectData: found dagnode %s (# of bytes: %d - # links: %d)", fpath, len(dagnode.Data), len(dagnode.Links))
328
329
return bytes.NewReader(dagnode.Data), nil
330
}
331
332
// objectLinks takes a key string and lists the links it points to
332
-func objectLinks(n *core.IpfsNode, key string) (*Object, error) {
333
- dagnode, err := n.Resolver.ResolvePath(key)
333
+func objectLinks(n *core.IpfsNode, fpath path.Path) (*Object, error) {
334
+ dagnode, err := n.Resolver.ResolvePath(fpath)
335
if err != nil {
336
return nil, err
337
}
338
338
- log.Debugf("objectLinks: found dagnode %q (# of bytes: %d - # links: %d)", key, len(dagnode.Data), len(dagnode.Links))
339
+ log.Debugf("objectLinks: found dagnode %s (# of bytes: %d - # links: %d)", fpath, len(dagnode.Data), len(dagnode.Links))
340
341
return getOutput(dagnode)
342
}
343
344
// objectGet takes a key string from args and a format option and serializes the dagnode to that format
344
-func objectGet(n *core.IpfsNode, key string) (*dag.Node, error) {
345
- dagnode, err := n.Resolver.ResolvePath(key)
345
+func objectGet(n *core.IpfsNode, fpath path.Path) (*dag.Node, error) {
346
+ dagnode, err := n.Resolver.ResolvePath(fpath)
347
if err != nil {
348
return nil, err
349
}
350
350
- log.Debugf("objectGet: found dagnode %q (# of bytes: %d - # links: %d)", key, len(dagnode.Data), len(dagnode.Links))
351
+ log.Debugf("objectGet: found dagnode %s (# of bytes: %d - # links: %d)", fpath, len(dagnode.Data), len(dagnode.Links))
352
353
return dagnode, nil
354
}
core/commands/refs.go
+2
-1
@@ -11,6 +11,7 @@ import (
11
cmds "github.com/jbenet/go-ipfs/commands"
12
"github.com/jbenet/go-ipfs/core"
13
dag "github.com/jbenet/go-ipfs/merkledag"
14
+ path "github.com/jbenet/go-ipfs/path"
15
u "github.com/jbenet/go-ipfs/util"
16
)
17
@@ -166,7 +167,7 @@ Displays the hashes of all local objects.
167
func objectsForPaths(n *core.IpfsNode, paths []string) ([]*dag.Node, error) {
168
objects := make([]*dag.Node, len(paths))
169
for i, p := range paths {
169
- o, err := n.Resolver.ResolvePath(p)
170
+ o, err := n.Resolver.ResolvePath(path.Path(p))
171
if err != nil {
172
return nil, err
173
}
core/core.go
+2
-2
@@ -286,8 +286,8 @@ func (n *IpfsNode) OnlineMode() bool {
286
}
287
}
288
289
-func (n *IpfsNode) Resolve(path string) (*merkledag.Node, error) {
290
- return n.Resolver.ResolvePath(path)
289
+func (n *IpfsNode) Resolve(fpath string) (*merkledag.Node, error) {
290
+ return n.Resolver.ResolvePath(path.Path(fpath))
291
}
292
293
func (n *IpfsNode) Bootstrap(cfg BootstrapConfig) error {
core/corehttp/gateway_handler.go
+9
-8
@@ -4,7 +4,7 @@ import (
4
"html/template"
5
"io"
6
"net/http"
7
- "path"
7
+ gopath "path"
8
"strings"
9
"time"
10
@@ -15,6 +15,7 @@ import (
15
"github.com/jbenet/go-ipfs/importer"
16
chunk "github.com/jbenet/go-ipfs/importer/chunk"
17
dag "github.com/jbenet/go-ipfs/merkledag"
18
+ path "github.com/jbenet/go-ipfs/path"
19
"github.com/jbenet/go-ipfs/routing"
20
uio "github.com/jbenet/go-ipfs/unixfs/io"
21
u "github.com/jbenet/go-ipfs/util"
@@ -71,7 +72,7 @@ func (i *gatewayHandler) loadTemplate() error {
72
}
73
74
func (i *gatewayHandler) ResolvePath(ctx context.Context, p string) (*dag.Node, string, error) {
74
- p = path.Clean(p)
75
+ p = gopath.Clean(p)
76
77
if strings.HasPrefix(p, IpnsPathPrefix) {
78
elements := strings.Split(p[len(IpnsPathPrefix):], "/")
@@ -82,13 +83,13 @@ func (i *gatewayHandler) ResolvePath(ctx context.Context, p string) (*dag.Node,
83
}
84
85
elements[0] = k.Pretty()
85
- p = path.Join(elements...)
86
+ p = gopath.Join(elements...)
87
}
88
if !strings.HasPrefix(p, IpfsPathPrefix) {
88
- p = path.Join(IpfsPathPrefix, p)
89
+ p = gopath.Join(IpfsPathPrefix, p)
90
}
91
91
- node, err := i.node.Resolver.ResolvePath(p)
92
+ node, err := i.node.Resolver.ResolvePath(path.Path(p))
93
if err != nil {
94
return nil, "", err
95
}
@@ -129,7 +130,7 @@ func (i *gatewayHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
130
return
131
}
132
132
- etag := path.Base(p)
133
+ etag := gopath.Base(p)
134
if r.Header.Get("If-None-Match") == etag {
135
w.WriteHeader(http.StatusNotModified)
136
return
@@ -151,7 +152,7 @@ func (i *gatewayHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
152
153
if err == nil {
154
defer dr.Close()
154
- _, name := path.Split(urlPath)
155
+ _, name := gopath.Split(urlPath)
156
// set modtime to a really long time ago, since files are immutable and should stay cached
157
modtime := time.Unix(1, 0)
158
http.ServeContent(w, r, name, modtime, dr)
@@ -188,7 +189,7 @@ func (i *gatewayHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
189
break
190
}
191
191
- di := directoryItem{link.Size, link.Name, path.Join(urlPath, link.Name)}
192
+ di := directoryItem{link.Size, link.Name, gopath.Join(urlPath, link.Name)}
193
dirListing = append(dirListing, di)
194
}
195
core/corerepo/pinning.go
+5
-4
@@ -5,14 +5,15 @@ import (
5
6
"github.com/jbenet/go-ipfs/core"
7
"github.com/jbenet/go-ipfs/merkledag"
8
+ path "github.com/jbenet/go-ipfs/path"
9
u "github.com/jbenet/go-ipfs/util"
10
)
11
12
func Pin(n *core.IpfsNode, paths []string, recursive bool) ([]u.Key, error) {
13
14
dagnodes := make([]*merkledag.Node, 0)
14
- for _, path := range paths {
15
- dagnode, err := n.Resolver.ResolvePath(path)
15
+ for _, fpath := range paths {
16
+ dagnode, err := n.Resolver.ResolvePath(path.Path(fpath))
17
if err != nil {
18
return nil, fmt.Errorf("pin: %s", err)
19
}
@@ -44,8 +45,8 @@ func Pin(n *core.IpfsNode, paths []string, recursive bool) ([]u.Key, error) {
45
func Unpin(n *core.IpfsNode, paths []string, recursive bool) ([]u.Key, error) {
46
47
dagnodes := make([]*merkledag.Node, 0)
47
- for _, path := range paths {
48
- dagnode, err := n.Resolver.ResolvePath(path)
48
+ for _, fpath := range paths {
49
+ dagnode, err := n.Resolver.ResolvePath(path.Path(fpath))
50
if err != nil {
51
return nil, err
52
}
core/coreunix/cat.go
+3
-2
@@ -4,11 +4,12 @@ import (
4
"io"
5
6
core "github.com/jbenet/go-ipfs/core"
7
+ path "github.com/jbenet/go-ipfs/path"
8
uio "github.com/jbenet/go-ipfs/unixfs/io"
9
)
10
10
-func Cat(n *core.IpfsNode, path string) (io.Reader, error) {
11
- dagNode, err := n.Resolver.ResolvePath(path)
11
+func Cat(n *core.IpfsNode, p path.Path) (io.Reader, error) {
12
+ dagNode, err := n.Resolver.ResolvePath(p)
13
if err != nil {
14
return nil, err
15
}
fuse/ipns/ipns_unix.go
+2
-1
@@ -19,6 +19,7 @@ import (
19
mdag "github.com/jbenet/go-ipfs/merkledag"
20
nsys "github.com/jbenet/go-ipfs/namesys"
21
ci "github.com/jbenet/go-ipfs/p2p/crypto"
22
+ path "github.com/jbenet/go-ipfs/path"
23
ft "github.com/jbenet/go-ipfs/unixfs"
24
uio "github.com/jbenet/go-ipfs/unixfs/io"
25
ftpb "github.com/jbenet/go-ipfs/unixfs/pb"
@@ -129,7 +130,7 @@ func CreateRoot(n *core.IpfsNode, keys []ci.PrivKey, ipfsroot string) (*Root, er
130
return nil, nil
131
}
132
132
- node, err := n.Resolver.ResolvePath(pointsTo.B58String())
133
+ node, err := n.Resolver.ResolvePath(path.Path(pointsTo.B58String()))
134
if err != nil {
135
log.Warning("Failed to resolve value from ipns entry in ipfs")
136
continue
fuse/readonly/readonly_unix.go
+2
-1
@@ -15,6 +15,7 @@ import (
15
16
core "github.com/jbenet/go-ipfs/core"
17
mdag "github.com/jbenet/go-ipfs/merkledag"
18
+ path "github.com/jbenet/go-ipfs/path"
19
uio "github.com/jbenet/go-ipfs/unixfs/io"
20
ftpb "github.com/jbenet/go-ipfs/unixfs/pb"
21
u "github.com/jbenet/go-ipfs/util"
@@ -56,7 +57,7 @@ func (s *Root) Lookup(name string, intr fs.Intr) (fs.Node, fuse.Error) {
57
return nil, fuse.ENOENT
58
}
59
59
- nd, err := s.Ipfs.Resolver.ResolvePath(name)
60
+ nd, err := s.Ipfs.Resolver.ResolvePath(path.Path(name))
61
if err != nil {
62
// todo: make this error more versatile.
63
return nil, fuse.ENOENT
path/path.go
+12
-90
@@ -1,104 +1,26 @@
1
-// package path implements utilities for resolving paths within ipfs.
1
package path
2
3
import (
5
- "fmt"
4
"path"
5
"strings"
8
-
9
- mh "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multihash"
10
- merkledag "github.com/jbenet/go-ipfs/merkledag"
11
- u "github.com/jbenet/go-ipfs/util"
6
)
7
14
-var log = u.Logger("path")
15
-
16
-// Resolver provides path resolution to IPFS
17
-// It has a pointer to a DAGService, which is uses to resolve nodes.
18
-type Resolver struct {
19
- DAG merkledag.DAGService
20
-}
21
-
22
-// ResolvePath fetches the node for given path. It uses the first
23
-// path component as a hash (key) of the first node, then resolves
24
-// all other components walking the links, with ResolveLinks.
25
-func (s *Resolver) ResolvePath(fpath string) (*merkledag.Node, error) {
26
- log.Debugf("Resolve: '%s'", fpath)
27
- fpath = path.Clean(fpath)
28
-
29
- if strings.HasPrefix(fpath, "/ipfs/") {
30
- fpath = fpath[6:]
31
- }
32
-
33
- parts := strings.Split(fpath, "/")
34
-
35
- // skip over empty first elem
36
- if len(parts[0]) == 0 {
37
- parts = parts[1:]
38
- }
39
-
40
- // if nothing, bail.
41
- if len(parts) == 0 {
42
- return nil, fmt.Errorf("ipfs path must contain at least one component")
43
- }
8
+// TODO: debate making this a private struct wrapped in a public interface
9
+// would allow us to control creation, and cache segments.
10
+type Path string
11
45
- // first element in the path is a b58 hash (for now)
46
- h, err := mh.FromB58String(parts[0])
47
- if err != nil {
48
- log.Debug("given path element is not a base58 string.\n")
49
- return nil, err
50
- }
12
+func (p Path) Segments() []string {
13
+ cleaned := path.Clean(string(p))
14
+ segments := strings.Split(cleaned, "/")
15
52
- log.Debug("Resolve dag get.\n")
53
- nd, err := s.DAG.Get(u.Key(h))
54
- if err != nil {
55
- return nil, err
16
+ // Ignore leading slash
17
+ if len(segments[0]) == 0 {
18
+ segments = segments[1:]
19
}
20
58
- return s.ResolveLinks(nd, parts[1:])
21
+ return segments
22
}
23
61
-// ResolveLinks iteratively resolves names by walking the link hierarchy.
62
-// Every node is fetched from the DAGService, resolving the next name.
63
-// Returns the last node found.
64
-//
65
-// ResolveLinks(nd, []string{"foo", "bar", "baz"})
66
-// would retrieve "baz" in ("bar" in ("foo" in nd.Links).Links).Links
67
-func (s *Resolver) ResolveLinks(ndd *merkledag.Node, names []string) (
68
- nd *merkledag.Node, err error) {
69
-
70
- nd = ndd // dup arg workaround
71
-
72
- // for each of the path components
73
- for _, name := range names {
74
-
75
- var next u.Key
76
- var nlink *merkledag.Link
77
- // for each of the links in nd, the current object
78
- for _, link := range nd.Links {
79
- if link.Name == name {
80
- next = u.Key(link.Hash)
81
- nlink = link
82
- break
83
- }
84
- }
85
-
86
- if next == "" {
87
- h1, _ := nd.Multihash()
88
- h2 := h1.B58String()
89
- return nil, fmt.Errorf("no link named %q under %s", name, h2)
90
- }
91
-
92
- if nlink.Node == nil {
93
- // fetch object for link and assign to nd
94
- nd, err = s.DAG.Get(next)
95
- if err != nil {
96
- return nd, err
97
- }
98
- nlink.Node = nd
99
- } else {
100
- nd = nlink.Node
101
- }
102
- }
103
- return
24
+func (p Path) String() string {
25
+ return string(p)
26
}
path/resolver.go
new
+95
@@ -0,0 +1,95 @@
1
+// package path implements utilities for resolving paths within ipfs.
2
+package path
3
+
4
+import (
5
+ "fmt"
6
+
7
+ mh "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multihash"
8
+ merkledag "github.com/jbenet/go-ipfs/merkledag"
9
+ u "github.com/jbenet/go-ipfs/util"
10
+)
11
+
12
+var log = u.Logger("path")
13
+
14
+// Resolver provides path resolution to IPFS
15
+// It has a pointer to a DAGService, which is uses to resolve nodes.
16
+type Resolver struct {
17
+ DAG merkledag.DAGService
18
+}
19
+
20
+// ResolvePath fetches the node for given path. It uses the first
21
+// path component as a hash (key) of the first node, then resolves
22
+// all other components walking the links, with ResolveLinks.
23
+func (s *Resolver) ResolvePath(fpath Path) (*merkledag.Node, error) {
24
+ log.Debugf("Resolve: '%s'", fpath)
25
+
26
+ parts := fpath.Segments()
27
+ if parts[0] == "ipfs" {
28
+ parts = parts[1:]
29
+ }
30
+
31
+ // if nothing, bail.
32
+ if len(parts) == 0 {
33
+ return nil, fmt.Errorf("ipfs path must contain at least one component")
34
+ }
35
+
36
+ // first element in the path is a b58 hash (for now)
37
+ h, err := mh.FromB58String(parts[0])
38
+ if err != nil {
39
+ log.Debug("given path element is not a base58 string.\n")
40
+ return nil, err
41
+ }
42
+
43
+ log.Debug("Resolve dag get.\n")
44
+ nd, err := s.DAG.Get(u.Key(h))
45
+ if err != nil {
46
+ return nil, err
47
+ }
48
+
49
+ return s.ResolveLinks(nd, parts[1:])
50
+}
51
+
52
+// ResolveLinks iteratively resolves names by walking the link hierarchy.
53
+// Every node is fetched from the DAGService, resolving the next name.
54
+// Returns the last node found.
55
+//
56
+// ResolveLinks(nd, []string{"foo", "bar", "baz"})
57
+// would retrieve "baz" in ("bar" in ("foo" in nd.Links).Links).Links
58
+func (s *Resolver) ResolveLinks(ndd *merkledag.Node, names []string) (
59
+ nd *merkledag.Node, err error) {
60
+
61
+ nd = ndd // dup arg workaround
62
+
63
+ // for each of the path components
64
+ for _, name := range names {
65
+
66
+ var next u.Key
67
+ var nlink *merkledag.Link
68
+ // for each of the links in nd, the current object
69
+ for _, link := range nd.Links {
70
+ if link.Name == name {
71
+ next = u.Key(link.Hash)
72
+ nlink = link
73
+ break
74
+ }
75
+ }
76
+
77
+ if next == "" {
78
+ h1, _ := nd.Multihash()
79
+ h2 := h1.B58String()
80
+ return nil, fmt.Errorf("no link named %q under %s", name, h2)
81
+ }
82
+
83
+ if nlink.Node == nil {
84
+ // fetch object for link and assign to nd
85
+ nd, err = s.DAG.Get(next)
86
+ if err != nil {
87
+ return nd, err
88
+ }
89
+ nlink.Node = nd
90
+ } else {
91
+ nd = nlink.Node
92
+ }
93
+ }
94
+ return
95
+}
server/http/ipfs.go
+3
-2
@@ -8,6 +8,7 @@ import (
8
"github.com/jbenet/go-ipfs/importer"
9
chunk "github.com/jbenet/go-ipfs/importer/chunk"
10
dag "github.com/jbenet/go-ipfs/merkledag"
11
+ path "github.com/jbenet/go-ipfs/path"
12
uio "github.com/jbenet/go-ipfs/unixfs/io"
13
u "github.com/jbenet/go-ipfs/util"
14
)
@@ -23,8 +24,8 @@ type ipfsHandler struct {
24
node *core.IpfsNode
25
}
26
26
-func (i *ipfsHandler) ResolvePath(path string) (*dag.Node, error) {
27
- return i.node.Resolver.ResolvePath(path)
27
+func (i *ipfsHandler) ResolvePath(fpath string) (*dag.Node, error) {
28
+ return i.node.Resolver.ResolvePath(path.Path(fpath))
29
}
30
31
func (i *ipfsHandler) NewDagFromReader(r io.Reader) (*dag.Node, error) {
test/epictest/addcat_test.go
+2
-1
@@ -15,6 +15,7 @@ import (
15
coreunix "github.com/jbenet/go-ipfs/core/coreunix"
16
mocknet "github.com/jbenet/go-ipfs/p2p/net/mock"
17
"github.com/jbenet/go-ipfs/p2p/peer"
18
+ path "github.com/jbenet/go-ipfs/path"
19
"github.com/jbenet/go-ipfs/thirdparty/unit"
20
errors "github.com/jbenet/go-ipfs/util/debugerror"
21
testutil "github.com/jbenet/go-ipfs/util/testutil"
@@ -130,7 +131,7 @@ func DirectAddCat(data []byte, conf testutil.LatencyConfig) error {
131
return err
132
}
133
133
- readerCatted, err := coreunix.Cat(catter, keyAdded.String())
134
+ readerCatted, err := coreunix.Cat(catter, path.Path(keyAdded.String()))
135
if err != nil {
136
return err
137
}
test/epictest/three_legged_cat_test.go
+2
-1
@@ -12,6 +12,7 @@ import (
12
coreunix "github.com/jbenet/go-ipfs/core/coreunix"
13
mocknet "github.com/jbenet/go-ipfs/p2p/net/mock"
14
"github.com/jbenet/go-ipfs/p2p/peer"
15
+ path "github.com/jbenet/go-ipfs/path"
16
"github.com/jbenet/go-ipfs/thirdparty/unit"
17
errors "github.com/jbenet/go-ipfs/util/debugerror"
18
testutil "github.com/jbenet/go-ipfs/util/testutil"
@@ -110,7 +111,7 @@ func RunThreeLeggedCat(data []byte, conf testutil.LatencyConfig) error {
111
return err
112
}
113
113
- readerCatted, err := coreunix.Cat(catter, keyAdded.String())
114
+ readerCatted, err := coreunix.Cat(catter, path.Path(keyAdded.String()))
115
if err != nil {
116
return err
117
}
unixfs/tar/reader.go
+2
-6
@@ -7,7 +7,6 @@ import (
7
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
8
"io"
9
gopath "path"
10
- "strings"
10
"time"
11
12
mdag "github.com/jbenet/go-ipfs/merkledag"
@@ -29,10 +28,7 @@ type Reader struct {
28
err error
29
}
30
32
-func NewReader(path string, dag mdag.DAGService, resolver *path.Resolver, compression int) (*Reader, error) {
33
- if strings.HasPrefix(path, "/ipfs/") {
34
- path = path[6:]
35
- }
31
+func NewReader(path path.Path, dag mdag.DAGService, resolver *path.Resolver, compression int) (*Reader, error) {
32
33
reader := &Reader{
34
signalChan: make(chan struct{}),
@@ -58,7 +54,7 @@ func NewReader(path string, dag mdag.DAGService, resolver *path.Resolver, compre
54
55
// writeToBuf will write the data to the buffer, and will signal when there
56
// is new data to read
61
- _, filename := gopath.Split(path)
57
+ _, filename := gopath.Split(path.String())
58
go reader.writeToBuf(dagnode, filename, 0)
59
60
return reader, nil
util/key.go
+4
@@ -120,6 +120,10 @@ func IsValidHash(s string) bool {
120
if out == nil || len(out) == 0 {
121
return false
122
}
123
+ _, err := mh.Cast(out)
124
+ if err != nil {
125
+ return false
126
+ }
127
return true
128
}
129