Skip to content

Commit

Permalink
Implement fixes, ignore G115 for header mode
Browse files Browse the repository at this point in the history
Signed-off-by: egibs <[email protected]>
  • Loading branch information
egibs committed Oct 7, 2024
1 parent ea1d80f commit df91250
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ linters:
enable:
- asciicheck
- bodyclose
- copyloopvar
- cyclop
- dogsled
- dupl
Expand All @@ -108,7 +109,6 @@ linters:
- errname
- errorlint
- exhaustive
- exportloopref
- forcetypeassert
- gocognit
- goconst
Expand Down
4 changes: 4 additions & 0 deletions pkg/action/archive.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,11 @@ func extractTar(ctx context.Context, d string, f string) error {

for {
header, err := tr.Next()

if errors.Is(err, io.ErrUnexpectedEOF) || errors.Is(err, io.EOF) {
break
}

if err != nil {
return fmt.Errorf("failed to read tar header: %w", err)
}
Expand All @@ -84,6 +86,7 @@ func extractTar(ctx context.Context, d string, f string) error {
}
target := filepath.Join(d, clean)
if header.FileInfo().IsDir() {
// #nosec G115
if err := os.MkdirAll(target, os.FileMode(header.Mode)); err != nil {
return fmt.Errorf("failed to create directory: %w", err)
}
Expand All @@ -94,6 +97,7 @@ func extractTar(ctx context.Context, d string, f string) error {
return fmt.Errorf("failed to create directory for file: %w", err)
}

// #nosec G115
f, err := os.OpenFile(target, os.O_RDWR|os.O_CREATE|os.O_TRUNC, os.FileMode(header.Mode))
if err != nil {
return fmt.Errorf("failed to create file: %w", err)
Expand Down
2 changes: 0 additions & 2 deletions pkg/action/archive_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ func TestExtractionMethod(t *testing.T) {
}

for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
got := extractionMethod(tt.ext)
if (got == nil) != (tt.want == nil) {
Expand Down Expand Up @@ -72,7 +71,6 @@ func TestExtractionMultiple(t *testing.T) {
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.path, func(t *testing.T) {
t.Parallel()
ctx := context.Background()
Expand Down
1 change: 0 additions & 1 deletion pkg/action/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,6 @@ func recursiveScan(ctx context.Context, c malcontent.Config) (*malcontent.Report
var g errgroup.Group
g.SetLimit(maxConcurrency)
for path := range pc {
path := path
g.Go(func() error {
if isSupportedArchive(path) {
return handleArchive(path)
Expand Down

0 comments on commit df91250

Please sign in to comment.