Skip to content

Commit

Permalink
fix: clear tmp contents
Browse files Browse the repository at this point in the history
close: #503

Signed-off-by: Christian Kotzbauer <git@ckotzbauer.de>
  • Loading branch information
ckotzbauer committed Dec 12, 2023
1 parent 10c5a66 commit ec1d81b
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion internal/syft/syft.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package syft

import (
"fmt"
"os"
"path/filepath"
"runtime/debug"
"strings"

Expand Down Expand Up @@ -98,7 +100,9 @@ func (s *Syft) ExecuteSyft(img *oci.RegistryImage) (string, error) {
return "", err
}

return string(b), nil
bom := string(b)
removeContents("/tmp")

Check failure on line 104 in internal/syft/syft.go

View workflow job for this annotation

GitHub Actions / golint / lint

Error return value is not checked (errcheck)
return bom, nil
}

func GetEncoder(sbomFormat string) (sbom.FormatEncoder, error) {
Expand Down Expand Up @@ -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
}

0 comments on commit ec1d81b

Please sign in to comment.