Skip to content

Commit

Permalink
fix: lint fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Kotzbauer <git@ckotzbauer.de>
  • Loading branch information
ckotzbauer committed Dec 12, 2023
1 parent ec1d81b commit 03da20a
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions internal/syft/syft.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package syft

import (
"fmt"
"io"
"os"
"path/filepath"
"runtime/debug"
Expand Down Expand Up @@ -101,7 +102,12 @@ func (s *Syft) ExecuteSyft(img *oci.RegistryImage) (string, error) {
}

bom := string(b)
removeContents("/tmp")
err = removeTempContents()
if err != nil {
logrus.WithError(err).Warn("Could not cleanup tmp directory")
return "", err
}

return bom, nil
}

Expand Down Expand Up @@ -160,12 +166,13 @@ func getSyftVersion() string {
return ""
}

func removeContents(dir string) error {
func removeTempContents() error {
dir := "/tmp"
d, err := os.Open(dir)
if err != nil {
return err
}
defer d.Close()
defer closeOrLog(d)
names, err := d.Readdirnames(-1)
if err != nil {
return err
Expand All @@ -178,3 +185,9 @@ func removeContents(dir string) error {
}
return nil
}

func closeOrLog(c io.Closer) {
if err := c.Close(); err != nil {
logrus.WithError(err).Warnf("Could not close file")
}
}

0 comments on commit 03da20a

Please sign in to comment.