Commit 24a9dcfa 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 9dfffa9b
......@@ -71,13 +71,9 @@ func GC(ctx context.Context, bs bstore.GCBlockstore, ls dag.LinkService, pn pin.
func Descendants(ctx context.Context, ls dag.LinkService, set key.KeySet, roots []*cid.Cid, bestEffort bool) error {
for _, c := range roots {
set.Add(key.Key(c.Hash()))
links, err := ls.GetLinks(ctx, c)
if err != nil {
return err
}
// EnumerateChildren recursively walks the dag and adds the keys to the given set
err = dag.EnumerateChildren(ctx, ls, links, func(c *cid.Cid) bool {
err := dag.EnumerateChildren(ctx, ls, c, func(c *cid.Cid) bool {
k := key.Key(c.Hash())
seen := set.Has(k)
if seen {
......
......@@ -178,7 +178,7 @@ func (p *pinner) Pin(ctx context.Context, node *mdag.Node, recurse bool) error {
}
// fetch entire graph
err := mdag.FetchGraph(ctx, node, p.dserv)
err := mdag.FetchGraph(ctx, c, p.dserv)
if err != nil {
return err
}
......@@ -279,12 +279,7 @@ func (p *pinner) isPinnedWithType(c *cid.Cid, mode PinMode) (string, bool, error
// Default is Indirect
for _, rc := range p.recursePin.Keys() {
links, err := p.dserv.GetLinks(context.Background(), rc)
if err != nil {
return "", false, err
}
has, err := hasChild(p.dserv, links, k)
has, err := hasChild(p.dserv, rc, k)
if err != nil {
return "", false, err
}
......@@ -521,19 +516,18 @@ func (p *pinner) PinWithMode(c *cid.Cid, mode PinMode) {
}
}
func hasChild(ds mdag.LinkService, links []*mdag.Link, child key.Key) (bool, error) {
func hasChild(ds mdag.LinkService, root *cid.Cid, child key.Key) (bool, error) {
links, err := ds.GetLinks(context.Background(), root)
if err != nil {
return false, err
}
for _, lnk := range links {
c := cid.NewCidV0(lnk.Hash)
if key.Key(c.Hash()) == child {
return true, nil
}
children, err := ds.GetLinks(context.Background(), c)
if err != nil {
return false, err
}
has, err := hasChild(ds, children, child)
has, err := hasChild(ds, c, child)
if err != nil {
return false, err
}
......
......@@ -225,6 +225,11 @@ func TestPinRecursiveFail(t *testing.T) {
t.Fatal(err)
}
_, err = dserv.Add(a)
if err != nil {
t.Fatal(err)
}
// this one is time based... but shouldnt cause any issues
mctx, _ = context.WithTimeout(ctx, time.Second)
err = p.Pin(mctx, a, true)
......
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