Skip to content

Commit

Permalink
fix: ignore packages with no files (project-stacker#58)
Browse files Browse the repository at this point in the history
Signed-off-by: Ramkumar Chinchani <[email protected]>
  • Loading branch information
rchincha committed Feb 7, 2024
1 parent 46a5bb4 commit 488c8b2
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
11 changes: 11 additions & 0 deletions pkg/distro/apk/apk.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down Expand Up @@ -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")

Expand Down
11 changes: 11 additions & 0 deletions pkg/distro/deb/deb.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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
Expand Down Expand Up @@ -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
}
Expand Down
1 change: 1 addition & 0 deletions pkg/distro/rpm/rpm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 488c8b2

Please sign in to comment.