Commit 67ad3923 authored by Kevin Atkinson's avatar Kevin Atkinson

Fix EnumerateChildren & hasChild to take a *cid.Cid instead of []*mdag.Link

Author: Kevin Atkinson <k@kevina.org>

Fix EnumerateChildren & hasChild to take a *cid.Cid instead of []*mdag.Link

Author: Jeromy Johnson <why@ipfs.io>

make FetchGraph use a cid

pin: fix TestPinRecursiveFail

License: MIT
Signed-off-by: default avatarJeromy <why@ipfs.io>

License: MIT
Signed-off-by: default avatarKevin Atkinson <k@kevina.org>
parent 5631a910
......@@ -126,8 +126,8 @@ func (n *dagService) Remove(nd *Node) error {
}
// FetchGraph fetches all nodes that are children of the given node
func FetchGraph(ctx context.Context, root *Node, serv DAGService) error {
return EnumerateChildrenAsync(ctx, serv, root, cid.NewSet().Visit)
func FetchGraph(ctx context.Context, c *cid.Cid, serv DAGService) error {
return EnumerateChildrenAsync(ctx, serv, c, cid.NewSet().Visit)
}
// FindLinks searches this nodes links for the given key,
......@@ -394,19 +394,17 @@ func legacyCidFromLink(lnk *Link) *cid.Cid {
// EnumerateChildren will walk the dag below the given root node and add all
// unseen children to the passed in set.
// TODO: parallelize to avoid disk latency perf hits?
func EnumerateChildren(ctx context.Context, ds LinkService, links []*Link, visit func(*cid.Cid) bool, bestEffort bool) error {
func EnumerateChildren(ctx context.Context, ds LinkService, root *cid.Cid, visit func(*cid.Cid) bool, bestEffort bool) error {
links, err := ds.GetLinks(ctx, root)
if bestEffort && err == ErrNotFound {
return nil
} else if err != nil {
return err
}
for _, lnk := range links {
c := legacyCidFromLink(lnk)
if visit(c) {
children, err := ds.GetLinks(ctx, c)
if err != nil {
if bestEffort && err == ErrNotFound {
continue
} else {
return err
}
}
err = EnumerateChildren(ctx, ds, children, visit, bestEffort)
err = EnumerateChildren(ctx, ds, c, visit, bestEffort)
if err != nil {
return err
}
......@@ -415,7 +413,7 @@ func EnumerateChildren(ctx context.Context, ds LinkService, links []*Link, visit
return nil
}
func EnumerateChildrenAsync(ctx context.Context, ds DAGService, root *Node, visit func(*cid.Cid) bool) error {
func EnumerateChildrenAsync(ctx context.Context, ds DAGService, c *cid.Cid, visit func(*cid.Cid) bool) error {
toprocess := make(chan []*cid.Cid, 8)
nodes := make(chan *NodeOption, 8)
......@@ -425,6 +423,11 @@ func EnumerateChildrenAsync(ctx context.Context, ds DAGService, root *Node, visi
go fetchNodes(ctx, ds, toprocess, nodes)
root, err := ds.Get(ctx, c)
if err != nil {
return err
}
nodes <- &NodeOption{Node: root}
live := 1
......
......@@ -231,7 +231,7 @@ func TestFetchGraph(t *testing.T) {
t.Fatal(err)
}
err = FetchGraph(context.TODO(), root, dservs[1])
err = FetchGraph(context.TODO(), root.Cid(), dservs[1])
if err != nil {
t.Fatal(err)
}
......@@ -241,7 +241,7 @@ func TestFetchGraph(t *testing.T) {
offline_ds := NewDAGService(bs)
err = EnumerateChildren(context.Background(), offline_ds, root.Links, func(_ *cid.Cid) bool { return true }, false)
err = EnumerateChildren(context.Background(), offline_ds, root.Cid(), func(_ *cid.Cid) bool { return true }, false)
if err != nil {
t.Fatal(err)
}
......@@ -258,7 +258,7 @@ func TestEnumerateChildren(t *testing.T) {
}
set := cid.NewSet()
err = EnumerateChildren(context.Background(), ds, root.Links, set.Visit, false)
err = EnumerateChildren(context.Background(), ds, root.Cid(), set.Visit, false)
if err != nil {
t.Fatal(err)
}
......@@ -269,7 +269,7 @@ func TestEnumerateChildren(t *testing.T) {
for _, lnk := range n.Links {
c := cid.NewCidV0(lnk.Hash)
if !set.Has(c) {
t.Fatal("missing key in set!")
t.Fatal("missing key in set! ", lnk.Hash.B58String())
}
child, err := ds.Get(context.Background(), c)
if err != nil {
......
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