Skip to content

Commit

Permalink
simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
gammazero committed Jan 21, 2025
1 parent 4369667 commit 9256fbe
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions ipld/unixfs/io/directory.go
Original file line number Diff line number Diff line change
Expand Up @@ -502,9 +502,8 @@ func (d *HAMTDirectory) sizeBelowThreshold(ctx context.Context, sizeChange int)

// We stop the enumeration once we have enough information and exit this function.
ctx, cancel := context.WithCancel(ctx)
defer cancel()

linkResults := d.EnumLinksAsync(ctx)

for linkResult := range linkResults {
if linkResult.Err != nil {
below = false
Expand All @@ -514,21 +513,22 @@ func (d *HAMTDirectory) sizeBelowThreshold(ctx context.Context, sizeChange int)

partialSize += linksize.LinkSizeFunction(linkResult.Link.Name, linkResult.Link.Cid)
if partialSize+sizeChange >= HAMTShardingSize {
// We have already fetched enough shards to assert we are
// above the threshold, so no need to keep fetching.
// We have already fetched enough shards to assert we are above the
// threshold, so no need to keep fetching.
below = false
break
}
}
cancel()

if !below {
cancel()
// Wait for channel to close so links are not being read after return.
for range linkResults {
}

Check warning on line 527 in ipld/unixfs/io/directory.go

View check run for this annotation

Codecov / codecov/patch

ipld/unixfs/io/directory.go#L527

Added line #L527 was not covered by tests
return false, err
}

// We enumerated *all* links in all shards and didn't reach the threshold.
// Enumerated all links in all shards before threshold reached.
return true, nil
}

Expand Down

0 comments on commit 9256fbe

Please sign in to comment.