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
Hide 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
...
@@ -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
Ignore
BadBlock
bool
Ignore
Errors
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
()
:
...
...
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