Skip to content

Commit

Permalink
commentary
Browse files Browse the repository at this point in the history
  • Loading branch information
rauljordan committed Jul 8, 2024
1 parent ee66142 commit 66114a5
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion staker/challenge-cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ func (c *Cache) Prune(ctx context.Context, messageNumber uint64) error {
if err != nil {
return err
}
// Delete the directory if the message number is <= the specified value.
// Collect the directory path if the message number is <= the specified value.
if dirNameMessageNum <= int(messageNumber) {
pathsToDelete = append(pathsToDelete, path)
}
Expand All @@ -211,6 +211,8 @@ func (c *Cache) Prune(ctx context.Context, messageNumber uint64) error {
}); err != nil {
return err
}
// We delete separately from collecting the paths, as deleting while walking
// a dir can cause issues with the filepath.Walk function.
for _, path := range pathsToDelete {
if err := os.RemoveAll(path); err != nil {
return fmt.Errorf("could not prune directory with path %s: %w", path, err)
Expand Down

0 comments on commit 66114a5

Please sign in to comment.