@cryptotaxi247 / kubo / commits / 498ee0dc0

resolve and pin in one step

instead of resolving all the pins first and then pinning, pin after resolving each pin. This: 1. Avoids storing all the nodes in memory. 2. Avoids not showing pin progress. fixes #4122 License: MIT Signed-off-by: Steven Allen <steven@stebalien.com>

Steven Allen committed Dec 3, 2017 at 19:03 UTC 498ee0dc0b0e0f1be16ff083a08d3c691ec90efc
1 file changed +4 -12
core/corerepo/pinning.go
+4 -12
@@ -22,18 +22,17 @@ import (
22 uio "github.com/ipfs/go-ipfs/unixfs/io"
23
24 cid "gx/ipfs/QmNp85zy9RLrQ5oQD4hPyS39ezrrXpcaa7R4Y9kxdWQLLQ/go-cid"
25 - node "gx/ipfs/QmPN7cwmpcc4DWXb4KTB9dNAJgjuPY69h3npsMfhRrQL9c/go-ipld-format"
25 )
26
27 func Pin(n *core.IpfsNode, ctx context.Context, paths []string, recursive bool) ([]*cid.Cid, error) {
29 - dagnodes := make([]node.Node, 0)
28 + out := make([]*cid.Cid, len(paths))
29
30 r := &path.Resolver{
31 DAG: n.DAG,
32 ResolveOnce: uio.ResolveUnixfsOnce,
33 }
34
36 - for _, fpath := range paths {
35 + for i, fpath := range paths {
36 p, err := path.ParsePath(fpath)
37 if err != nil {
38 return nil, err
@@ -43,18 +42,11 @@ func Pin(n *core.IpfsNode, ctx context.Context, paths []string, recursive bool)
42 if err != nil {
43 return nil, fmt.Errorf("pin: %s", err)
44 }
46 - dagnodes = append(dagnodes, dagnode)
47 - }
48 -
49 - var out []*cid.Cid
50 - for _, dagnode := range dagnodes {
51 - c := dagnode.Cid()
52 -
53 - err := n.Pinning.Pin(ctx, dagnode, recursive)
45 + err = n.Pinning.Pin(ctx, dagnode, recursive)
46 if err != nil {
47 return nil, fmt.Errorf("pin: %s", err)
48 }
57 - out = append(out, c)
49 + out[i] = dagnode.Cid()
50 }
51
52 err := n.Pinning.Flush()