Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-merkledag
Commits
86e56524
Unverified
Commit
86e56524
authored
Jul 18, 2019
by
Michael Muré
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add a IgnoreErrors() walking option
parent
1ee27334
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
5 deletions
+13
-5
merkledag.go
merkledag.go
+13
-5
No files found.
merkledag.go
View file @
86e56524
...
...
@@ -289,7 +289,7 @@ const defaultConcurrentFetch = 32
// WalkOptions represent the parameters of a graph walking algorithm
type
WalkOptions
struct
{
WithRoot
bool
Ignore
BadBlock
bool
Ignore
Errors
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
()
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment