diff --git a/pkg/distro/apk/apk.go b/pkg/distro/apk/apk.go index c37edf0..f01e1f9 100644 --- a/pkg/distro/apk/apk.go +++ b/pkg/distro/apk/apk.go @@ -203,6 +203,8 @@ func InstalledPackage(doc *spdx.Document, pkg *IndexEntry, files []string) error LicenseDeclared: pkg.PackageLicense, } + filesFound := false + for _, file := range files { info, err := os.Stat(file) if err != nil { @@ -219,6 +221,8 @@ func InstalledPackage(doc *spdx.Document, pkg *IndexEntry, files []string) error continue } + filesFound = true + fhandle, err := os.Open(file) if err != nil { return err @@ -264,6 +268,13 @@ func InstalledPackage(doc *spdx.Document, pkg *IndexEntry, files []string) error } } + if !filesFound { + // no files found! + log.Info().Str("package", pkg.PackageName).Msg("ignoring empty package") + + return nil + } + if err := doc.AddPackage(spkg); err != nil { log.Error().Err(err).Msg("unable to add package to doc") diff --git a/pkg/distro/deb/deb.go b/pkg/distro/deb/deb.go index e6286b1..b43b125 100644 --- a/pkg/distro/deb/deb.go +++ b/pkg/distro/deb/deb.go @@ -308,6 +308,8 @@ func InstalledPackage(doc *spdx.Document, pkg Package, path string) error { scanner := bufio.NewScanner(fhandle) scanner.Split(bufio.ScanLines) + filesFound := false + for scanner.Scan() { line := scanner.Text() @@ -322,6 +324,8 @@ func InstalledPackage(doc *spdx.Document, pkg Package, path string) error { continue } + filesFound = true + fhandle, err := os.Open(line) if err != nil { return err @@ -383,6 +387,13 @@ func InstalledPackage(doc *spdx.Document, pkg Package, path string) error { spkg.LicenseDeclared = license + if !filesFound { + // no files found! + log.Info().Str("package", pkg.Package).Msg("ignoring empty package") + + return nil + } + for _, file := range spkg.Files() { file.LicenseInfoInFile = license } diff --git a/pkg/distro/rpm/rpm.go b/pkg/distro/rpm/rpm.go index 6e51fe7..0c2f32e 100644 --- a/pkg/distro/rpm/rpm.go +++ b/pkg/distro/rpm/rpm.go @@ -268,6 +268,7 @@ func InstalledPackage(doc *spdx.Document, pkg *rpmdb.PackageInfo) error { } if !filesFound { + // no files found! log.Info().Str("package", pkg.Name).Msg("ignoring empty package") return nil