Skip to content

Commit

Permalink
Incorporate review feedback
Browse files Browse the repository at this point in the history
- don't use import alias
- close all readers / writers
- fix typo
- also use bosh filesystem interface when reading file contents
  • Loading branch information
rkoster committed Oct 17, 2024
1 parent af1229a commit 7f488fc
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions fileutil/tarball_compressor.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"path/filepath"

"archive/tar"
gzip "github.com/klauspost/pgzip"
"github.com/klauspost/pgzip"

bosherr "github.com/cloudfoundry/bosh-utils/errors"
boshsys "github.com/cloudfoundry/bosh-utils/system"
Expand Down Expand Up @@ -37,7 +37,7 @@ func (c tarballCompressor) CompressSpecificFilesInDir(dir string, files []string

defer tarball.Close()

zw := gzip.NewWriter(tarball)
zw := pgzip.NewWriter(tarball)
tw := tar.NewWriter(zw)

for _, file := range files {
Expand Down Expand Up @@ -66,7 +66,9 @@ func (c tarballCompressor) CompressSpecificFilesInDir(dir string, files []string
}

if fi.Mode().IsRegular() {
data, err := os.Open(f)
data, err := c.fs.OpenFile(f, os.O_RDONLY, 0)
defer data.Close()

Check failure on line 70 in fileutil/tarball_compressor.go

View workflow job for this annotation

GitHub Actions / lint (ubuntu-latest)

SA5001: should check error returned from c.fs.OpenFile() before deferring data.Close() (staticcheck)

Check failure on line 70 in fileutil/tarball_compressor.go

View workflow job for this annotation

GitHub Actions / lint (ubuntu-latest)

SA5001: should check error returned from c.fs.OpenFile() before deferring data.Close() (staticcheck)

if err != nil {
return bosherr.WrapError(err, "Reading tar source file")
}
Expand Down Expand Up @@ -99,11 +101,15 @@ func (c tarballCompressor) DecompressFileToDir(tarballPath string, dir string, o
}

tarball, err := c.fs.OpenFile(tarballPath, os.O_RDONLY, 0)
defer tarball.Close()

Check failure on line 104 in fileutil/tarball_compressor.go

View workflow job for this annotation

GitHub Actions / lint (ubuntu-latest)

SA5001: should check error returned from c.fs.OpenFile() before deferring tarball.Close() (staticcheck)

Check failure on line 104 in fileutil/tarball_compressor.go

View workflow job for this annotation

GitHub Actions / lint (ubuntu-latest)

SA5001: should check error returned from c.fs.OpenFile() before deferring tarball.Close() (staticcheck)

if err != nil {
return bosherr.WrapError(err, "Opening tarball")
}

zr, err := gzip.NewReader(tarball)
zr, err := pgzip.NewReader(tarball)
defer zr.Close()

Check failure on line 111 in fileutil/tarball_compressor.go

View workflow job for this annotation

GitHub Actions / lint (ubuntu-latest)

SA5001: should check error returned from pgzip.NewReader() before deferring zr.Close() (staticcheck)

Check failure on line 111 in fileutil/tarball_compressor.go

View workflow job for this annotation

GitHub Actions / lint (ubuntu-latest)

SA5001: should check error returned from pgzip.NewReader() before deferring zr.Close() (staticcheck)

if err != nil {
return bosherr.WrapError(err, "Creating gzip reader")
}
Expand Down Expand Up @@ -151,7 +157,7 @@ func (c tarballCompressor) DecompressFileToDir(tarballPath string, dir string, o
return bosherr.WrapError(err, "Decompressing file contents")
}
default:
return fmt.Errorf("uknown type: %v in %s for tar: %s",
return fmt.Errorf("unknown type: %v in %s for tar: %s",
header.Typeflag, header.Name, tarballPath)
}

Expand Down

0 comments on commit 7f488fc

Please sign in to comment.