Skip to content

Commit

Permalink
[GH-168] Resolve G307 issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
030 committed Oct 10, 2021
1 parent e928b32 commit 510dab9
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/gosec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ jobs:
- name: Run Gosec Security Scanner
uses: securego/gosec@master
with:
args: -exclude=G304,G307 ./...
args: -exclude=G304 ./...
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed

- Resolve gosec G401 and G501 issues
- Resolve gosec G307, G401 and G501 issues.

## [6.0.12] - 2021-10-09

Expand Down
7 changes: 6 additions & 1 deletion internal/artifacts/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,15 @@ func createArtifact(d string, f string, content string, md5sum string) error {
}

_, err = file.WriteString(content)
defer file.Close()
if err != nil {
return err
}

defer func() {
if err == nil {
err = file.Close()
}
}()
}

if ociBucketname != "" && !objectExists {
Expand Down
7 changes: 6 additions & 1 deletion internal/artifacts/oci.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,12 @@ func ociBackup(Bucketname, Filename string) error {
if err != nil {
return err
}
defer file.Close()
defer func() {
if err == nil {
err = file.Close()
}
}()

fi, err := file.Stat()
if err != nil {
return err
Expand Down
20 changes: 17 additions & 3 deletions internal/artifacts/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,14 +213,21 @@ func (n *Nexus3) openFileAndUpload(file string) error {
if err != nil {
return err
}
defer f.Close()
defer func() {
if err == nil {
err = f.Close()
}
}()

req, err := http.NewRequest("POST", n.URL+"/repository/"+n.Repository+"/", f)
if err != nil {
return err
}

if err := n.uploadFile(file, req); err != nil {
return err
}

return nil
}

Expand All @@ -230,8 +237,15 @@ func (n *Nexus3) openMultipartFileAndUpload(f, httpMethod, uri string, statusCre
fileName := f
filePath := path.Join(fileDir, n.Repository, fileName)

file, _ := os.Open(filePath)
defer file.Close()
file, err := os.Open(filePath)
if err != nil {
return err
}
defer func() {
if err == nil {
err = file.Close()
}
}()

body := &bytes.Buffer{}
writer := multipart.NewWriter(body)
Expand Down

0 comments on commit 510dab9

Please sign in to comment.