Skip to content

Commit

Permalink
Fail to construct preload hamt shards when traversal fails
Browse files Browse the repository at this point in the history
Fix #54
  • Loading branch information
willscott committed Jul 6, 2023
1 parent 364a549 commit 2450f69
Showing 1 changed file with 24 additions and 7 deletions.
31 changes: 24 additions & 7 deletions hamt/shardeddir.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,13 @@ func NewUnixFSHAMTShardWithPreload(ctx context.Context, substrate dagpb.PBNode,
return n, err
}

traverse := n.Length()
traverse, err := n.(*_UnixFSHAMTShard).length()

Check warning on line 68 in hamt/shardeddir.go

View check run for this annotation

Codecov / codecov/patch

hamt/shardeddir.go#L68

Added line #L68 was not covered by tests
if traverse == -1 {
return n, fmt.Errorf("could not fully explore hamt during preload")
}
if err != nil {
return n, err
}

Check warning on line 74 in hamt/shardeddir.go

View check run for this annotation

Codecov / codecov/patch

hamt/shardeddir.go#L72-L74

Added lines #L72 - L74 were not covered by tests

return n, nil
}
Expand Down Expand Up @@ -261,9 +264,9 @@ func (n UnixFSHAMTShard) ListIterator() ipld.ListIterator {

// Length returns the length of a list, or the number of entries in a map,
// or -1 if the node is not of list nor map kind.
func (n UnixFSHAMTShard) Length() int64 {
func (n UnixFSHAMTShard) length() (int64, error) {
if n.cachedLength != -1 {
return n.cachedLength
return n.cachedLength, nil

Check warning on line 269 in hamt/shardeddir.go

View check run for this annotation

Codecov / codecov/patch

hamt/shardeddir.go#L269

Added line #L269 was not covered by tests
}
maxPadLen := maxPadLength(n.data)
total := int64(0)
Expand All @@ -272,20 +275,34 @@ func (n UnixFSHAMTShard) Length() int64 {
_, pbLink := itr.Next()
isValue, err := isValueLink(pbLink, maxPadLen)
if err != nil {
continue
return 0, err

Check warning on line 278 in hamt/shardeddir.go

View check run for this annotation

Codecov / codecov/patch

hamt/shardeddir.go#L278

Added line #L278 was not covered by tests
}
if isValue {
total++
} else {
child, err := n.loadChild(pbLink)
if err != nil {
continue
return 0, err

Check warning on line 285 in hamt/shardeddir.go

View check run for this annotation

Codecov / codecov/patch

hamt/shardeddir.go#L285

Added line #L285 was not covered by tests
}
total += child.Length()
cl, err := child.length()
if err != nil {
return 0, err
}

Check warning on line 290 in hamt/shardeddir.go

View check run for this annotation

Codecov / codecov/patch

hamt/shardeddir.go#L289-L290

Added lines #L289 - L290 were not covered by tests
total += cl
}
}
n.cachedLength = total
return total
return total, nil
}

// Length returns the length of a list, or the number of entries in a map,
// or -1 if the node is not of list nor map kind.
func (n UnixFSHAMTShard) Length() int64 {
len, err := n.length()
if err != nil {
return 0
}

Check warning on line 304 in hamt/shardeddir.go

View check run for this annotation

Codecov / codecov/patch

hamt/shardeddir.go#L303-L304

Added lines #L303 - L304 were not covered by tests
return len
}

func (n UnixFSHAMTShard) IsAbsent() bool {
Expand Down

0 comments on commit 2450f69

Please sign in to comment.