@cryptotaxi247 / kubo / commits / a49c07a17

Drop some coreunix code

License: MIT Signed-off-by: Łukasz Magiera <magik6k@gmail.com>

Łukasz Magiera committed Jan 22, 2019 at 15:00 UTC a49c07a1766c9786079ee9f79dd95ac2039d1371
8 files changed +123 -231
assets/assets.go
+21 -27
@@ -4,15 +4,17 @@
4 package assets
5
6 import (
7 - "bytes"
7 "fmt"
8 "os"
9 "path/filepath"
10
11 "github.com/ipfs/go-ipfs/core"
13 - "github.com/ipfs/go-ipfs/core/coreunix"
12 + "github.com/ipfs/go-ipfs/core/coreapi"
13 + "github.com/ipfs/go-ipfs/core/coreapi/interface"
14 + "github.com/ipfs/go-ipfs/core/coreapi/interface/options"
15 +
16 cid "gx/ipfs/QmR8BauakNcBa3RbE4nbQu76PDiJgoQgz8AJdhJuiU4TAw/go-cid"
15 - uio "gx/ipfs/QmSMJ4rZbCJaih3y82Ebq7BZqK6vU2FHsKcWKQiE1DPTpS/go-unixfs/io"
17 + files "gx/ipfs/QmXWZCd8jfaHmt4UDSnjKmGcrQMw95bDGWqEeVLVJjoANX/go-ipfs-files"
18
19 // this import keeps gx from thinking the dep isn't used
20 _ "gx/ipfs/QmT1jwrqzSMjSjLG5oBd9w4P9vXPKQksWuf5ghsE3Q88ZV/dir-index-html"
@@ -45,7 +47,17 @@ func SeedInitDirIndex(nd *core.IpfsNode) (cid.Cid, error) {
47 }
48
49 func addAssetList(nd *core.IpfsNode, l []string) (cid.Cid, error) {
48 - dirb := uio.NewDirectory(nd.DAG)
50 + api, err := coreapi.NewCoreAPI(nd)
51 + if err != nil {
52 + return cid.Cid{}, err
53 + }
54 +
55 + dirb, err := api.Object().New(nd.Context(), options.Object.Type("unixfs-dir"))
56 + if err != nil {
57 + return cid.Cid{}, err
58 + }
59 +
60 + basePath := iface.IpfsPath(dirb.Cid())
61
62 for _, p := range l {
63 d, err := Asset(p)
@@ -53,40 +65,22 @@ func addAssetList(nd *core.IpfsNode, l []string) (cid.Cid, error) {
65 return cid.Cid{}, fmt.Errorf("assets: could load Asset '%s': %s", p, err)
66 }
67
56 - s, err := coreunix.Add(nd, bytes.NewBuffer(d))
68 + fp, err := api.Unixfs().Add(nd.Context(), files.NewBytesFile(d))
69 if err != nil {
58 - return cid.Cid{}, fmt.Errorf("assets: could not Add '%s': %s", p, err)
70 + return cid.Cid{}, err
71 }
72
73 fname := filepath.Base(p)
74
63 - c, err := cid.Decode(s)
75 + basePath, err = api.Object().AddLink(nd.Context(), basePath, fname, fp)
76 if err != nil {
77 return cid.Cid{}, err
78 }
67 -
68 - node, err := nd.DAG.Get(nd.Context(), c)
69 - if err != nil {
70 - return cid.Cid{}, err
71 - }
72 -
73 - if err := dirb.AddChild(nd.Context(), fname, node); err != nil {
74 - return cid.Cid{}, fmt.Errorf("assets: could not add '%s' as a child: %s", fname, err)
75 - }
79 }
80
78 - dir, err := dirb.GetNode()
79 - if err != nil {
81 + if err := api.Pin().Add(nd.Context(), basePath); err != nil {
82 return cid.Cid{}, err
83 }
84
83 - if err := nd.Pinning.Pin(nd.Context(), dir, true); err != nil {
84 - return cid.Cid{}, fmt.Errorf("assets: Pinning on init-docu failed: %s", err)
85 - }
86 -
87 - if err := nd.Pinning.Flush(); err != nil {
88 - return cid.Cid{}, fmt.Errorf("assets: Pinning flush failed: %s", err)
89 - }
90 -
91 - return dir.Cid(), nil
85 + return basePath.Cid(), nil
86 }
cmd/ipfswatch/main.go
+22 -2
@@ -11,11 +11,12 @@ import (
11
12 commands "github.com/ipfs/go-ipfs/commands"
13 core "github.com/ipfs/go-ipfs/core"
14 + coreapi "github.com/ipfs/go-ipfs/core/coreapi"
15 corehttp "github.com/ipfs/go-ipfs/core/corehttp"
15 - coreunix "github.com/ipfs/go-ipfs/core/coreunix"
16 fsrepo "github.com/ipfs/go-ipfs/repo/fsrepo"
17
18 process "gx/ipfs/QmSF8fPo3jgVBAy8fpdjjYqgG87dkJgUprRBHRd2tmfgpP/goprocess"
19 + files "gx/ipfs/QmXWZCd8jfaHmt4UDSnjKmGcrQMw95bDGWqEeVLVJjoANX/go-ipfs-files"
20 config "gx/ipfs/QmcRKBUqc2p3L1ZraoJjbXfs9E6xzvEuyK9iypb5RGwfsr/go-ipfs-config"
21 homedir "gx/ipfs/QmdcULN1WCzgoQmcCaUAmEhwcxHYsDrbZ2LvRJKCL8dMrK/go-homedir"
22 fsnotify "gx/ipfs/QmfNjggF4Pt6erqg3NDafD3MdvDHk1qqCVr8pL5hnPucS8/fsnotify"
@@ -83,6 +84,11 @@ func run(ipfsPath, watchPath string) error {
84 }
85 defer node.Close()
86
87 + api, err := coreapi.NewCoreAPI(node)
88 + if err != nil {
89 + return err
90 + }
91 +
92 if *http {
93 addr := "/ip4/127.0.0.1/tcp/5001"
94 var opts = []corehttp.ServeOption{
@@ -130,9 +136,23 @@ func run(ipfsPath, watchPath string) error {
136 file, err := os.Open(e.Name)
137 if err != nil {
138 log.Println(err)
139 + return
140 }
141 defer file.Close()
135 - k, err := coreunix.Add(node, file)
142 +
143 + st, err := file.Stat()
144 + if err != nil {
145 + log.Println(err)
146 + return
147 + }
148 +
149 + f, err := files.NewReaderPathFile(e.Name, file, st)
150 + if err != nil {
151 + log.Println(err)
152 + return
153 + }
154 +
155 + k, err := api.Unixfs().Add(node.Context(), f)
156 if err != nil {
157 log.Println(err)
158 }
core/corehttp/gateway_test.go
+56 -69
@@ -13,15 +13,17 @@ import (
13
14 version "github.com/ipfs/go-ipfs"
15 core "github.com/ipfs/go-ipfs/core"
16 - coreunix "github.com/ipfs/go-ipfs/core/coreunix"
16 + "github.com/ipfs/go-ipfs/core/coreapi"
17 + "github.com/ipfs/go-ipfs/core/coreapi/interface"
18 + "github.com/ipfs/go-ipfs/core/coreapi/interface/options"
19 namesys "github.com/ipfs/go-ipfs/namesys"
20 nsopts "github.com/ipfs/go-ipfs/namesys/opts"
21 repo "github.com/ipfs/go-ipfs/repo"
22
23 ci "gx/ipfs/QmNiJiXwWE3kRhZrC5ej3kSjWHm337pYfhjLGSCDNKJP2s/go-libp2p-crypto"
24 path "gx/ipfs/QmWqh9oob7ZHQRwU5CdTqpnC8ip8BEkFNrwXRxeNo5Y7vA/go-path"
25 + files "gx/ipfs/QmXWZCd8jfaHmt4UDSnjKmGcrQMw95bDGWqEeVLVJjoANX/go-ipfs-files"
26 id "gx/ipfs/QmYxivS34F2M2n44WQQnRHGAKS8aoRUxwGpi9wk4Cdn4Jf/go-libp2p/p2p/protocol/identify"
24 - dag "gx/ipfs/Qmb2UEG2TAeVrEJSjqsZF7Y2he7wRDkrdt6c3bECxwZf4k/go-merkledag"
27 config "gx/ipfs/QmcRKBUqc2p3L1ZraoJjbXfs9E6xzvEuyK9iypb5RGwfsr/go-ipfs-config"
28 datastore "gx/ipfs/Qmf4xQhNomPNhrtZc67qSnfJSjxjXs9LWvknJtSXwimPrM/go-datastore"
29 syncds "gx/ipfs/Qmf4xQhNomPNhrtZc67qSnfJSjxjXs9LWvknJtSXwimPrM/go-datastore/sync"
@@ -117,7 +119,7 @@ func doWithoutRedirect(req *http.Request) (*http.Response, error) {
119 return res, nil
120 }
121
120 -func newTestServerAndNode(t *testing.T, ns mockNamesys) (*httptest.Server, *core.IpfsNode) {
122 +func newTestServerAndNode(t *testing.T, ns mockNamesys) (*httptest.Server, iface.CoreAPI, context.Context) {
123 n, err := newNodeWithMockNamesys(ns)
124 if err != nil {
125 t.Fatal(err)
@@ -144,23 +146,28 @@ func newTestServerAndNode(t *testing.T, ns mockNamesys) (*httptest.Server, *core
146 t.Fatal(err)
147 }
148
147 - return ts, n
149 + api, err := coreapi.NewCoreAPI(n)
150 + if err != nil {
151 + t.Fatal(err)
152 + }
153 +
154 + return ts, api, n.Context()
155 }
156
157 func TestGatewayGet(t *testing.T) {
158 ns := mockNamesys{}
152 - ts, n := newTestServerAndNode(t, ns)
159 + ts, api, ctx := newTestServerAndNode(t, ns)
160 defer ts.Close()
161
155 - k, err := coreunix.Add(n, strings.NewReader("fnord"))
162 + k, err := api.Unixfs().Add(ctx, files.NewBytesFile([]byte("fnord")))
163 if err != nil {
164 t.Fatal(err)
165 }
159 - ns["/ipns/example.com"] = path.FromString("/ipfs/" + k)
160 - ns["/ipns/working.example.com"] = path.FromString("/ipfs/" + k)
166 + ns["/ipns/example.com"] = path.FromString(k.String())
167 + ns["/ipns/working.example.com"] = path.FromString(k.String())
168 ns["/ipns/double.example.com"] = path.FromString("/ipns/working.example.com")
169 ns["/ipns/triple.example.com"] = path.FromString("/ipns/double.example.com")
163 - ns["/ipns/broken.example.com"] = path.FromString("/ipns/" + k)
170 + ns["/ipns/broken.example.com"] = path.FromString("/ipns/" + k.Cid().String())
171 // We picked .man because:
172 // 1. It's a valid TLD.
173 // 2. Go treats it as the file extension for "man" files (even though
@@ -168,18 +175,18 @@ func TestGatewayGet(t *testing.T) {
175 //
176 // Unfortunately, this may not work on all platforms as file type
177 // detection is platform dependent.
171 - ns["/ipns/example.man"] = path.FromString("/ipfs/" + k)
178 + ns["/ipns/example.man"] = path.FromString(k.String())
179
180 t.Log(ts.URL)
174 - for _, test := range []struct {
181 + for i, test := range []struct {
182 host string
183 path string
184 status int
185 text string
186 }{
187 {"localhost:5001", "/", http.StatusNotFound, "404 page not found\n"},
181 - {"localhost:5001", "/" + k, http.StatusNotFound, "404 page not found\n"},
182 - {"localhost:5001", "/ipfs/" + k, http.StatusOK, "fnord"},
188 + {"localhost:5001", "/" + k.Cid().String(), http.StatusNotFound, "404 page not found\n"},
189 + {"localhost:5001", k.String(), http.StatusOK, "fnord"},
190 {"localhost:5001", "/ipns/nxdomain.example.com", http.StatusNotFound, "ipfs resolve -r /ipns/nxdomain.example.com: " + namesys.ErrResolveFailed.Error() + "\n"},
191 {"localhost:5001", "/ipns/%0D%0A%0D%0Ahello", http.StatusNotFound, "ipfs resolve -r /ipns/%0D%0A%0D%0Ahello: " + namesys.ErrResolveFailed.Error() + "\n"},
192 {"localhost:5001", "/ipns/example.com", http.StatusOK, "fnord"},
@@ -188,9 +195,9 @@ func TestGatewayGet(t *testing.T) {
195 {"working.example.com", "/", http.StatusOK, "fnord"},
196 {"double.example.com", "/", http.StatusOK, "fnord"},
197 {"triple.example.com", "/", http.StatusOK, "fnord"},
191 - {"working.example.com", "/ipfs/" + k, http.StatusNotFound, "ipfs resolve -r /ipns/working.example.com/ipfs/" + k + ": no link named \"ipfs\" under " + k + "\n"},
198 + {"working.example.com", k.String(), http.StatusNotFound, "ipfs resolve -r /ipns/working.example.com" + k.String() + ": no link named \"ipfs\" under " + k.Cid().String() + "\n"},
199 {"broken.example.com", "/", http.StatusNotFound, "ipfs resolve -r /ipns/broken.example.com/: " + namesys.ErrResolveFailed.Error() + "\n"},
193 - {"broken.example.com", "/ipfs/" + k, http.StatusNotFound, "ipfs resolve -r /ipns/broken.example.com/ipfs/" + k + ": " + namesys.ErrResolveFailed.Error() + "\n"},
200 + {"broken.example.com", k.String(), http.StatusNotFound, "ipfs resolve -r /ipns/broken.example.com" + k.String() + ": " + namesys.ErrResolveFailed.Error() + "\n"},
201 // This test case ensures we don't treat the TLD as a file extension.
202 {"example.man", "/", http.StatusOK, "fnord"},
203 } {
@@ -213,7 +220,7 @@ func TestGatewayGet(t *testing.T) {
220 t.Errorf("expected content type to be text/plain, got %s", contentType)
221 }
222 if resp.StatusCode != test.status {
216 - t.Errorf("got %d, expected %d from %s", resp.StatusCode, test.status, urlstr)
223 + t.Errorf("(%d) got %d, expected %d from %s", i, resp.StatusCode, test.status, urlstr)
224 continue
225 }
226 body, err := ioutil.ReadAll(resp.Body)
@@ -232,39 +239,26 @@ func TestIPNSHostnameRedirect(t *testing.T) {
239 defer cancel()
240
241 ns := mockNamesys{}
235 - ts, n := newTestServerAndNode(t, ns)
242 + ts, api, ctx := newTestServerAndNode(t, ns)
243 t.Logf("test server url: %s", ts.URL)
244 defer ts.Close()
245
246 // create /ipns/example.net/foo/index.html
240 - _, dagn1, err := coreunix.AddWrapped(n, strings.NewReader("_"), "_")
241 - if err != nil {
242 - t.Fatal(err)
243 - }
244 -
245 - _, dagn2, err := coreunix.AddWrapped(n, strings.NewReader("_"), "index.html")
246 - if err != nil {
247 - t.Fatal(err)
248 - }
249 -
250 - dagn1.(*dag.ProtoNode).AddNodeLink("foo", dagn2)
251 - if err != nil {
252 - t.Fatal(err)
253 - }
247
255 - err = n.DAG.Add(ctx, dagn2)
256 - if err != nil {
257 - t.Fatal(err)
258 - }
248 + f1 := files.NewMapDirectory(map[string]files.Node{
249 + "_": files.NewBytesFile([]byte("_")),
250 + "foo": files.NewMapDirectory(map[string]files.Node{
251 + "index.html": files.NewBytesFile([]byte("_")),
252 + }),
253 + })
254
260 - err = n.DAG.Add(ctx, dagn1)
255 + k, err := api.Unixfs().Add(ctx, f1, options.Unixfs.Wrap(true))
256 if err != nil {
257 t.Fatal(err)
258 }
259
265 - k := dagn1.Cid()
260 t.Logf("k: %s\n", k)
267 - ns["/ipns/example.net"] = path.FromString("/ipfs/" + k.String())
261 + ns["/ipns/example.net"] = path.FromString(k.String())
262
263 // make request to directory containing index.html
264 req, err := http.NewRequest("GET", ts.URL+"/foo", nil)
@@ -336,45 +330,38 @@ func TestIPNSHostnameBacklinks(t *testing.T) {
330 defer cancel()
331
332 ns := mockNamesys{}
339 - ts, n := newTestServerAndNode(t, ns)
333 + ts, api, ctx := newTestServerAndNode(t, ns)
334 t.Logf("test server url: %s", ts.URL)
335 defer ts.Close()
336
337 + f1 := files.NewMapDirectory(map[string]files.Node{
338 + "file.txt": files.NewBytesFile([]byte("1")),
339 + "foo? #<'": files.NewMapDirectory(map[string]files.Node{
340 + "file.txt": files.NewBytesFile([]byte("2")),
341 + "bar": files.NewMapDirectory(map[string]files.Node{
342 + "file.txt": files.NewBytesFile([]byte("3")),
343 + }),
344 + }),
345 + })
346 +
347 // create /ipns/example.net/foo/
344 - _, dagn1, err := coreunix.AddWrapped(n, strings.NewReader("1"), "file.txt")
345 - if err != nil {
346 - t.Fatal(err)
347 - }
348 - _, dagn2, err := coreunix.AddWrapped(n, strings.NewReader("2"), "file.txt")
349 - if err != nil {
350 - t.Fatal(err)
351 - }
352 - _, dagn3, err := coreunix.AddWrapped(n, strings.NewReader("3"), "file.txt")
353 - if err != nil {
354 - t.Fatal(err)
355 - }
356 - dagn2.(*dag.ProtoNode).AddNodeLink("bar", dagn3)
357 - dagn1.(*dag.ProtoNode).AddNodeLink("foo? #<'", dagn2)
348 + k, err := api.Unixfs().Add(ctx, f1, options.Unixfs.Wrap(true))
349 if err != nil {
350 t.Fatal(err)
351 }
352
362 - err = n.DAG.Add(ctx, dagn3)
353 + k2, err := api.ResolvePath(ctx, iface.Join(k, "foo? #<'"))
354 if err != nil {
355 t.Fatal(err)
356 }
366 - err = n.DAG.Add(ctx, dagn2)
367 - if err != nil {
368 - t.Fatal(err)
369 - }
370 - err = n.DAG.Add(ctx, dagn1)
357 +
358 + k3, err := api.ResolvePath(ctx, iface.Join(k, "foo? #<'/bar"))
359 if err != nil {
360 t.Fatal(err)
361 }
362
375 - k := dagn1.Cid()
363 t.Logf("k: %s\n", k)
377 - ns["/ipns/example.net"] = path.FromString("/ipfs/" + k.String())
364 + ns["/ipns/example.net"] = path.FromString(k.String())
365
366 // make request to directory listing
367 req, err := http.NewRequest("GET", ts.URL+"/foo%3F%20%23%3C%27/", nil)
@@ -405,7 +392,7 @@ func TestIPNSHostnameBacklinks(t *testing.T) {
392 if !strings.Contains(s, "<a href=\"/foo%3F%20%23%3C%27/file.txt\">") {
393 t.Fatalf("expected file in directory listing")
394 }
408 - if !strings.Contains(s, dagn2.Cid().String()) {
395 + if !strings.Contains(s, k2.Cid().String()) {
396 t.Fatalf("expected hash in directory listing")
397 }
398
@@ -438,7 +425,7 @@ func TestIPNSHostnameBacklinks(t *testing.T) {
425 if !strings.Contains(s, "<a href=\"/file.txt\">") {
426 t.Fatalf("expected file in directory listing")
427 }
441 - if !strings.Contains(s, dagn1.Cid().String()) {
428 + if !strings.Contains(s, k.Cid().String()) {
429 t.Fatalf("expected hash in directory listing")
430 }
431
@@ -471,7 +458,7 @@ func TestIPNSHostnameBacklinks(t *testing.T) {
458 if !strings.Contains(s, "<a href=\"/foo%3F%20%23%3C%27/bar/file.txt\">") {
459 t.Fatalf("expected file in directory listing")
460 }
474 - if !strings.Contains(s, dagn3.Cid().String()) {
461 + if !strings.Contains(s, k3.Cid().String()) {
462 t.Fatalf("expected hash in directory listing")
463 }
464
@@ -505,7 +492,7 @@ func TestIPNSHostnameBacklinks(t *testing.T) {
492 if !strings.Contains(s, "<a href=\"/good-prefix/file.txt\">") {
493 t.Fatalf("expected file in directory listing")
494 }
508 - if !strings.Contains(s, dagn1.Cid().String()) {
495 + if !strings.Contains(s, k.Cid().String()) {
496 t.Fatalf("expected hash in directory listing")
497 }
498
@@ -547,13 +534,13 @@ func TestIPNSHostnameBacklinks(t *testing.T) {
534 if !strings.Contains(s, "<a href=\"/file.txt\">") {
535 t.Fatalf("expected file in directory listing")
536 }
550 - if !strings.Contains(s, dagn1.Cid().String()) {
537 + if !strings.Contains(s, k.Cid().String()) {
538 t.Fatalf("expected hash in directory listing")
539 }
540 }
541
542 func TestCacheControlImmutable(t *testing.T) {
556 - ts, _ := newTestServerAndNode(t, nil)
543 + ts, _, _ := newTestServerAndNode(t, nil)
544 t.Logf("test server url: %s", ts.URL)
545 defer ts.Close()
546
@@ -579,7 +566,7 @@ func TestCacheControlImmutable(t *testing.T) {
566 }
567
568 func TestGoGetSupport(t *testing.T) {
582 - ts, _ := newTestServerAndNode(t, nil)
569 + ts, _, _ := newTestServerAndNode(t, nil)
570 t.Logf("test server url: %s", ts.URL)
571 defer ts.Close()
572
@@ -603,7 +590,7 @@ func TestVersion(t *testing.T) {
590 version.CurrentCommit = "theshortcommithash"
591
592 ns := mockNamesys{}
606 - ts, _ := newTestServerAndNode(t, ns)
593 + ts, _, _ := newTestServerAndNode(t, ns)
594 t.Logf("test server url: %s", ts.URL)
595 defer ts.Close()
596
core/coreunix/add.go
-86
@@ -7,10 +7,8 @@ import (
7 "io"
8 "os"
9 gopath "path"
10 - "path/filepath"
10 "strconv"
11
13 - "github.com/ipfs/go-ipfs/core"
12 coreiface "github.com/ipfs/go-ipfs/core/coreapi/interface"
13 "github.com/ipfs/go-ipfs/pin"
14
@@ -276,90 +274,6 @@ func (adder *Adder) outputDirs(path string, fsn mfs.FSNode) error {
274 }
275 }
276
279 -// Add builds a merkledag node from a reader, adds it to the blockstore,
280 -// and returns the key representing that node.
281 -// If you want to pin it, use NewAdder() and Adder.PinRoot().
282 -func Add(n *core.IpfsNode, r io.Reader) (string, error) {
283 - return AddWithContext(n.Context(), n, r)
284 -}
285 -
286 -// AddWithContext does the same as Add, but with a custom context.
287 -func AddWithContext(ctx context.Context, n *core.IpfsNode, r io.Reader) (string, error) {
288 - defer n.Blockstore.PinLock().Unlock()
289 -
290 - fileAdder, err := NewAdder(ctx, n.Pinning, n.Blockstore, n.DAG)
291 - if err != nil {
292 - return "", err
293 - }
294 -
295 - node, err := fileAdder.add(r)
296 - if err != nil {
297 - return "", err
298 - }
299 -
300 - return node.Cid().String(), nil
301 -}
302 -
303 -// AddR recursively adds files in |path|.
304 -func AddR(n *core.IpfsNode, root string) (key string, err error) {
305 - defer n.Blockstore.PinLock().Unlock()
306 -
307 - stat, err := os.Lstat(root)
308 - if err != nil {
309 - return "", err
310 - }
311 -
312 - f, err := files.NewSerialFile(root, false, stat)
313 - if err != nil {
314 - return "", err
315 - }
316 - defer f.Close()
317 -
318 - fileAdder, err := NewAdder(n.Context(), n.Pinning, n.Blockstore, n.DAG)
319 - if err != nil {
320 - return "", err
321 - }
322 -
323 - err = fileAdder.addFileNode(filepath.Base(root), f)
324 - if err != nil {
325 - return "", err
326 - }
327 -
328 - nd, err := fileAdder.Finalize()
329 - if err != nil {
330 - return "", err
331 - }
332 -
333 - return nd.String(), nil
334 -}
335 -
336 -// AddWrapped adds data from a reader, and wraps it with a directory object
337 -// to preserve the filename.
338 -// Returns the path of the added file ("<dir hash>/filename"), the DAG node of
339 -// the directory, and and error if any.
340 -func AddWrapped(n *core.IpfsNode, r io.Reader, filename string) (string, ipld.Node, error) {
341 - fileAdder, err := NewAdder(n.Context(), n.Pinning, n.Blockstore, n.DAG)
342 - if err != nil {
343 - return "", nil, err
344 - }
345 - fileAdder.Wrap = true
346 -
347 - defer n.Blockstore.PinLock().Unlock()
348 -
349 - err = fileAdder.addFileNode(filename, files.NewReaderFile(r))
350 - if err != nil {
351 - return "", nil, err
352 - }
353 -
354 - dagnode, err := fileAdder.Finalize()
355 - if err != nil {
356 - return "", nil, err
357 - }
358 -
359 - c := dagnode.Cid()
360 - return gopath.Join(c.String(), filename), dagnode, nil
361 -}
362 -
277 func (adder *Adder) addNode(node ipld.Node, path string) error {
278 // patch it into the root
279 if path == "" {
core/coreunix/add_test.go
-20
@@ -30,26 +30,6 @@ import (
30
31 const testPeerID = "QmTFauExutTsy4XP6JbMFcw2Wa9645HJt2bTqL6qYDCKfe"
32
33 -func TestAddRecursive(t *testing.T) {
34 - r := &repo.Mock{
35 - C: config.Config{
36 - Identity: config.Identity{
37 - PeerID: testPeerID, // required by offline node
38 - },
39 - },
40 - D: syncds.MutexWrap(datastore.NewMapDatastore()),
41 - }
42 - node, err := core.NewNode(context.Background(), &core.BuildCfg{Repo: r})
43 - if err != nil {
44 - t.Fatal(err)
45 - }
46 - if k, err := AddR(node, "test/data"); err != nil {
47 - t.Fatal(err)
48 - } else if k != "QmWCCga8AbTyfAQ7pTnGT6JgmRMAB3Qp8ZmTEFi5q5o8jC" {
49 - t.Fatal("keys do not match: ", k)
50 - }
51 -}
52 -
33 func TestAddGCLive(t *testing.T) {
34 r := &repo.Mock{
35 C: config.Config{
test/integration/addcat_test.go
+8 -9
@@ -13,14 +13,13 @@ import (
13
14 "github.com/ipfs/go-ipfs/core"
15 "github.com/ipfs/go-ipfs/core/coreapi"
16 - "github.com/ipfs/go-ipfs/core/coreapi/interface"
17 - coreunix "github.com/ipfs/go-ipfs/core/coreunix"
16 mock "github.com/ipfs/go-ipfs/core/mock"
17 "github.com/ipfs/go-ipfs/thirdparty/unit"
18
19 testutil "gx/ipfs/QmNvHv84aH2qZafDuSdKJCQ1cvPZ1kmQmyD4YtzjUHuk9v/go-testutil"
20 pstore "gx/ipfs/QmPiemjiKBC9VA7vZF82m4x1oygtg2c2YVqag8PX7dN1BD/go-libp2p-peerstore"
21 random "gx/ipfs/QmSJ9n2s9NUoA9D849W5jj5SJ94nMcZpj1jCgQJieiNqSt/go-random"
22 + files "gx/ipfs/QmXWZCd8jfaHmt4UDSnjKmGcrQMw95bDGWqEeVLVJjoANX/go-ipfs-files"
23 mocknet "gx/ipfs/QmYxivS34F2M2n44WQQnRHGAKS8aoRUxwGpi9wk4Cdn4Jf/go-libp2p/p2p/net/mock"
24 logging "gx/ipfs/QmcuXC5cxs79ro2cUuHs4HQ2bkDLJUYokwL8aivcX6HW3C/go-log"
25 )
@@ -120,6 +119,11 @@ func DirectAddCat(data []byte, conf testutil.LatencyConfig) error {
119 }
120 defer catter.Close()
121
122 + adderApi, err := coreapi.NewCoreAPI(adder)
123 + if err != nil {
124 + return err
125 + }
126 +
127 catterApi, err := coreapi.NewCoreAPI(catter)
128 if err != nil {
129 return err
@@ -140,17 +144,12 @@ func DirectAddCat(data []byte, conf testutil.LatencyConfig) error {
144 return err
145 }
146
143 - added, err := coreunix.Add(adder, bytes.NewReader(data))
144 - if err != nil {
145 - return err
146 - }
147 -
148 - ap, err := iface.ParsePath(added)
147 + added, err := adderApi.Unixfs().Add(ctx, files.NewBytesFile(data))
148 if err != nil {
149 return err
150 }
151
153 - readerCatted, err := catterApi.Unixfs().Get(ctx, ap)
152 + readerCatted, err := catterApi.Unixfs().Get(ctx, added)
153 if err != nil {
154 return err
155 }
test/integration/bench_cat_test.go
+8 -9
@@ -10,13 +10,12 @@ import (
10
11 "github.com/ipfs/go-ipfs/core"
12 "github.com/ipfs/go-ipfs/core/coreapi"
13 - "github.com/ipfs/go-ipfs/core/coreapi/interface"
14 - coreunix "github.com/ipfs/go-ipfs/core/coreunix"
13 mock "github.com/ipfs/go-ipfs/core/mock"
14 "github.com/ipfs/go-ipfs/thirdparty/unit"
15
16 testutil "gx/ipfs/QmNvHv84aH2qZafDuSdKJCQ1cvPZ1kmQmyD4YtzjUHuk9v/go-testutil"
17 pstore "gx/ipfs/QmPiemjiKBC9VA7vZF82m4x1oygtg2c2YVqag8PX7dN1BD/go-libp2p-peerstore"
18 + files "gx/ipfs/QmXWZCd8jfaHmt4UDSnjKmGcrQMw95bDGWqEeVLVJjoANX/go-ipfs-files"
19 mocknet "gx/ipfs/QmYxivS34F2M2n44WQQnRHGAKS8aoRUxwGpi9wk4Cdn4Jf/go-libp2p/p2p/net/mock"
20 )
21
@@ -66,6 +65,11 @@ func benchCat(b *testing.B, data []byte, conf testutil.LatencyConfig) error {
65 }
66 defer catter.Close()
67
68 + adderApi, err := coreapi.NewCoreAPI(adder)
69 + if err != nil {
70 + return err
71 + }
72 +
73 catterApi, err := coreapi.NewCoreAPI(catter)
74 if err != nil {
75 return err
@@ -86,18 +90,13 @@ func benchCat(b *testing.B, data []byte, conf testutil.LatencyConfig) error {
90 return err
91 }
92
89 - added, err := coreunix.Add(adder, bytes.NewReader(data))
90 - if err != nil {
91 - return err
92 - }
93 -
94 - ap, err := iface.ParsePath(added)
93 + added, err := adderApi.Unixfs().Add(ctx, files.NewBytesFile(data))
94 if err != nil {
95 return err
96 }
97
98 b.StartTimer()
100 - readerCatted, err := catterApi.Unixfs().Get(ctx, ap)
99 + readerCatted, err := catterApi.Unixfs().Get(ctx, added)
100 if err != nil {
101 return err
102 }
test/integration/three_legged_cat_test.go
+8 -9
@@ -11,13 +11,12 @@ import (
11
12 core "github.com/ipfs/go-ipfs/core"
13 "github.com/ipfs/go-ipfs/core/coreapi"
14 - "github.com/ipfs/go-ipfs/core/coreapi/interface"
15 - coreunix "github.com/ipfs/go-ipfs/core/coreunix"
14 mock "github.com/ipfs/go-ipfs/core/mock"
15 "github.com/ipfs/go-ipfs/thirdparty/unit"
16
17 testutil "gx/ipfs/QmNvHv84aH2qZafDuSdKJCQ1cvPZ1kmQmyD4YtzjUHuk9v/go-testutil"
18 pstore "gx/ipfs/QmPiemjiKBC9VA7vZF82m4x1oygtg2c2YVqag8PX7dN1BD/go-libp2p-peerstore"
19 + files "gx/ipfs/QmXWZCd8jfaHmt4UDSnjKmGcrQMw95bDGWqEeVLVJjoANX/go-ipfs-files"
20 mocknet "gx/ipfs/QmYxivS34F2M2n44WQQnRHGAKS8aoRUxwGpi9wk4Cdn4Jf/go-libp2p/p2p/net/mock"
21 )
22
@@ -103,6 +102,11 @@ func RunThreeLeggedCat(data []byte, conf testutil.LatencyConfig) error {
102 }
103 defer catter.Close()
104
105 + adderApi, err := coreapi.NewCoreAPI(adder)
106 + if err != nil {
107 + return err
108 + }
109 +
110 catterApi, err := coreapi.NewCoreAPI(catter)
111 if err != nil {
112 return err
@@ -119,17 +123,12 @@ func RunThreeLeggedCat(data []byte, conf testutil.LatencyConfig) error {
123 return err
124 }
125
122 - added, err := coreunix.Add(adder, bytes.NewReader(data))
123 - if err != nil {
124 - return err
125 - }
126 -
127 - ap, err := iface.ParsePath(added)
126 + added, err := adderApi.Unixfs().Add(ctx, files.NewBytesFile(data))
127 if err != nil {
128 return err
129 }
130
132 - readerCatted, err := catterApi.Unixfs().Get(ctx, ap)
131 + readerCatted, err := catterApi.Unixfs().Get(ctx, added)
132 if err != nil {
133 return err
134 }