diff --git a/go.mod b/go.mod index fe90888..b877f1a 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,6 @@ require ( github.com/andybalholm/brotli v1.1.1 github.com/bodgit/plumbing v1.3.0 github.com/bodgit/windows v1.0.1 - github.com/hashicorp/go-multierror v1.1.1 github.com/hashicorp/golang-lru/v2 v2.0.7 github.com/klauspost/compress v1.17.11 github.com/pierrec/lz4/v4 v4.1.21 @@ -19,7 +18,6 @@ require ( require ( github.com/davecgh/go-spew v1.1.1 // indirect - github.com/hashicorp/errwrap v1.0.0 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index 029681e..31c07e8 100644 --- a/go.sum +++ b/go.sum @@ -60,10 +60,6 @@ github.com/google/pprof v0.0.0-20200212024743-f11f1df84d12/go.mod h1:ZgVRPoUq/hf github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk= -github.com/hashicorp/errwrap v1.0.0 h1:hLrqtEDnRye3+sgx6z4qVLNuviH3MR5aQ0ykNJa/UYA= -github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= -github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo= -github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM= github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hashicorp/golang-lru/v2 v2.0.7 h1:a+bsQ5rvGLjzHuww6tVxozPZFVghXaHOwFs4luLUK2k= diff --git a/internal/bcj2/reader.go b/internal/bcj2/reader.go index 957ea23..24c8aec 100644 --- a/internal/bcj2/reader.go +++ b/internal/bcj2/reader.go @@ -9,7 +9,6 @@ import ( "io" "github.com/bodgit/sevenzip/internal/util" - "github.com/hashicorp/go-multierror" ) type readCloser struct { @@ -102,8 +101,7 @@ func (rc *readCloser) Close() error { return errAlreadyClosed } - //nolint:lll - if err := multierror.Append(rc.main.Close(), rc.call.Close(), rc.jump.Close(), rc.rd.Close()).ErrorOrNil(); err != nil { + if err := errors.Join(rc.main.Close(), rc.call.Close(), rc.jump.Close(), rc.rd.Close()); err != nil { return fmt.Errorf("bcj2: error closing: %w", err) } diff --git a/internal/deflate/reader.go b/internal/deflate/reader.go index c0b4e4d..e02a2cd 100644 --- a/internal/deflate/reader.go +++ b/internal/deflate/reader.go @@ -8,7 +8,6 @@ import ( "sync" "github.com/bodgit/sevenzip/internal/util" - "github.com/hashicorp/go-multierror" "github.com/klauspost/compress/flate" ) @@ -30,7 +29,7 @@ func (rc *readCloser) Close() error { return errAlreadyClosed } - if err := multierror.Append(rc.fr.Close(), rc.c.Close()).ErrorOrNil(); err != nil { + if err := errors.Join(rc.fr.Close(), rc.c.Close()); err != nil { return fmt.Errorf("deflate: error closing: %w", err) } diff --git a/reader.go b/reader.go index 635f5c2..7b5358a 100644 --- a/reader.go +++ b/reader.go @@ -21,7 +21,6 @@ import ( "github.com/bodgit/plumbing" "github.com/bodgit/sevenzip/internal/pool" "github.com/bodgit/sevenzip/internal/util" - "github.com/hashicorp/go-multierror" "go4.org/readerutil" ) @@ -202,7 +201,7 @@ func OpenReaderWithPassword(name, password string) (*ReadCloser, error) { info, err := f.Stat() if err != nil { - err = multierror.Append(err, f.Close()) + err = errors.Join(err, f.Close()) return nil, fmt.Errorf("sevenzip: error retrieving file info: %w", err) } @@ -222,22 +221,28 @@ func OpenReaderWithPassword(name, password string) (*ReadCloser, error) { break } + errs := make([]error, 0, len(files)+1) + errs = append(errs, err) + for _, file := range files { - err = multierror.Append(err, file.Close()) + errs = append(errs, file.Close()) } - return nil, fmt.Errorf("sevenzip: error opening: %w", err) + return nil, fmt.Errorf("sevenzip: error opening: %w", errors.Join(errs...)) } files = append(files, f) info, err = f.Stat() if err != nil { + errs := make([]error, 0, len(files)+1) + errs = append(errs, err) + for _, file := range files { - err = multierror.Append(err, file.Close()) + errs = append(errs, file.Close()) } - return nil, fmt.Errorf("sevenzip: error retrieving file info: %w", err) + return nil, fmt.Errorf("sevenzip: error retrieving file info: %w", errors.Join(errs...)) } sr = append(sr, io.NewSectionReader(f, 0, info.Size())) @@ -251,11 +256,14 @@ func OpenReaderWithPassword(name, password string) (*ReadCloser, error) { r.p = password if err := r.init(reader, size); err != nil { + errs := make([]error, 0, len(files)+1) + errs = append(errs, err) + for _, file := range files { - err = multierror.Append(err, file.Close()) + errs = append(errs, file.Close()) } - return nil, fmt.Errorf("sevenzip: error initialising: %w", err) + return nil, fmt.Errorf("sevenzip: error initialising: %w", errors.Join(errs...)) } r.f = files @@ -465,7 +473,7 @@ func (z *Reader) init(r io.ReaderAt, size int64) (err error) { } defer func() { - err = multierror.Append(err, fr.Close()).ErrorOrNil() + err = errors.Join(err, fr.Close()) }() if header, err = readEncodedHeader(util.ByteReadCloser(fr)); err != nil { @@ -551,11 +559,14 @@ func (rc *ReadCloser) Volumes() []string { } // Close closes the 7-zip file or volumes, rendering them unusable for I/O. -func (rc *ReadCloser) Close() (err error) { +func (rc *ReadCloser) Close() error { + errs := make([]error, 0, len(rc.f)) + for _, f := range rc.f { - err = multierror.Append(err, f.Close()).ErrorOrNil() + errs = append(errs, f.Close()) } + err := errors.Join(errs...) if err != nil { err = fmt.Errorf("sevenzip: error closing: %w", err) } diff --git a/reader_test.go b/reader_test.go index d9760ab..8286755 100644 --- a/reader_test.go +++ b/reader_test.go @@ -15,7 +15,6 @@ import ( "github.com/bodgit/sevenzip" "github.com/bodgit/sevenzip/internal/util" - "github.com/hashicorp/go-multierror" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "golang.org/x/sync/errgroup" @@ -66,7 +65,7 @@ func extractArchive(tb testing.TB, r *sevenzip.ReadCloser, stream int, h hash.Ha } defer func() { - err = multierror.Append(err, rc.Close()).ErrorOrNil() + err = errors.Join(err, rc.Close()) }() if err = extractFile(tb, fn(rc), h, f); err != nil { @@ -467,7 +466,7 @@ func benchmarkArchiveNaiveParallel(b *testing.B, file string, workers int) { } defer func() { - err = multierror.Append(err, rc.Close()).ErrorOrNil() + err = errors.Join(err, rc.Close()) }() return extractFile(b, rc, crc32.NewIEEE(), f)