@cryptotaxi247 / kubo / commits / 9ddfafb40

address concerns about user interface with new Path type

Jeromy committed Jan 30, 2015 at 19:55 UTC 9ddfafb40ad8d3c158ca0211183c215e437d77db
5 files changed +27 -12
core/coreunix/add.go
+9 -5
@@ -4,7 +4,7 @@ import (
4 "errors"
5 "io"
6 "os"
7 - "path"
7 + gopath "path"
8
9 "github.com/jbenet/go-ipfs/commands/files"
10 core "github.com/jbenet/go-ipfs/core"
@@ -14,14 +14,13 @@ import (
14 "github.com/jbenet/go-ipfs/pin"
15 "github.com/jbenet/go-ipfs/thirdparty/eventlog"
16 unixfs "github.com/jbenet/go-ipfs/unixfs"
17 - u "github.com/jbenet/go-ipfs/util"
17 )
18
19 var log = eventlog.Logger("coreunix")
20
21 // Add builds a merkledag from the a reader, pinning all objects to the local
22 // datastore. Returns a key representing the root node.
24 -func Add(n *core.IpfsNode, r io.Reader) (u.Key, error) {
23 +func Add(n *core.IpfsNode, r io.Reader) (string, error) {
24 // TODO more attractive function signature importer.BuildDagFromReader
25 dagNode, err := importer.BuildDagFromReader(
26 r,
@@ -35,7 +34,12 @@ func Add(n *core.IpfsNode, r io.Reader) (u.Key, error) {
34 if err := n.Pinning.Flush(); err != nil {
35 return "", err
36 }
38 - return dagNode.Key()
37 + k, err := dagNode.Key()
38 + if err != nil {
39 + return "", err
40 + }
41 +
42 + return k.String(), nil
43 }
44
45 // AddR recursively adds files in |path|.
@@ -124,7 +128,7 @@ Loop:
128 return nil, err
129 }
130
127 - _, name := path.Split(file.FileName())
131 + _, name := gopath.Split(file.FileName())
132
133 err = tree.AddNodeLink(name, node)
134 if err != nil {
core/coreunix/cat.go
+2 -1
@@ -8,7 +8,8 @@ import (
8 uio "github.com/jbenet/go-ipfs/unixfs/io"
9 )
10
11 -func Cat(n *core.IpfsNode, p path.Path) (io.Reader, error) {
11 +func Cat(n *core.IpfsNode, pstr string) (io.Reader, error) {
12 + p := path.FromString(pstr)
13 dagNode, err := n.Resolver.ResolvePath(p)
14 if err != nil {
15 return nil, err
path/path.go
+12
@@ -3,12 +3,24 @@ package path
3 import (
4 "path"
5 "strings"
6 +
7 + u "github.com/jbenet/go-ipfs/util"
8 )
9
10 // TODO: debate making this a private struct wrapped in a public interface
11 // would allow us to control creation, and cache segments.
12 type Path string
13
14 +// FromString safely converts a string type to a Path type
15 +func FromString(s string) Path {
16 + return Path(s)
17 +}
18 +
19 +// FromKey safely converts a Key type to a Path type
20 +func FromKey(k u.Key) Path {
21 + return Path(k.String())
22 +}
23 +
24 func (p Path) Segments() []string {
25 cleaned := path.Clean(string(p))
26 segments := strings.Split(cleaned, "/")
test/integration/addcat_test.go
+2 -3
@@ -15,7 +15,6 @@ 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"
18 "github.com/jbenet/go-ipfs/thirdparty/unit"
19 errors "github.com/jbenet/go-ipfs/util/debugerror"
20 testutil "github.com/jbenet/go-ipfs/util/testutil"
@@ -126,12 +125,12 @@ func DirectAddCat(data []byte, conf testutil.LatencyConfig) error {
125 return err
126 }
127
129 - keyAdded, err := coreunix.Add(adder, bytes.NewReader(data))
128 + added, err := coreunix.Add(adder, bytes.NewReader(data))
129 if err != nil {
130 return err
131 }
132
134 - readerCatted, err := coreunix.Cat(catter, path.Path(keyAdded.String()))
133 + readerCatted, err := coreunix.Cat(catter, added)
134 if err != nil {
135 return err
136 }
test/integration/three_legged_cat_test.go
+2 -3
@@ -12,7 +12,6 @@ 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"
15 "github.com/jbenet/go-ipfs/thirdparty/unit"
16 errors "github.com/jbenet/go-ipfs/util/debugerror"
17 testutil "github.com/jbenet/go-ipfs/util/testutil"
@@ -106,12 +105,12 @@ func RunThreeLeggedCat(data []byte, conf testutil.LatencyConfig) error {
105 return err
106 }
107
109 - keyAdded, err := coreunix.Add(adder, bytes.NewReader(data))
108 + added, err := coreunix.Add(adder, bytes.NewReader(data))
109 if err != nil {
110 return err
111 }
112
114 - readerCatted, err := coreunix.Cat(catter, path.Path(keyAdded.String()))
113 + readerCatted, err := coreunix.Cat(catter, added)
114 if err != nil {
115 return err
116 }