Commit 84ce7bc8 authored by Adrian Sutton's avatar Adrian Sutton

op-challenger: Use errors.Join

parent 8f56a3d9
package fault package fault
import ( import (
"errors"
"fmt" "fmt"
"os" "os"
"path/filepath" "path/filepath"
"strings" "strings"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/hashicorp/go-multierror"
"golang.org/x/exp/slices" "golang.org/x/exp/slices"
) )
...@@ -31,7 +31,7 @@ func (d *diskManager) RemoveAllExcept(keep []common.Address) error { ...@@ -31,7 +31,7 @@ func (d *diskManager) RemoveAllExcept(keep []common.Address) error {
if err != nil { if err != nil {
return fmt.Errorf("failed to list directory: %w", err) return fmt.Errorf("failed to list directory: %w", err)
} }
var result error var errs []error
for _, entry := range entries { for _, entry := range entries {
if !entry.IsDir() || !strings.HasPrefix(entry.Name(), gameDirPrefix) { if !entry.IsDir() || !strings.HasPrefix(entry.Name(), gameDirPrefix) {
// Skip files and directories that don't have the game directory prefix. // Skip files and directories that don't have the game directory prefix.
...@@ -49,9 +49,7 @@ func (d *diskManager) RemoveAllExcept(keep []common.Address) error { ...@@ -49,9 +49,7 @@ func (d *diskManager) RemoveAllExcept(keep []common.Address) error {
// Preserve data for games we should keep. // Preserve data for games we should keep.
continue continue
} }
if err := os.RemoveAll(filepath.Join(d.datadir, entry.Name())); err != nil { errs = append(errs, os.RemoveAll(filepath.Join(d.datadir, entry.Name())))
result = multierror.Append(result, err)
}
} }
return result return errors.Join(errs...)
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment