@@ -17,6 +17,7 @@ import (
17
17
"github.com/ipfs/go-ipfs-pinner/dsindex"
18
18
ipld "github.com/ipfs/go-ipld-format"
19
19
logging "github.com/ipfs/go-log"
20
+ "github.com/ipfs/go-merkledag"
20
21
mdag "github.com/ipfs/go-merkledag"
21
22
"github.com/ipfs/go-merkledag/dagutils"
22
23
"github.com/polydawn/refmt/cbor"
@@ -489,49 +490,30 @@ func (p *pinner) CheckIfPinned(ctx context.Context, cids ...cid.Cid) ([]ipfspinn
489
490
}
490
491
}
491
492
492
- // Now walk all recursive pins to check for indirect pins
493
- var checkChildren func (cid.Cid , cid.Cid ) error
494
- checkChildren = func (rk , parentKey cid.Cid ) error {
495
- links , err := ipld .GetLinks (ctx , p .dserv , parentKey )
496
- if err != nil {
497
- return err
498
- }
499
- for _ , lnk := range links {
500
- c := lnk .Cid
501
-
502
- if toCheck .Has (c ) {
503
- pinned = append (pinned ,
504
- ipfspinner.Pinned {Key : c , Mode : ipfspinner .Indirect , Via : rk })
505
- toCheck .Remove (c )
506
- }
507
-
508
- err = checkChildren (rk , c )
509
- if err != nil {
510
- return err
511
- }
512
-
513
- if toCheck .Len () == 0 {
514
- return nil
515
- }
516
- }
517
- return nil
518
- }
519
-
520
493
var e error
494
+ visited := cid .NewSet ()
521
495
err := p .cidRIndex .ForEach (ctx , "" , func (key , value string ) bool {
522
496
var rk cid.Cid
523
497
rk , e = cid .Cast ([]byte (key ))
524
498
if e != nil {
525
499
return false
526
500
}
527
- e = checkChildren (rk , rk )
501
+ e = merkledag .Walk (ctx , merkledag .GetLinksWithDAG (p .dserv ), rk , func (c cid.Cid ) bool {
502
+ if toCheck .Len () == 0 || ! visited .Visit (c ) {
503
+ return false
504
+ }
505
+
506
+ if toCheck .Has (c ) {
507
+ pinned = append (pinned , ipfspinner.Pinned {Key : c , Mode : ipfspinner .Indirect , Via : rk })
508
+ toCheck .Remove (c )
509
+ }
510
+
511
+ return true
512
+ }, merkledag .Concurrent ())
528
513
if e != nil {
529
514
return false
530
515
}
531
- if toCheck .Len () == 0 {
532
- return false
533
- }
534
- return true
516
+ return toCheck .Len () > 0
535
517
})
536
518
if err != nil {
537
519
return nil , err
0 commit comments