mirror of
https://github.com/ipfs/kubo.git
synced 2026-02-25 04:17:44 +08:00
an attempt at making the editor more efficient
License: MIT Signed-off-by: Jeromy <jeromyj@gmail.com>
This commit is contained in:
parent
f1e86ec702
commit
b52210766f
@ -151,3 +151,32 @@ func rmLink(ctx context.Context, ds dag.DAGService, root *dag.Node, path []strin
|
||||
|
||||
return root, nil
|
||||
}
|
||||
|
||||
func (e *Editor) WriteOutputTo(ds dag.DAGService) error {
|
||||
return copyDag(e.GetNode(), e.ds, ds)
|
||||
}
|
||||
|
||||
func copyDag(nd *dag.Node, from, to dag.DAGService) error {
|
||||
_, err := to.Add(nd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, lnk := range nd.Links {
|
||||
child, err := lnk.GetNode(context.Background(), from)
|
||||
if err != nil {
|
||||
if err == dag.ErrNotFound {
|
||||
// not found means we didnt modify it, and it should
|
||||
// already be in the target datastore
|
||||
continue
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
err = copyDag(child, from, to)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user