Commit 498ee0dc authored by Steven Allen's avatar Steven Allen

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: default avatarSteven Allen <steven@stebalien.com>
parent 924b2a0a
......@@ -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()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment