Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Steinhardt <psteinhardt@gitlab.com>2022-08-11 14:27:08 +0300
committerPatrick Steinhardt <psteinhardt@gitlab.com>2022-09-22 16:40:36 +0300
commit984aa42cc91eadc12288a6fcf38f1d7b62077c5d (patch)
tree7a819ac7ec1aa4ca2b61cf704615b0b5c3b74638
parent1d581c49b9e9763fb3335cf1427cec84518c19c8 (diff)
packed_binaries: Check error code when closing packed filepks-golangci-lint-errcheck-improvements
We don't properly verify the error code when closing the file that corresponds to the packed binary. While this doesn't really matter in the first place, fixing this one case lets us drop another exception to our linting rules.
-rw-r--r--.golangci.yml1
-rw-r--r--packed_binaries.go14
2 files changed, 12 insertions, 3 deletions
diff --git a/.golangci.yml b/.golangci.yml
index 17cad66ec..f97d22a09 100644
--- a/.golangci.yml
+++ b/.golangci.yml
@@ -64,7 +64,6 @@ linters-settings:
- (*io.PipeWriter).Close
- (*os.File).Close
- (io.Closer).Close
- - (io/fs.File).Close
- (net.Conn).Close
- (net.Listener).Close
forbidigo:
diff --git a/packed_binaries.go b/packed_binaries.go
index fe3e435e0..6b0774988 100644
--- a/packed_binaries.go
+++ b/packed_binaries.go
@@ -40,14 +40,20 @@ func UnpackAuxiliaryBinaries(destinationDir string) error {
if err != nil {
return fmt.Errorf("open packed binary %q: %w", packedPath, err)
}
- defer packedFile.Close()
+ defer func() {
+ // We already check the error below.
+ _ = packedFile.Close()
+ }()
unpackedPath := filepath.Join(destinationDir, entry.Name())
unpackedFile, err := os.OpenFile(unpackedPath, os.O_CREATE|os.O_EXCL|os.O_WRONLY, 0o700)
if err != nil {
return err
}
- defer unpackedFile.Close()
+ defer func() {
+ // We already check the error below.
+ _ = unpackedFile.Close()
+ }()
if _, err := io.Copy(unpackedFile, packedFile); err != nil {
return fmt.Errorf("unpack %q: %w", unpackedPath, err)
@@ -57,6 +63,10 @@ func UnpackAuxiliaryBinaries(destinationDir string) error {
return fmt.Errorf("close %q: %w", unpackedPath, err)
}
+ if err := packedFile.Close(); err != nil {
+ return fmt.Errorf("close packed file %q: %w", packedPath, err)
+ }
+
return nil
}(); err != nil {
return err