refractor: remove dependency on pkg/errors.

This commit is contained in:
Alexandre Pujol 2024-03-07 17:25:13 +00:00
parent 09cdf6158d
commit d40985099c
No known key found for this signature in database
GPG Key ID: C5469996F0DF68EC
4 changed files with 8 additions and 11 deletions

1
go.mod
View File

@ -4,7 +4,6 @@ go 1.21
require (
github.com/arduino/go-paths-helper v1.12.0
github.com/pkg/errors v0.9.1
golang.org/x/exp v0.0.0-20240222234643-814bf88cf225
gopkg.in/yaml.v2 v2.4.0
)

2
go.sum
View File

@ -2,8 +2,6 @@ github.com/arduino/go-paths-helper v1.12.0 h1:xizOQtI9iHdl19qXd1EmWg5i9W//2bOCOY
github.com/arduino/go-paths-helper v1.12.0/go.mod h1:jcpW4wr0u69GlXhTYydsdsqAjLaYK5n7oWHfKqOG6LM=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=

View File

@ -5,12 +5,12 @@
package integration
import (
"fmt"
"io"
"net/http"
"strings"
"github.com/arduino/go-paths-helper"
"github.com/pkg/errors"
"github.com/roddhjav/apparmor.d/pkg/util"
)
@ -33,7 +33,7 @@ func (t Tldr) Download() error {
if !gzPath.Exist() {
resp, err := http.Get(t.Url)
if err != nil {
return errors.Wrapf(err, "downloading %s", t.Url)
return fmt.Errorf("downloading %s: %w", t.Url, err)
}
defer resp.Body.Close()

View File

@ -7,12 +7,12 @@ package util
import (
"archive/tar"
"compress/gzip"
"fmt"
"io"
"path/filepath"
"strings"
"github.com/arduino/go-paths-helper"
"github.com/pkg/errors"
)
// Either or not to extract the file
@ -29,18 +29,18 @@ func toExtrat(name string, subfolders []string) bool {
func ExtratTo(src *paths.Path, dst *paths.Path, subfolders []string) error {
gzIn, err := src.Open()
if err != nil {
return errors.Wrapf(err, "opening %s", src)
return fmt.Errorf("opening %s: %w", src, err)
}
defer gzIn.Close()
in, err := gzip.NewReader(gzIn)
if err != nil {
return errors.Wrapf(err, "decoding %s", src)
return fmt.Errorf("decoding %s: %w", src, err)
}
defer in.Close()
if err := dst.MkdirAll(); err != nil {
return errors.Wrapf(err, "creating %s", src)
return fmt.Errorf("creating %s: %w", src, err)
}
tarIn := tar.NewReader(in)
@ -60,10 +60,10 @@ func ExtratTo(src *paths.Path, dst *paths.Path, subfolders []string) error {
path := dst.Join(filepath.Base(header.Name))
file, err := path.Create()
if err != nil {
return errors.Wrapf(err, "creating %s", file.Name())
return fmt.Errorf("creating %s: %w", file.Name(), err)
}
if _, err := io.Copy(file, tarIn); err != nil {
return errors.Wrapf(err, "extracting %s", file.Name())
return fmt.Errorf("extracting %s: %w", file.Name(), err)
}
file.Close()
}