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