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

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()
}