1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-06-28 17:03:58 +08:00

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>
This commit is contained in:
Steven Allen
2017-12-03 19:03:04 -08:00
parent 924b2a0a34
commit 498ee0dc0b

View File

@ -22,18 +22,17 @@ import (
uio "github.com/ipfs/go-ipfs/unixfs/io"
cid "gx/ipfs/QmNp85zy9RLrQ5oQD4hPyS39ezrrXpcaa7R4Y9kxdWQLLQ/go-cid"
node "gx/ipfs/QmPN7cwmpcc4DWXb4KTB9dNAJgjuPY69h3npsMfhRrQL9c/go-ipld-format"
)
func Pin(n *core.IpfsNode, ctx context.Context, paths []string, recursive bool) ([]*cid.Cid, error) {
dagnodes := make([]node.Node, 0)
out := make([]*cid.Cid, len(paths))
r := &path.Resolver{
DAG: n.DAG,
ResolveOnce: uio.ResolveUnixfsOnce,
}
for _, fpath := range paths {
for i, fpath := range paths {
p, err := path.ParsePath(fpath)
if err != nil {
return nil, err
@ -43,18 +42,11 @@ func Pin(n *core.IpfsNode, ctx context.Context, paths []string, recursive bool)
if err != nil {
return nil, fmt.Errorf("pin: %s", err)
}
dagnodes = append(dagnodes, dagnode)
}
var out []*cid.Cid
for _, dagnode := range dagnodes {
c := dagnode.Cid()
err := n.Pinning.Pin(ctx, dagnode, recursive)
err = n.Pinning.Pin(ctx, dagnode, recursive)
if err != nil {
return nil, fmt.Errorf("pin: %s", err)
}
out = append(out, c)
out[i] = dagnode.Cid()
}
err := n.Pinning.Flush()