From 03da20a1246ec4d53c8feee66a7808b070ddbd92 Mon Sep 17 00:00:00 2001 From: Christian Kotzbauer Date: Tue, 12 Dec 2023 10:58:21 +0100 Subject: [PATCH] fix: lint fixes Signed-off-by: Christian Kotzbauer --- internal/syft/syft.go | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/internal/syft/syft.go b/internal/syft/syft.go index bb0c54f5..bf1279d2 100644 --- a/internal/syft/syft.go +++ b/internal/syft/syft.go @@ -2,6 +2,7 @@ package syft import ( "fmt" + "io" "os" "path/filepath" "runtime/debug" @@ -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 } @@ -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 @@ -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") + } +}