add a IgnoreErrors() walking option

parent 1ee27334
......@@ -289,7 +289,7 @@ const defaultConcurrentFetch = 32
// WalkOptions represent the parameters of a graph walking algorithm
type WalkOptions struct {
WithRoot bool
IgnoreBadBlock bool
IgnoreErrors bool
Concurrency int
}
......@@ -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.
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 {
......@@ -356,7 +364,7 @@ func sequentialWalkDepth(ctx context.Context, getLinks GetLinks, root cid.Cid, d
}
links, err := getLinks(ctx, root)
if err != nil {
if err != nil && !options.IgnoreErrors {
return err
}
......@@ -437,7 +445,7 @@ func parallelWalkDepth(ctx context.Context, getLinks GetLinks, root cid.Cid, vis
if shouldVisit {
links, err := getLinks(ctx, ci)
if err != nil {
if err != nil && !options.IgnoreErrors {
select {
case errChan <- err:
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