Commit 80c1eb3e authored by Kejie Zhang's avatar Kejie Zhang

add copy dagservice function

parent 6b9f5037
......@@ -89,6 +89,26 @@ func GetNodes(ctx context.Context, ds NodeGetter, keys []*cid.Cid) []*NodePromis
return promises
}
func Copy(ctx context.Context, from, to DAGService, root *cid.Cid) error {
node, err := from.Get(ctx, root)
if err != nil {
return err
}
links := node.Links()
if len(links) == 0 {
n := node.Copy()
to.Add(ctx, n)
return nil
}
for _, link := range links {
err := Copy(ctx, from, to, link.Cid)
if err != nil {
return err
}
}
return nil
}
// Remove duplicates from a list of keys
func dedupeKeys(cids []*cid.Cid) []*cid.Cid {
set := cid.NewSet()
......
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