Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clean up temporary bom data #459

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions pkg/spdx/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import (
"os"
"path/filepath"

"github.com/sirupsen/logrus"

"sigs.k8s.io/release-utils/util"
)

Expand Down Expand Up @@ -87,6 +89,16 @@ type DocBuilder struct {
// Generate creates a new SPDX SBOM. The resulting document will describe the all
// artifacts specified in the DocGenerateOptions struct passed.
func (db *DocBuilder) Generate(genopts *DocGenerateOptions) (*Document, error) {
defer func() {
// cleanup tmp files
if util.Exists(filepath.Join(os.TempDir(), spdxTempDir)) {
logrus.Infof("Cleaning up temporary data at %s", filepath.Join(os.TempDir(), spdxTempDir))
if err := os.RemoveAll(filepath.Join(os.TempDir(), spdxTempDir)); err != nil {
logrus.Warnf("Failed to cleanup temporary data in the temporary directory: %v", err)
}
}
}()

if err := db.impl.ReadYamlConfiguration(genopts.ConfigFile, genopts); err != nil {
return nil, fmt.Errorf("parsing configuration file: %w", err)
}
Expand Down
Loading