From ec1d81b2022719fd9e4de6e73b7d694ec680ed1e Mon Sep 17 00:00:00 2001 From: Christian Kotzbauer Date: Tue, 12 Dec 2023 10:50:45 +0100 Subject: [PATCH] fix: clear tmp contents close: #503 Signed-off-by: Christian Kotzbauer --- internal/syft/syft.go | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/internal/syft/syft.go b/internal/syft/syft.go index 13b16168..bb0c54f5 100644 --- a/internal/syft/syft.go +++ b/internal/syft/syft.go @@ -2,6 +2,8 @@ package syft import ( "fmt" + "os" + "path/filepath" "runtime/debug" "strings" @@ -98,7 +100,9 @@ func (s *Syft) ExecuteSyft(img *oci.RegistryImage) (string, error) { return "", err } - return string(b), nil + bom := string(b) + removeContents("/tmp") + return bom, nil } func GetEncoder(sbomFormat string) (sbom.FormatEncoder, error) { @@ -155,3 +159,22 @@ func getSyftVersion() string { return "" } + +func removeContents(dir string) error { + d, err := os.Open(dir) + if err != nil { + return err + } + defer d.Close() + names, err := d.Readdirnames(-1) + if err != nil { + return err + } + for _, name := range names { + err = os.RemoveAll(filepath.Join(dir, name)) + if err != nil { + return err + } + } + return nil +}