Skip to content

Commit c793e51

Browse files
committed
drop external dep and update copy function
1 parent a8cc0b9 commit c793e51

File tree

2 files changed

+8
-18
lines changed

2 files changed

+8
-18
lines changed

daghelpers.go

+4-11
Original file line numberDiff line numberDiff line change
@@ -95,22 +95,15 @@ func Copy(ctx context.Context, from, to DAGService, root *cid.Cid) error {
9595
return err
9696
}
9797
links := node.Links()
98-
if len(links) == 0 {
99-
err := to.Add(ctx, node)
100-
if err != nil {
101-
return err
102-
}
103-
return nil
104-
}
10598
for _, link := range links {
10699
err := Copy(ctx, from, to, link.Cid)
107100
if err != nil {
108101
return err
109102
}
110-
err = to.Add(ctx, node)
111-
if err != nil {
112-
return err
113-
}
103+
}
104+
err = to.Add(ctx, node)
105+
if err != nil {
106+
return err
114107
}
115108
return nil
116109
}

daghelpers_test.go

+4-7
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"context"
55
"github.com/ipfs/go-cid"
66
mh "github.com/multiformats/go-multihash"
7-
"github.com/stretchr/testify/assert"
87
"testing"
98
)
109

@@ -132,13 +131,11 @@ func TestCopy(t *testing.T) {
132131
}
133132

134133
r, err := to.Get(ctx, root.Cid())
135-
if err != nil {
136-
t.Error(err)
134+
if err != nil || len(r.Links()) != 2 {
135+
t.Error("fail to copy dag")
137136
}
138137
l1, err := to.Get(ctx, l11.Cid())
139-
if err != nil {
140-
t.Error(err)
138+
if err != nil || len(l1.Links()) != 3 {
139+
t.Error("fail to copy dag")
141140
}
142-
assert.Equal(t, len(r.Links()), 2)
143-
assert.Equal(t, len(l1.Links()), 3)
144141
}

0 commit comments

Comments
 (0)