Skip to content

Commit

Permalink
Replace errors.Wrapf with fmt.Errorf
Browse files Browse the repository at this point in the history
  • Loading branch information
RebeccaMahany committed Apr 10, 2024
1 parent fa777d9 commit a4356a2
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions fsutil/filesystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"strings"

"github.com/kolide/kit/env"
"github.com/pkg/errors"
)

const (
Expand Down Expand Up @@ -95,13 +94,13 @@ func CopyFile(src, dest string) error {
func UntarBundle(destination string, source string) error {
f, err := os.Open(source)
if err != nil {
return errors.Wrap(err, "open download source")
return fmt.Errorf("opening source: %w", err)
}
defer f.Close()

gzr, err := gzip.NewReader(f)
if err != nil {
return errors.Wrapf(err, "create gzip reader from %s", source)
return fmt.Errorf("creating gzip reader from %s: %w", source, err)
}
defer gzr.Close()

Expand All @@ -112,18 +111,18 @@ func UntarBundle(destination string, source string) error {
break
}
if err != nil {
return errors.Wrap(err, "reading tar file")
return fmt.Errorf("reading tar file: %w", err)
}

if err := sanitizeExtractPath(filepath.Dir(destination), header.Name); err != nil {
return errors.Wrap(err, "checking filename")
return fmt.Errorf("checking filename: %w", err)
}

destPath := filepath.Join(filepath.Dir(destination), header.Name)
info := header.FileInfo()
if info.IsDir() {
if err = os.MkdirAll(destPath, info.Mode()); err != nil {
return errors.Wrapf(err, "creating directory for tar file: %s", destPath)
return fmt.Errorf("creating directory %s for tar file: %w", destPath, err)
}
continue
}
Expand Down Expand Up @@ -153,7 +152,7 @@ func writeBundleFile(destPath string, perm fs.FileMode, srcReader io.Reader) err
func sanitizeExtractPath(filePath string, destination string) error {
destpath := filepath.Join(destination, filePath)
if !strings.HasPrefix(destpath, filepath.Clean(destination)+string(os.PathSeparator)) {
return errors.Errorf("%s: illegal file path", filePath)
return fmt.Errorf("%s: illegal file path", filePath)
}
return nil
}

0 comments on commit a4356a2

Please sign in to comment.