Skip to content

Commit

Permalink
Bugfix: Do not walk pages we walked before. (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
scudette authored Dec 3, 2019
1 parent 9cc509a commit 0c80dd2
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions parser/pages.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,20 @@ func (self *ESENT_LEAF_HEADER) Dump() {
func WalkPages(ctx *ESEContext,
id int64,
cb func(header *PageHeader, page_id int64, value *Value) error) error {
if id <= 0 {
seen := make(map[int64]bool)

return _walkPages(ctx, id, seen, cb)
}

func _walkPages(ctx *ESEContext,
id int64, seen map[int64]bool,
cb func(header *PageHeader, page_id int64, value *Value) error) error {

_, pres := seen[id]
if id <= 0 || pres {
return nil
}
seen[id] = true

if DebugWalk {
fmt.Printf("Walking page %v\n", id)
Expand All @@ -248,15 +259,15 @@ func WalkPages(ctx *ESEContext,
} else if header.IsBranch() {
// Walk the branch
branch := NewESENT_BRANCH_ENTRY(ctx, value)
err := WalkPages(ctx, branch.ChildPageNumber(), cb)
err := _walkPages(ctx, branch.ChildPageNumber(), seen, cb)
if err != nil {
return err
}
}
}

if header.NextPageNumber() > 0 {
err := WalkPages(ctx, int64(header.NextPageNumber()), cb)
err := _walkPages(ctx, int64(header.NextPageNumber()), seen, cb)
if err != nil {
return err
}
Expand Down

0 comments on commit 0c80dd2

Please sign in to comment.