mirror of
https://github.com/anchore/syft.git
synced 2025-11-17 16:33:21 +01:00
chore: add debug logging for errors reading RPM files (#3051)
Signed-off-by: Keith Zantow <kzantow@gmail.com>
This commit is contained in:
parent
bfe6f5204a
commit
125c787e40
@ -8,6 +8,7 @@ import (
|
|||||||
rpmdb "github.com/knqyf263/go-rpmdb/pkg"
|
rpmdb "github.com/knqyf263/go-rpmdb/pkg"
|
||||||
"github.com/sassoftware/go-rpmutils"
|
"github.com/sassoftware/go-rpmutils"
|
||||||
|
|
||||||
|
"github.com/anchore/syft/internal/log"
|
||||||
"github.com/anchore/syft/syft/artifact"
|
"github.com/anchore/syft/syft/artifact"
|
||||||
"github.com/anchore/syft/syft/file"
|
"github.com/anchore/syft/syft/file"
|
||||||
"github.com/anchore/syft/syft/pkg"
|
"github.com/anchore/syft/syft/pkg"
|
||||||
@ -26,12 +27,22 @@ func parseRpmArchive(_ context.Context, _ file.Resolver, _ *generic.Environment,
|
|||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
licenses, _ := rpm.Header.GetStrings(rpmutils.LICENSE)
|
licenses, err := rpm.Header.GetStrings(rpmutils.LICENSE)
|
||||||
sourceRpm, _ := rpm.Header.GetString(rpmutils.SOURCERPM)
|
logRpmArchiveErr(reader.Location, "license", err)
|
||||||
vendor, _ := rpm.Header.GetString(rpmutils.VENDOR)
|
|
||||||
digestAlgorithm := getDigestAlgorithm(rpm.Header)
|
sourceRpm, err := rpm.Header.GetString(rpmutils.SOURCERPM)
|
||||||
size, _ := rpm.Header.InstalledSize()
|
logRpmArchiveErr(reader.Location, "sourcerpm", err)
|
||||||
files, _ := rpm.Header.GetFiles()
|
|
||||||
|
vendor, err := rpm.Header.GetString(rpmutils.VENDOR)
|
||||||
|
logRpmArchiveErr(reader.Location, "vendor", err)
|
||||||
|
|
||||||
|
digestAlgorithm := getDigestAlgorithm(reader.Location, rpm.Header)
|
||||||
|
|
||||||
|
size, err := rpm.Header.InstalledSize()
|
||||||
|
logRpmArchiveErr(reader.Location, "size", err)
|
||||||
|
|
||||||
|
files, err := rpm.Header.GetFiles()
|
||||||
|
logRpmArchiveErr(reader.Location, "files", err)
|
||||||
|
|
||||||
metadata := pkg.RpmArchive{
|
metadata := pkg.RpmArchive{
|
||||||
Name: nevra.Name,
|
Name: nevra.Name,
|
||||||
@ -48,12 +59,16 @@ func parseRpmArchive(_ context.Context, _ file.Resolver, _ *generic.Environment,
|
|||||||
return []pkg.Package{newArchivePackage(reader.Location, metadata, licenses)}, nil, nil
|
return []pkg.Package{newArchivePackage(reader.Location, metadata, licenses)}, nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getDigestAlgorithm(header *rpmutils.RpmHeader) string {
|
func getDigestAlgorithm(location file.Location, header *rpmutils.RpmHeader) string {
|
||||||
digestAlgorithm, _ := header.GetString(rpmutils.FILEDIGESTALGO)
|
digestAlgorithm, err := header.GetString(rpmutils.FILEDIGESTALGO)
|
||||||
|
logRpmArchiveErr(location, "file digest algo", err)
|
||||||
|
|
||||||
if digestAlgorithm != "" {
|
if digestAlgorithm != "" {
|
||||||
return digestAlgorithm
|
return digestAlgorithm
|
||||||
}
|
}
|
||||||
digestAlgorithms, _ := header.GetUint32s(rpmutils.FILEDIGESTALGO)
|
digestAlgorithms, err := header.GetUint32s(rpmutils.FILEDIGESTALGO)
|
||||||
|
logRpmArchiveErr(location, "file digest algo 32-bit", err)
|
||||||
|
|
||||||
if len(digestAlgorithms) > 0 {
|
if len(digestAlgorithms) > 0 {
|
||||||
digestAlgo := int(digestAlgorithms[0])
|
digestAlgo := int(digestAlgorithms[0])
|
||||||
return rpmutils.GetFileAlgoName(digestAlgo)
|
return rpmutils.GetFileAlgoName(digestAlgo)
|
||||||
@ -91,3 +106,9 @@ func parseEpoch(epoch string) *int {
|
|||||||
}
|
}
|
||||||
return &i
|
return &i
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func logRpmArchiveErr(location file.Location, operation string, err error) {
|
||||||
|
if err != nil {
|
||||||
|
log.Debugf("ERROR in parse_rpm_archive %s file: %s: %v", operation, location.RealPath, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user