mirror of
https://github.com/ipfs/kubo.git
synced 2025-06-29 01:12:24 +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:
@ -22,18 +22,17 @@ import (
|
|||||||
uio "github.com/ipfs/go-ipfs/unixfs/io"
|
uio "github.com/ipfs/go-ipfs/unixfs/io"
|
||||||
|
|
||||||
cid "gx/ipfs/QmNp85zy9RLrQ5oQD4hPyS39ezrrXpcaa7R4Y9kxdWQLLQ/go-cid"
|
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) {
|
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{
|
r := &path.Resolver{
|
||||||
DAG: n.DAG,
|
DAG: n.DAG,
|
||||||
ResolveOnce: uio.ResolveUnixfsOnce,
|
ResolveOnce: uio.ResolveUnixfsOnce,
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, fpath := range paths {
|
for i, fpath := range paths {
|
||||||
p, err := path.ParsePath(fpath)
|
p, err := path.ParsePath(fpath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -43,18 +42,11 @@ func Pin(n *core.IpfsNode, ctx context.Context, paths []string, recursive bool)
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("pin: %s", err)
|
return nil, fmt.Errorf("pin: %s", err)
|
||||||
}
|
}
|
||||||
dagnodes = append(dagnodes, dagnode)
|
err = n.Pinning.Pin(ctx, dagnode, recursive)
|
||||||
}
|
|
||||||
|
|
||||||
var out []*cid.Cid
|
|
||||||
for _, dagnode := range dagnodes {
|
|
||||||
c := dagnode.Cid()
|
|
||||||
|
|
||||||
err := n.Pinning.Pin(ctx, dagnode, recursive)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("pin: %s", err)
|
return nil, fmt.Errorf("pin: %s", err)
|
||||||
}
|
}
|
||||||
out = append(out, c)
|
out[i] = dagnode.Cid()
|
||||||
}
|
}
|
||||||
|
|
||||||
err := n.Pinning.Flush()
|
err := n.Pinning.Flush()
|
||||||
|
Reference in New Issue
Block a user