an attempt at making the editor more efficient
License: MIT Signed-off-by: Jeromy <jeromyj@gmail.com>
Jeromy committed
Aug 12, 2015 at 13:44 UTC
b52210766f396cfe70e689fa415429ca4e6fac77
1 file changed
+29
merkledag/utils/utils.go
+29
@@ -151,3 +151,32 @@ func rmLink(ctx context.Context, ds dag.DAGService, root *dag.Node, path []strin
151
152
return root, nil
153
}
154
+
155
+func (e *Editor) WriteOutputTo(ds dag.DAGService) error {
156
+ return copyDag(e.GetNode(), e.ds, ds)
157
+}
158
+
159
+func copyDag(nd *dag.Node, from, to dag.DAGService) error {
160
+ _, err := to.Add(nd)
161
+ if err != nil {
162
+ return err
163
+ }
164
+
165
+ for _, lnk := range nd.Links {
166
+ child, err := lnk.GetNode(context.Background(), from)
167
+ if err != nil {
168
+ if err == dag.ErrNotFound {
169
+ // not found means we didnt modify it, and it should
170
+ // already be in the target datastore
171
+ continue
172
+ }
173
+ return err
174
+ }
175
+
176
+ err = copyDag(child, from, to)
177
+ if err != nil {
178
+ return err
179
+ }
180
+ }
181
+ return nil
182
+}