Commit c793e51b authored by Kejie Zhang's avatar Kejie Zhang

drop external dep and update copy function

parent a8cc0b99
......@@ -95,23 +95,16 @@ func Copy(ctx context.Context, from, to DAGService, root *cid.Cid) error {
return err
}
links := node.Links()
if len(links) == 0 {
err := to.Add(ctx, node)
if err != nil {
return err
}
return nil
}
for _, link := range links {
err := Copy(ctx, from, to, link.Cid)
if err != nil {
return err
}
}
err = to.Add(ctx, node)
if err != nil {
return err
}
}
return nil
}
......
......@@ -4,7 +4,6 @@ import (
"context"
"github.com/ipfs/go-cid"
mh "github.com/multiformats/go-multihash"
"github.com/stretchr/testify/assert"
"testing"
)
......@@ -132,13 +131,11 @@ func TestCopy(t *testing.T) {
}
r, err := to.Get(ctx, root.Cid())
if err != nil {
t.Error(err)
if err != nil || len(r.Links()) != 2 {
t.Error("fail to copy dag")
}
l1, err := to.Get(ctx, l11.Cid())
if err != nil {
t.Error(err)
if err != nil || len(l1.Links()) != 3 {
t.Error("fail to copy dag")
}
assert.Equal(t, len(r.Links()), 2)
assert.Equal(t, len(l1.Links()), 3)
}
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