add a IgnoreErrors() walking option

parent 1ee27334
...@@ -288,9 +288,9 @@ const defaultConcurrentFetch = 32 ...@@ -288,9 +288,9 @@ const defaultConcurrentFetch = 32
// WalkOptions represent the parameters of a graph walking algorithm // WalkOptions represent the parameters of a graph walking algorithm
type WalkOptions struct { type WalkOptions struct {
WithRoot bool WithRoot bool
IgnoreBadBlock bool IgnoreErrors bool
Concurrency int Concurrency int
} }
// WalkOption is a setter for WalkOptions // WalkOption is a setter for WalkOptions
...@@ -323,6 +323,14 @@ func Concurrency(worker int) WalkOption { ...@@ -323,6 +323,14 @@ func Concurrency(worker int) WalkOption {
} }
} }
// IgnoreErrors is a WalkOption indicating that the walk should attempt to
// continue even when an error occur.
func IgnoreErrors() WalkOption {
return func(walkOptions *WalkOptions) {
walkOptions.IgnoreErrors = true
}
}
// WalkGraph will walk the dag in order (depth first) starting at the given root. // WalkGraph will walk the dag in order (depth first) starting at the given root.
func Walk(ctx context.Context, getLinks GetLinks, c cid.Cid, visit func(cid.Cid) bool, options ...WalkOption) error { func Walk(ctx context.Context, getLinks GetLinks, c cid.Cid, visit func(cid.Cid) bool, options ...WalkOption) error {
visitDepth := func(c cid.Cid, depth int) bool { visitDepth := func(c cid.Cid, depth int) bool {
...@@ -356,7 +364,7 @@ func sequentialWalkDepth(ctx context.Context, getLinks GetLinks, root cid.Cid, d ...@@ -356,7 +364,7 @@ func sequentialWalkDepth(ctx context.Context, getLinks GetLinks, root cid.Cid, d
} }
links, err := getLinks(ctx, root) links, err := getLinks(ctx, root)
if err != nil { if err != nil && !options.IgnoreErrors {
return err return err
} }
...@@ -437,7 +445,7 @@ func parallelWalkDepth(ctx context.Context, getLinks GetLinks, root cid.Cid, vis ...@@ -437,7 +445,7 @@ func parallelWalkDepth(ctx context.Context, getLinks GetLinks, root cid.Cid, vis
if shouldVisit { if shouldVisit {
links, err := getLinks(ctx, ci) links, err := getLinks(ctx, ci)
if err != nil { if err != nil && !options.IgnoreErrors {
select { select {
case errChan <- err: case errChan <- err:
case <-fetchersCtx.Done(): case <-fetchersCtx.Done():
......
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