Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit aa122a5

Browse files
committedAug 12, 2015
an attempt at making the editor more efficient
License: MIT Signed-off-by: Jeromy <jeromyj@gmail.com>
1 parent ace06b4 commit aa122a5

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed
 

‎merkledag/utils/utils.go

+29
Original file line numberDiff line numberDiff line change
@@ -153,3 +153,32 @@ func rmLink(ctx context.Context, ds dag.DAGService, root *dag.Node, path []strin
153153

154154
return root, nil
155155
}
156+
157+
func (e *Editor) WriteOutputTo(ds dag.DAGService) error {
158+
return copyDag(e.GetNode(), e.ds, ds)
159+
}
160+
161+
func copyDag(nd *dag.Node, from, to dag.DAGService) error {
162+
_, err := to.Add(nd)
163+
if err != nil {
164+
return err
165+
}
166+
167+
for _, lnk := range nd.Links {
168+
child, err := lnk.GetNode(context.Background(), from)
169+
if err != nil {
170+
if err == dag.ErrNotFound {
171+
// not found means we didnt modify it, and it should
172+
// already be in the target datastore
173+
continue
174+
}
175+
return err
176+
}
177+
178+
err = copyDag(child, from, to)
179+
if err != nil {
180+
return err
181+
}
182+
}
183+
return nil
184+
}

0 commit comments

Comments
 (0)
Please sign in to comment.