@cryptotaxi247 / kubo / commits / 1ed555b87

Cleanup instances of manual resolver construction

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

Łukasz Magiera committed Sep 19, 2018 at 23:40 UTC 1ed555b87f3d933bd3e234d083168254bf6f309d
14 files changed +170 -190
core/commands/cat.go
+15 -6
@@ -6,9 +6,8 @@ import (
6 "io"
7 "os"
8
9 - core "github.com/ipfs/go-ipfs/core"
9 cmdenv "github.com/ipfs/go-ipfs/core/commands/cmdenv"
11 - coreunix "github.com/ipfs/go-ipfs/core/coreunix"
10 + "github.com/ipfs/go-ipfs/core/coreapi/interface"
11
12 "gx/ipfs/QmSP88ryZkHSRn1fnngAaV2Vcn63WUJzAavnRM9CVdU1Ky/go-ipfs-cmdkit"
13 cmds "gx/ipfs/QmXTmUCBtDUrzDYVzASogLiNph7EBuYqEgPL7QoHNMzUnz/go-ipfs-cmds"
@@ -35,6 +34,11 @@ var CatCmd = &cmds.Command{
34 return err
35 }
36
37 + api, err := cmdenv.GetApi(env)
38 + if err != nil {
39 + return err
40 + }
41 +
42 if !node.OnlineMode() {
43 if err := node.SetupOfflineRouting(); err != nil {
44 return err
@@ -62,7 +66,7 @@ var CatCmd = &cmds.Command{
66 return err
67 }
68
65 - readers, length, err := cat(req.Context, node, req.Arguments, int64(offset), int64(max))
69 + readers, length, err := cat(req.Context, api, req.Arguments, int64(offset), int64(max))
70 if err != nil {
71 return err
72 }
@@ -115,14 +119,19 @@ var CatCmd = &cmds.Command{
119 },
120 }
121
118 -func cat(ctx context.Context, node *core.IpfsNode, paths []string, offset int64, max int64) ([]io.Reader, uint64, error) {
122 +func cat(ctx context.Context, api iface.CoreAPI, paths []string, offset int64, max int64) ([]io.Reader, uint64, error) {
123 readers := make([]io.Reader, 0, len(paths))
124 length := uint64(0)
125 if max == 0 {
126 return nil, 0, nil
127 }
124 - for _, fpath := range paths {
125 - read, err := coreunix.Cat(ctx, node, fpath)
128 + for _, p := range paths {
129 + fpath, err := iface.ParsePath(p)
130 + if err != nil {
131 + return nil, 0, err
132 + }
133 +
134 + read, err := api.Unixfs().Cat(ctx, fpath)
135 if err != nil {
136 return nil, 0, err
137 }
core/commands/files.go
+20 -16
@@ -16,21 +16,19 @@ import (
16 core "github.com/ipfs/go-ipfs/core"
17 cmdenv "github.com/ipfs/go-ipfs/core/commands/cmdenv"
18 e "github.com/ipfs/go-ipfs/core/commands/e"
19 - ft "gx/ipfs/QmU4x3742bvgfxJsByEDpBnifJqjJdV6x528co4hwKCn46/go-unixfs"
20 - uio "gx/ipfs/QmU4x3742bvgfxJsByEDpBnifJqjJdV6x528co4hwKCn46/go-unixfs/io"
21 - dag "gx/ipfs/QmcBoNcAP6qDjgRBew7yjvCqHq7p5jMstE44jPUBWBxzsV/go-merkledag"
22 - bservice "gx/ipfs/QmcRecCZWM2NZfCQrCe97Ch3Givv8KKEP82tGUDntzdLFe/go-blockservice"
23 - path "gx/ipfs/QmcjwUb36Z16NJkvDX6ccXPqsFswo6AsRXynyXcLLCphV2/go-path"
24 - resolver "gx/ipfs/QmcjwUb36Z16NJkvDX6ccXPqsFswo6AsRXynyXcLLCphV2/go-path/resolver"
19 + "github.com/ipfs/go-ipfs/core/coreapi/interface"
20
21 humanize "gx/ipfs/QmPSBJL4momYnE7DcUyk2DVhD6rH488ZmHBGLbxNdhU44K/go-humanize"
22 cid "gx/ipfs/QmPSQnBKM9g7BaUcZCvswUJVscQ1ipjmwxN5PXCjkp9EQ7/go-cid"
23 mh "gx/ipfs/QmPnFwZ2JXKnXgMw8CdBPxn7FWh6LLdjUjxV1fKHuJnkr8/go-multihash"
24 offline "gx/ipfs/QmR5miWuikPxWyUrzMYJVmFUcD44pGdtc98h9Qsbp4YcJw/go-ipfs-exchange-offline"
25 cmdkit "gx/ipfs/QmSP88ryZkHSRn1fnngAaV2Vcn63WUJzAavnRM9CVdU1Ky/go-ipfs-cmdkit"
26 + ft "gx/ipfs/QmU4x3742bvgfxJsByEDpBnifJqjJdV6x528co4hwKCn46/go-unixfs"
27 cmds "gx/ipfs/QmXTmUCBtDUrzDYVzASogLiNph7EBuYqEgPL7QoHNMzUnz/go-ipfs-cmds"
28 logging "gx/ipfs/QmZChCsSt8DctjceaL56Eibc29CVQq4dGKRXC5JRZ6Ppae/go-log"
29 mfs "gx/ipfs/QmahrY1adY4wvtYEtoGjpZ2GUohTyukrkMkwUR9ytRjTG2/go-mfs"
30 + dag "gx/ipfs/QmcBoNcAP6qDjgRBew7yjvCqHq7p5jMstE44jPUBWBxzsV/go-merkledag"
31 + bservice "gx/ipfs/QmcRecCZWM2NZfCQrCe97Ch3Givv8KKEP82tGUDntzdLFe/go-blockservice"
32 ipld "gx/ipfs/QmdDXJs4axxefSPgK6Y1QhpJWKuDPnGJiqgq4uncb4rFHL/go-ipld-format"
33 )
34
@@ -120,6 +118,11 @@ var filesStatCmd = &cmds.Command{
118 return err
119 }
120
121 + api, err := cmdenv.GetApi(env)
122 + if err != nil {
123 + return err
124 + }
125 +
126 path, err := checkPath(req.Arguments[0])
127 if err != nil {
128 return err
@@ -138,7 +141,7 @@ var filesStatCmd = &cmds.Command{
141 dagserv = node.DAG
142 }
143
141 - nd, err := getNodeFromPath(req.Context, node, dagserv, path)
144 + nd, err := getNodeFromPath(req.Context, node, api, path)
145 if err != nil {
146 return err
147 }
@@ -305,6 +308,12 @@ var filesCpCmd = &oldcmds.Command{
308 return
309 }
310
311 + api, err := req.InvocContext().GetApi()
312 + if err != nil {
313 + res.SetError(err, cmdkit.ErrNormal)
314 + return
315 + }
316 +
317 flush, _, _ := req.Option("flush").Bool()
318
319 src, err := checkPath(req.Arguments()[0])
@@ -324,7 +333,7 @@ var filesCpCmd = &oldcmds.Command{
333 dst += gopath.Base(src)
334 }
335
327 - nd, err := getNodeFromPath(req.Context(), node, node.DAG, src)
336 + nd, err := getNodeFromPath(req.Context(), node, api, src)
337 if err != nil {
338 res.SetError(fmt.Errorf("cp: cannot get node from path %s: %s", src, err), cmdkit.ErrNormal)
339 return
@@ -348,20 +357,15 @@ var filesCpCmd = &oldcmds.Command{
357 },
358 }
359
351 -func getNodeFromPath(ctx context.Context, node *core.IpfsNode, dagservice ipld.DAGService, p string) (ipld.Node, error) {
360 +func getNodeFromPath(ctx context.Context, node *core.IpfsNode, api iface.CoreAPI, p string) (ipld.Node, error) {
361 switch {
362 case strings.HasPrefix(p, "/ipfs/"):
354 - np, err := path.ParsePath(p)
363 + np, err := iface.ParsePath(p)
364 if err != nil {
365 return nil, err
366 }
367
359 - resolver := &resolver.Resolver{
360 - DAG: dagservice,
361 - ResolveOnce: uio.ResolveUnixfsOnce,
362 - }
363 -
364 - return core.Resolve(ctx, node.Namesys, resolver, np)
368 + return api.ResolveNode(ctx, np)
369 default:
370 fsn, err := mfs.Lookup(node.FilesRoot, p)
371 if err != nil {
core/commands/ls.go
+13 -14
@@ -7,19 +7,17 @@ import (
7 "text/tabwriter"
8
9 cmds "github.com/ipfs/go-ipfs/commands"
10 - core "github.com/ipfs/go-ipfs/core"
10 e "github.com/ipfs/go-ipfs/core/commands/e"
11 + iface "github.com/ipfs/go-ipfs/core/coreapi/interface"
12 +
13 + cid "gx/ipfs/QmPSQnBKM9g7BaUcZCvswUJVscQ1ipjmwxN5PXCjkp9EQ7/go-cid"
14 + offline "gx/ipfs/QmR5miWuikPxWyUrzMYJVmFUcD44pGdtc98h9Qsbp4YcJw/go-ipfs-exchange-offline"
15 + "gx/ipfs/QmSP88ryZkHSRn1fnngAaV2Vcn63WUJzAavnRM9CVdU1Ky/go-ipfs-cmdkit"
16 unixfs "gx/ipfs/QmU4x3742bvgfxJsByEDpBnifJqjJdV6x528co4hwKCn46/go-unixfs"
17 uio "gx/ipfs/QmU4x3742bvgfxJsByEDpBnifJqjJdV6x528co4hwKCn46/go-unixfs/io"
18 unixfspb "gx/ipfs/QmU4x3742bvgfxJsByEDpBnifJqjJdV6x528co4hwKCn46/go-unixfs/pb"
19 merkledag "gx/ipfs/QmcBoNcAP6qDjgRBew7yjvCqHq7p5jMstE44jPUBWBxzsV/go-merkledag"
20 blockservice "gx/ipfs/QmcRecCZWM2NZfCQrCe97Ch3Givv8KKEP82tGUDntzdLFe/go-blockservice"
17 - path "gx/ipfs/QmcjwUb36Z16NJkvDX6ccXPqsFswo6AsRXynyXcLLCphV2/go-path"
18 - resolver "gx/ipfs/QmcjwUb36Z16NJkvDX6ccXPqsFswo6AsRXynyXcLLCphV2/go-path/resolver"
19 -
20 - cid "gx/ipfs/QmPSQnBKM9g7BaUcZCvswUJVscQ1ipjmwxN5PXCjkp9EQ7/go-cid"
21 - offline "gx/ipfs/QmR5miWuikPxWyUrzMYJVmFUcD44pGdtc98h9Qsbp4YcJw/go-ipfs-exchange-offline"
22 - "gx/ipfs/QmSP88ryZkHSRn1fnngAaV2Vcn63WUJzAavnRM9CVdU1Ky/go-ipfs-cmdkit"
21 ipld "gx/ipfs/QmdDXJs4axxefSPgK6Y1QhpJWKuDPnGJiqgq4uncb4rFHL/go-ipld-format"
22 )
23
@@ -65,6 +63,12 @@ The JSON output contains type information.
63 return
64 }
65
66 + api, err := req.InvocContext().GetApi()
67 + if err != nil {
68 + res.SetError(err, cmdkit.ErrNormal)
69 + return
70 + }
71 +
72 // get options early -> exit early in case of error
73 if _, _, err := req.Option("headers").Bool(); err != nil {
74 res.SetError(err, cmdkit.ErrNormal)
@@ -88,18 +92,13 @@ The JSON output contains type information.
92
93 var dagnodes []ipld.Node
94 for _, fpath := range paths {
91 - p, err := path.ParsePath(fpath)
95 + p, err := iface.ParsePath(fpath)
96 if err != nil {
97 res.SetError(err, cmdkit.ErrNormal)
98 return
99 }
100
97 - r := &resolver.Resolver{
98 - DAG: nd.DAG,
99 - ResolveOnce: uio.ResolveUnixfsOnce,
100 - }
101 -
102 - dagnode, err := core.Resolve(req.Context(), nd.Namesys, r, p)
101 + dagnode, err := api.ResolveNode(req.Context(), p)
102 if err != nil {
103 res.SetError(err, cmdkit.ErrNormal)
104 return
core/commands/pin.go
+32 -43
@@ -10,9 +10,10 @@ import (
10 cmds "github.com/ipfs/go-ipfs/commands"
11 core "github.com/ipfs/go-ipfs/core"
12 e "github.com/ipfs/go-ipfs/core/commands/e"
13 + iface "github.com/ipfs/go-ipfs/core/coreapi/interface"
14 + options "github.com/ipfs/go-ipfs/core/coreapi/interface/options"
15 corerepo "github.com/ipfs/go-ipfs/core/corerepo"
16 pin "github.com/ipfs/go-ipfs/pin"
15 - uio "gx/ipfs/QmU4x3742bvgfxJsByEDpBnifJqjJdV6x528co4hwKCn46/go-unixfs/io"
17
18 cid "gx/ipfs/QmPSQnBKM9g7BaUcZCvswUJVscQ1ipjmwxN5PXCjkp9EQ7/go-cid"
19 offline "gx/ipfs/QmR5miWuikPxWyUrzMYJVmFUcD44pGdtc98h9Qsbp4YcJw/go-ipfs-exchange-offline"
@@ -20,8 +21,6 @@ import (
21 "gx/ipfs/QmVkMRSkXrpjqrroEXWuYBvDBnXCdMMY6gsKicBGVGUqKT/go-verifcid"
22 dag "gx/ipfs/QmcBoNcAP6qDjgRBew7yjvCqHq7p5jMstE44jPUBWBxzsV/go-merkledag"
23 bserv "gx/ipfs/QmcRecCZWM2NZfCQrCe97Ch3Givv8KKEP82tGUDntzdLFe/go-blockservice"
23 - path "gx/ipfs/QmcjwUb36Z16NJkvDX6ccXPqsFswo6AsRXynyXcLLCphV2/go-path"
24 - resolver "gx/ipfs/QmcjwUb36Z16NJkvDX6ccXPqsFswo6AsRXynyXcLLCphV2/go-path/resolver"
24 )
25
26 var PinCmd = &cmds.Command{
@@ -68,6 +67,12 @@ var addPinCmd = &cmds.Command{
67 return
68 }
69
70 + api, err := req.InvocContext().GetApi()
71 + if err != nil {
72 + res.SetError(err, cmdkit.ErrNormal)
73 + return
74 + }
75 +
76 defer n.Blockstore.PinLock().Unlock()
77
78 // set recursive flag
@@ -79,7 +84,7 @@ var addPinCmd = &cmds.Command{
84 showProgress, _, _ := req.Option("progress").Bool()
85
86 if !showProgress {
82 - added, err := corerepo.Pin(n, req.Context(), req.Arguments(), recursive)
87 + added, err := corerepo.Pin(n, api, req.Context(), req.Arguments(), recursive)
88 if err != nil {
89 res.SetError(err, cmdkit.ErrNormal)
90 return
@@ -99,7 +104,7 @@ var addPinCmd = &cmds.Command{
104 }
105 ch := make(chan pinResult, 1)
106 go func() {
102 - added, err := corerepo.Pin(n, ctx, req.Arguments(), recursive)
107 + added, err := corerepo.Pin(n, api, ctx, req.Arguments(), recursive)
108 ch <- pinResult{pins: added, err: err}
109 }()
110
@@ -193,6 +198,12 @@ collected if needed. (By default, recursively. Use -r=false for direct pins.)
198 return
199 }
200
201 + api, err := req.InvocContext().GetApi()
202 + if err != nil {
203 + res.SetError(err, cmdkit.ErrNormal)
204 + return
205 + }
206 +
207 // set recursive flag
208 recursive, _, err := req.Option("recursive").Bool()
209 if err != nil {
@@ -200,7 +211,7 @@ collected if needed. (By default, recursively. Use -r=false for direct pins.)
211 return
212 }
213
203 - removed, err := corerepo.Unpin(n, req.Context(), req.Arguments(), recursive)
214 + removed, err := corerepo.Unpin(n, api, req.Context(), req.Arguments(), recursive)
215 if err != nil {
216 res.SetError(err, cmdkit.ErrNormal)
217 return
@@ -287,6 +298,12 @@ Example:
298 return
299 }
300
301 + api, err := req.InvocContext().GetApi()
302 + if err != nil {
303 + res.SetError(err, cmdkit.ErrNormal)
304 + return
305 + }
306 +
307 typeStr, _, err := req.Option("type").String()
308 if err != nil {
309 res.SetError(err, cmdkit.ErrNormal)
@@ -304,7 +321,7 @@ Example:
321 var keys map[string]RefKeyObject
322
323 if len(req.Arguments()) > 0 {
307 - keys, err = pinLsKeys(req.Context(), req.Arguments(), typeStr, n)
324 + keys, err = pinLsKeys(req.Context(), req.Arguments(), typeStr, n, api)
325 } else {
326 keys, err = pinLsAll(req.Context(), typeStr, n)
327 }
@@ -364,7 +381,7 @@ new pin and removing the old one.
381 },
382 Type: PinOutput{},
383 Run: func(req cmds.Request, res cmds.Response) {
367 - n, err := req.InvocContext().GetNode()
384 + api, err := req.InvocContext().GetApi()
385 if err != nil {
386 res.SetError(err, cmdkit.ErrNormal)
387 return
@@ -376,42 +393,19 @@ new pin and removing the old one.
393 return
394 }
395
379 - from, err := path.ParsePath(req.Arguments()[0])
396 + from, err := iface.ParsePath(req.Arguments()[0])
397 if err != nil {
398 res.SetError(err, cmdkit.ErrNormal)
399 return
400 }
401
385 - to, err := path.ParsePath(req.Arguments()[1])
402 + to, err := iface.ParsePath(req.Arguments()[1])
403 if err != nil {
404 res.SetError(err, cmdkit.ErrNormal)
405 return
406 }
407
391 - r := &resolver.Resolver{
392 - DAG: n.DAG,
393 - ResolveOnce: uio.ResolveUnixfsOnce,
394 - }
395 -
396 - fromc, err := core.ResolveToCid(req.Context(), n.Namesys, r, from)
397 - if err != nil {
398 - res.SetError(err, cmdkit.ErrNormal)
399 - return
400 - }
401 -
402 - toc, err := core.ResolveToCid(req.Context(), n.Namesys, r, to)
403 - if err != nil {
404 - res.SetError(err, cmdkit.ErrNormal)
405 - return
406 - }
407 -
408 - err = n.Pinning.Update(req.Context(), fromc, toc, unpin)
409 - if err != nil {
410 - res.SetError(err, cmdkit.ErrNormal)
411 - return
412 - }
413 -
414 - err = n.Pinning.Flush()
408 + err = api.Pin().Update(req.Context(), from, to, options.Pin.Unpin(unpin))
409 if err != nil {
410 res.SetError(err, cmdkit.ErrNormal)
411 return
@@ -501,7 +495,7 @@ type RefKeyList struct {
495 Keys map[string]RefKeyObject
496 }
497
504 -func pinLsKeys(ctx context.Context, args []string, typeStr string, n *core.IpfsNode) (map[string]RefKeyObject, error) {
498 +func pinLsKeys(ctx context.Context, args []string, typeStr string, n *core.IpfsNode, api iface.CoreAPI) (map[string]RefKeyObject, error) {
499
500 mode, ok := pin.StringToMode(typeStr)
501 if !ok {
@@ -510,23 +504,18 @@ func pinLsKeys(ctx context.Context, args []string, typeStr string, n *core.IpfsN
504
505 keys := make(map[string]RefKeyObject)
506
513 - r := &resolver.Resolver{
514 - DAG: n.DAG,
515 - ResolveOnce: uio.ResolveUnixfsOnce,
516 - }
517 -
507 for _, p := range args {
519 - pth, err := path.ParsePath(p)
508 + pth, err := iface.ParsePath(p)
509 if err != nil {
510 return nil, err
511 }
512
524 - c, err := core.ResolveToCid(ctx, n.Namesys, r, pth)
513 + c, err := api.ResolvePath(ctx, pth)
514 if err != nil {
515 return nil, err
516 }
517
529 - pinType, pinned, err := n.Pinning.IsPinnedWithType(c, mode)
518 + pinType, pinned, err := n.Pinning.IsPinnedWithType(c.Cid(), mode)
519 if err != nil {
520 return nil, err
521 }
core/commands/unixfs/ls.go
+16 -12
@@ -7,16 +7,13 @@ import (
7 "sort"
8 "text/tabwriter"
9
10 - cmdkit "gx/ipfs/QmSP88ryZkHSRn1fnngAaV2Vcn63WUJzAavnRM9CVdU1Ky/go-ipfs-cmdkit"
11 -
10 cmds "github.com/ipfs/go-ipfs/commands"
13 - core "github.com/ipfs/go-ipfs/core"
11 e "github.com/ipfs/go-ipfs/core/commands/e"
12 + iface "github.com/ipfs/go-ipfs/core/coreapi/interface"
13 +
14 + cmdkit "gx/ipfs/QmSP88ryZkHSRn1fnngAaV2Vcn63WUJzAavnRM9CVdU1Ky/go-ipfs-cmdkit"
15 unixfs "gx/ipfs/QmU4x3742bvgfxJsByEDpBnifJqjJdV6x528co4hwKCn46/go-unixfs"
16 - uio "gx/ipfs/QmU4x3742bvgfxJsByEDpBnifJqjJdV6x528co4hwKCn46/go-unixfs/io"
16 merkledag "gx/ipfs/QmcBoNcAP6qDjgRBew7yjvCqHq7p5jMstE44jPUBWBxzsV/go-merkledag"
18 - path "gx/ipfs/QmcjwUb36Z16NJkvDX6ccXPqsFswo6AsRXynyXcLLCphV2/go-path"
19 - resolver "gx/ipfs/QmcjwUb36Z16NJkvDX6ccXPqsFswo6AsRXynyXcLLCphV2/go-path/resolver"
17 )
18
19 type LsLink struct {
@@ -82,6 +79,12 @@ possible, please use 'ipfs ls' instead.
79 return
80 }
81
82 + api, err := req.InvocContext().GetApi()
83 + if err != nil {
84 + res.SetError(err, cmdkit.ErrNormal)
85 + return
86 + }
87 +
88 paths := req.Arguments()
89
90 output := LsOutput{
@@ -89,15 +92,16 @@ possible, please use 'ipfs ls' instead.
92 Objects: map[string]*LsObject{},
93 }
94
92 - for _, fpath := range paths {
95 + for _, p := range paths {
96 ctx := req.Context()
97
95 - resolver := &resolver.Resolver{
96 - DAG: node.DAG,
97 - ResolveOnce: uio.ResolveUnixfsOnce,
98 + fpath, err := iface.ParsePath(p)
99 + if err != nil {
100 + res.SetError(err, cmdkit.ErrNormal)
101 + return
102 }
103
100 - merkleNode, err := core.Resolve(ctx, node.Namesys, resolver, path.Path(fpath))
104 + merkleNode, err := api.ResolveNode(ctx, fpath)
105 if err != nil {
106 res.SetError(err, cmdkit.ErrNormal)
107 return
@@ -106,7 +110,7 @@ possible, please use 'ipfs ls' instead.
110 c := merkleNode.Cid()
111
112 hash := c.String()
109 - output.Arguments[fpath] = hash
113 + output.Arguments[p] = hash
114
115 if _, ok := output.Objects[hash]; ok {
116 // duplicate argument for an already-listed node
core/coreapi/interface/util.go
+11 -1
@@ -1,10 +1,20 @@
1 package iface
2
3 import (
4 + "context"
5 "io"
6 )
7
8 type Reader interface {
8 - io.ReadSeeker
9 + ReadSeekCloser
10 + Size() uint64
11 + CtxReadFull(context.Context, []byte) (int, error)
12 +}
13 +
14 +// A ReadSeekCloser implements interfaces to read, copy, seek and close.
15 +type ReadSeekCloser interface {
16 + io.Reader
17 + io.Seeker
18 io.Closer
19 + io.WriterTo
20 }
core/coreapi/pin.go
+10 -5
@@ -29,12 +29,12 @@ func (api *PinAPI) Add(ctx context.Context, p coreiface.Path, opts ...caopts.Pin
29 return err
30 }
31
32 - _, err = corerepo.Pin(api.node, ctx, []string{rp.Cid().String()}, settings.Recursive)
32 + _, err = corerepo.Pin(api.node, api.core(), ctx, []string{rp.Cid().String()}, settings.Recursive)
33 if err != nil {
34 return err
35 }
36
37 - return nil
37 + return api.node.Pinning.Flush()
38 }
39
40 func (api *PinAPI) Ls(ctx context.Context, opts ...caopts.PinLsOption) ([]coreiface.Pin, error) {
@@ -53,12 +53,12 @@ func (api *PinAPI) Ls(ctx context.Context, opts ...caopts.PinLsOption) ([]coreif
53 }
54
55 func (api *PinAPI) Rm(ctx context.Context, p coreiface.Path) error {
56 - _, err := corerepo.Unpin(api.node, ctx, []string{p.String()}, true)
56 + _, err := corerepo.Unpin(api.node, api.core(), ctx, []string{p.String()}, true)
57 if err != nil {
58 return err
59 }
60
61 - return nil
61 + return api.node.Pinning.Flush()
62 }
63
64 func (api *PinAPI) Update(ctx context.Context, from coreiface.Path, to coreiface.Path, opts ...caopts.PinUpdateOption) error {
@@ -77,7 +77,12 @@ func (api *PinAPI) Update(ctx context.Context, from coreiface.Path, to coreiface
77 return err
78 }
79
80 - return api.node.Pinning.Update(ctx, fp.Cid(), tp.Cid(), settings.Unpin)
80 + err = api.node.Pinning.Update(ctx, fp.Cid(), tp.Cid(), settings.Unpin)
81 + if err != nil {
82 + return err
83 + }
84 +
85 + return api.node.Pinning.Flush()
86 }
87
88 type pinStatus struct {
core/corerepo/pinning.go
+10 -22
@@ -18,28 +18,21 @@ import (
18 "fmt"
19
20 "github.com/ipfs/go-ipfs/core"
21 - uio "gx/ipfs/QmU4x3742bvgfxJsByEDpBnifJqjJdV6x528co4hwKCn46/go-unixfs/io"
22 - path "gx/ipfs/QmcjwUb36Z16NJkvDX6ccXPqsFswo6AsRXynyXcLLCphV2/go-path"
23 - resolver "gx/ipfs/QmcjwUb36Z16NJkvDX6ccXPqsFswo6AsRXynyXcLLCphV2/go-path/resolver"
21 + "github.com/ipfs/go-ipfs/core/coreapi/interface"
22
25 - cid "gx/ipfs/QmPSQnBKM9g7BaUcZCvswUJVscQ1ipjmwxN5PXCjkp9EQ7/go-cid"
23 + "gx/ipfs/QmPSQnBKM9g7BaUcZCvswUJVscQ1ipjmwxN5PXCjkp9EQ7/go-cid"
24 )
25
28 -func Pin(n *core.IpfsNode, ctx context.Context, paths []string, recursive bool) ([]cid.Cid, error) {
26 +func Pin(n *core.IpfsNode, api iface.CoreAPI, ctx context.Context, paths []string, recursive bool) ([]cid.Cid, error) {
27 out := make([]cid.Cid, len(paths))
28
31 - r := &resolver.Resolver{
32 - DAG: n.DAG,
33 - ResolveOnce: uio.ResolveUnixfsOnce,
34 - }
35 -
29 for i, fpath := range paths {
37 - p, err := path.ParsePath(fpath)
30 + p, err := iface.ParsePath(fpath)
31 if err != nil {
32 return nil, err
33 }
34
42 - dagnode, err := core.Resolve(ctx, n.Namesys, r, p)
35 + dagnode, err := api.ResolveNode(ctx, p)
36 if err != nil {
37 return nil, fmt.Errorf("pin: %s", err)
38 }
@@ -58,30 +51,25 @@ func Pin(n *core.IpfsNode, ctx context.Context, paths []string, recursive bool)
51 return out, nil
52 }
53
61 -func Unpin(n *core.IpfsNode, ctx context.Context, paths []string, recursive bool) ([]cid.Cid, error) {
54 +func Unpin(n *core.IpfsNode, api iface.CoreAPI, ctx context.Context, paths []string, recursive bool) ([]cid.Cid, error) {
55 unpinned := make([]cid.Cid, len(paths))
56
64 - r := &resolver.Resolver{
65 - DAG: n.DAG,
66 - ResolveOnce: uio.ResolveUnixfsOnce,
67 - }
68 -
57 for i, p := range paths {
70 - p, err := path.ParsePath(p)
58 + p, err := iface.ParsePath(p)
59 if err != nil {
60 return nil, err
61 }
62
75 - k, err := core.ResolveToCid(ctx, n.Namesys, r, p)
63 + k, err := api.ResolvePath(ctx, p)
64 if err != nil {
65 return nil, err
66 }
67
80 - err = n.Pinning.Unpin(ctx, k, recursive)
68 + err = n.Pinning.Unpin(ctx, k.Cid(), recursive)
69 if err != nil {
70 return nil, err
71 }
84 - unpinned[i] = k
72 + unpinned[i] = k.Cid()
73 }
74
75 err := n.Pinning.Flush()
core/coreunix/cat.go deleted
-24
@@ -1,24 +0,0 @@
1 -package coreunix
2 -
3 -import (
4 - "context"
5 -
6 - core "github.com/ipfs/go-ipfs/core"
7 - uio "gx/ipfs/QmU4x3742bvgfxJsByEDpBnifJqjJdV6x528co4hwKCn46/go-unixfs/io"
8 - path "gx/ipfs/QmcjwUb36Z16NJkvDX6ccXPqsFswo6AsRXynyXcLLCphV2/go-path"
9 - resolver "gx/ipfs/QmcjwUb36Z16NJkvDX6ccXPqsFswo6AsRXynyXcLLCphV2/go-path/resolver"
10 -)
11 -
12 -func Cat(ctx context.Context, n *core.IpfsNode, pstr string) (uio.DagReader, error) {
13 - r := &resolver.Resolver{
14 - DAG: n.DAG,
15 - ResolveOnce: uio.ResolveUnixfsOnce,
16 - }
17 -
18 - dagNode, err := core.Resolve(ctx, n.Namesys, r, path.Path(pstr))
19 - if err != nil {
20 - return nil, err
21 - }
22 -
23 - return uio.NewDagReader(ctx, dagNode, n.DAG)
24 -}
core/pathresolver.go
+2 -37
@@ -6,11 +6,10 @@ import (
6 "strings"
7
8 namesys "github.com/ipfs/go-ipfs/namesys"
9 - path "gx/ipfs/QmcjwUb36Z16NJkvDX6ccXPqsFswo6AsRXynyXcLLCphV2/go-path"
10 - resolver "gx/ipfs/QmcjwUb36Z16NJkvDX6ccXPqsFswo6AsRXynyXcLLCphV2/go-path/resolver"
9
12 - cid "gx/ipfs/QmPSQnBKM9g7BaUcZCvswUJVscQ1ipjmwxN5PXCjkp9EQ7/go-cid"
10 logging "gx/ipfs/QmZChCsSt8DctjceaL56Eibc29CVQq4dGKRXC5JRZ6Ppae/go-log"
11 + path "gx/ipfs/QmcjwUb36Z16NJkvDX6ccXPqsFswo6AsRXynyXcLLCphV2/go-path"
12 + resolver "gx/ipfs/QmcjwUb36Z16NJkvDX6ccXPqsFswo6AsRXynyXcLLCphV2/go-path/resolver"
13 ipld "gx/ipfs/QmdDXJs4axxefSPgK6Y1QhpJWKuDPnGJiqgq4uncb4rFHL/go-ipld-format"
14 )
15
@@ -74,37 +73,3 @@ func Resolve(ctx context.Context, nsys namesys.NameSystem, r *resolver.Resolver,
73 // ok, we have an IPFS path now (or what we'll treat as one)
74 return r.ResolvePath(ctx, p)
75 }
77 -
78 -// ResolveToCid resolves a path to a cid.
79 -//
80 -// It first checks if the path is already in the form of just a cid (<cid> or
81 -// /ipfs/<cid>) and returns immediately if so. Otherwise, it falls back onto
82 -// Resolve to perform resolution of the dagnode being referenced.
83 -func ResolveToCid(ctx context.Context, nsys namesys.NameSystem, r *resolver.Resolver, p path.Path) (cid.Cid, error) {
84 -
85 - // If the path is simply a cid, parse and return it. Parsed paths are already
86 - // normalized (read: prepended with /ipfs/ if needed), so segment[1] should
87 - // always be the key.
88 - if p.IsJustAKey() {
89 - return cid.Decode(p.Segments()[1])
90 - }
91 -
92 - // Fall back onto regular dagnode resolution. Retrieve the second-to-last
93 - // segment of the path and resolve its link to the last segment.
94 - head, tail, err := p.PopLastSegment()
95 - if err != nil {
96 - return cid.Cid{}, err
97 - }
98 - dagnode, err := Resolve(ctx, nsys, r, head)
99 - if err != nil {
100 - return cid.Cid{}, err
101 - }
102 -
103 - // Extract and return the cid of the link to the target dag node.
104 - link, _, err := dagnode.ResolveLink([]string{tail})
105 - if err != nil {
106 - return cid.Cid{}, err
107 - }
108 -
109 - return link.Cid, nil
110 -}
fuse/readonly/ipfs_test.go
+10 -7
@@ -14,16 +14,17 @@ import (
14 "testing"
15
16 core "github.com/ipfs/go-ipfs/core"
17 - coreunix "github.com/ipfs/go-ipfs/core/coreunix"
17 + coreapi "github.com/ipfs/go-ipfs/core/coreapi"
18 + iface "github.com/ipfs/go-ipfs/core/coreapi/interface"
19 coremock "github.com/ipfs/go-ipfs/core/mock"
19 - importer "gx/ipfs/QmU4x3742bvgfxJsByEDpBnifJqjJdV6x528co4hwKCn46/go-unixfs/importer"
20 - uio "gx/ipfs/QmU4x3742bvgfxJsByEDpBnifJqjJdV6x528co4hwKCn46/go-unixfs/io"
21 - dag "gx/ipfs/QmcBoNcAP6qDjgRBew7yjvCqHq7p5jMstE44jPUBWBxzsV/go-merkledag"
20
21 ci "gx/ipfs/QmNfQbgBfARAtrYsBguChX6VJ5nbjeoYy1KdC36aaYWqG8/go-testutil/ci"
22 u "gx/ipfs/QmPdKqUcHGFdeSpvjVoaTRPPstGif9GBZb5Q56RVw9o69A/go-ipfs-util"
23 fstest "gx/ipfs/QmSJBsmLP1XMjv8hxYg2rUMdPDB7YUpyBo9idjrJ6Cmq6F/fuse/fs/fstestutil"
24 + importer "gx/ipfs/QmU4x3742bvgfxJsByEDpBnifJqjJdV6x528co4hwKCn46/go-unixfs/importer"
25 + uio "gx/ipfs/QmU4x3742bvgfxJsByEDpBnifJqjJdV6x528co4hwKCn46/go-unixfs/io"
26 chunker "gx/ipfs/QmULKgr55cSWR8Kiwy3cVRcAiGVnR6EVSaB7hJcWS4138p/go-ipfs-chunker"
27 + dag "gx/ipfs/QmcBoNcAP6qDjgRBew7yjvCqHq7p5jMstE44jPUBWBxzsV/go-merkledag"
28 ipld "gx/ipfs/QmdDXJs4axxefSPgK6Y1QhpJWKuDPnGJiqgq4uncb4rFHL/go-ipld-format"
29 )
30
@@ -116,6 +117,8 @@ func TestIpfsStressRead(t *testing.T) {
117 nd, mnt := setupIpfsTest(t, nil)
118 defer mnt.Close()
119
120 + api := coreapi.NewCoreAPI(nd)
121 +
122 var nodes []ipld.Node
123 var paths []string
124
@@ -165,14 +168,14 @@ func TestIpfsStressRead(t *testing.T) {
168 defer wg.Done()
169
170 for i := 0; i < 2000; i++ {
168 - item := paths[rand.Intn(len(paths))]
169 - fname := path.Join(mnt.Dir, item)
171 + item, _ := iface.ParsePath(paths[rand.Intn(len(paths))])
172 + fname := path.Join(mnt.Dir, item.String())
173 rbuf, err := ioutil.ReadFile(fname)
174 if err != nil {
175 errs <- err
176 }
177
175 - read, err := coreunix.Cat(nd.Context(), nd, item)
178 + read, err := api.Unixfs().Cat(nd.Context(), item)
179 if err != nil {
180 errs <- err
181 }
test/integration/addcat_test.go
+10 -1
@@ -12,6 +12,8 @@ import (
12 "time"
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"
18 mock "github.com/ipfs/go-ipfs/core/mock"
19 "github.com/ipfs/go-ipfs/thirdparty/unit"
@@ -118,6 +120,8 @@ func DirectAddCat(data []byte, conf testutil.LatencyConfig) error {
120 }
121 defer catter.Close()
122
123 + catterApi := coreapi.NewCoreAPI(catter)
124 +
125 err = mn.LinkAll()
126 if err != nil {
127 return err
@@ -138,7 +142,12 @@ func DirectAddCat(data []byte, conf testutil.LatencyConfig) error {
142 return err
143 }
144
141 - readerCatted, err := coreunix.Cat(ctx, catter, added)
145 + ap, err := iface.ParsePath(added)
146 + if err != nil {
147 + return err
148 + }
149 +
150 + readerCatted, err := catterApi.Unixfs().Cat(ctx, ap)
151 if err != nil {
152 return err
153 }
test/integration/bench_cat_test.go
+10 -1
@@ -9,6 +9,8 @@ import (
9 "testing"
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"
15 mock "github.com/ipfs/go-ipfs/core/mock"
16 "github.com/ipfs/go-ipfs/thirdparty/unit"
@@ -64,6 +66,8 @@ func benchCat(b *testing.B, data []byte, conf testutil.LatencyConfig) error {
66 }
67 defer catter.Close()
68
69 + catterApi := coreapi.NewCoreAPI(catter)
70 +
71 err = mn.LinkAll()
72 if err != nil {
73 return err
@@ -84,8 +88,13 @@ func benchCat(b *testing.B, data []byte, conf testutil.LatencyConfig) error {
88 return err
89 }
90
91 + ap, err := iface.ParsePath(added)
92 + if err != nil {
93 + return err
94 + }
95 +
96 b.StartTimer()
88 - readerCatted, err := coreunix.Cat(ctx, catter, added)
97 + readerCatted, err := catterApi.Unixfs().Cat(ctx, ap)
98 if err != nil {
99 return err
100 }
test/integration/three_legged_cat_test.go
+11 -1
@@ -10,6 +10,8 @@ import (
10 "time"
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"
16 mock "github.com/ipfs/go-ipfs/core/mock"
17 "github.com/ipfs/go-ipfs/thirdparty/unit"
@@ -100,6 +102,9 @@ func RunThreeLeggedCat(data []byte, conf testutil.LatencyConfig) error {
102 return err
103 }
104 defer catter.Close()
105 +
106 + catterApi := coreapi.NewCoreAPI(catter)
107 +
108 mn.LinkAll()
109
110 bis := bootstrap.Peerstore.PeerInfo(bootstrap.PeerHost.ID())
@@ -116,7 +121,12 @@ func RunThreeLeggedCat(data []byte, conf testutil.LatencyConfig) error {
121 return err
122 }
123
119 - readerCatted, err := coreunix.Cat(ctx, catter, added)
124 + ap, err := iface.ParsePath(added)
125 + if err != nil {
126 + return err
127 + }
128 +
129 + readerCatted, err := catterApi.Unixfs().Cat(ctx, ap)
130 if err != nil {
131 return err
132 }