Skip to content

Commit 8cf1bf9

Browse files
aqua-bottofay
andauthored
fix(alma): parse epochs from rpmqa file [backport: release/v0.64] (#9119)
Co-authored-by: Tom Fay <[email protected]>
1 parent 280491b commit 8cf1bf9

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

pkg/fanal/analyzer/pkg/rpm/rpmqa.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"context"
66
"os"
77
"slices"
8+
"strconv"
89
"strings"
910

1011
"golang.org/x/xerrors"
@@ -50,6 +51,7 @@ func (a rpmqaPkgAnalyzer) parseRpmqaManifest(r xio.ReadSeekerAt) ([]types.Packag
5051
for scanner.Scan() {
5152
line := scanner.Text()
5253
var name, ver, rel, sourceRpm, arch string
54+
var epoch int
5355
// %{NAME}\t%{VERSION}-%{RELEASE}\t%{INSTALLTIME}\t%{BUILDTIME}\t%{VENDOR}\t(none)\t%{SIZE}\t%{ARCH}\t%{EPOCHNUM}\t%{SOURCERPM}
5456
s := strings.Split(line, "\t")
5557
if len(s) != 10 {
@@ -68,12 +70,18 @@ func (a rpmqaPkgAnalyzer) parseRpmqaManifest(r xio.ReadSeekerAt) ([]types.Packag
6870
if err != nil {
6971
return nil, xerrors.Errorf("failed to split source rpm: %w", err)
7072
}
73+
epoch, err = strconv.Atoi(s[8])
74+
if err != nil {
75+
return nil, xerrors.Errorf("failed to parse epoch number (%s): %w", s[8], err)
76+
}
7177
pkgs = append(pkgs, types.Package{
7278
Name: name,
7379
Version: ver,
80+
Epoch: epoch,
7481
Release: rel,
7582
Arch: arch,
7683
SrcName: srcName,
84+
SrcEpoch: epoch,
7785
SrcVersion: srcVer,
7886
SrcRelease: srcRel,
7987
})

pkg/fanal/analyzer/pkg/rpm/rpmqa_test.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ func TestParseMarinerDistrolessManifest(t *testing.T) {
2121
name: "happy path",
2222
content: `mariner-release 2.0-12.cm2 1653816591 1653753130 Microsoft Corporation (none) 580 noarch 0 mariner-release-2.0-12.cm2.src.rpm
2323
filesystem 1.1-9.cm2 1653816591 1653628924 Microsoft Corporation (none) 7596 x86_64 0 filesystem-1.1-9.cm2.src.rpm
24-
glibc 2.35-2.cm2 1653816591 1653628955 Microsoft Corporation (none) 10855265 x86_64 0 glibc-2.35-2.cm2.src.rpm`,
24+
glibc 2.35-2.cm2 1653816591 1653628955 Microsoft Corporation (none) 10855265 x86_64 0 glibc-2.35-2.cm2.src.rpm
25+
ca-certificates-base 3.0.0-8.azl3 1748892790 1735838940 Microsoft Corporation (none) 130628 noarch 1 ca-certificates-3.0.0-8.azl3.src.rpm`,
2526
wantPkgs: []types.Package{
2627
{
2728
Name: "mariner-release",
@@ -50,6 +51,17 @@ glibc 2.35-2.cm2 1653816591 1653628955 Microsoft Corporation (none) 10855265 x86
5051
SrcVersion: "2.35",
5152
SrcRelease: "2.cm2",
5253
},
54+
{
55+
Name: "ca-certificates-base",
56+
Version: "3.0.0",
57+
Epoch: 1,
58+
Release: "8.azl3",
59+
Arch: "noarch",
60+
SrcName: "ca-certificates",
61+
SrcEpoch: 1,
62+
SrcVersion: "3.0.0",
63+
SrcRelease: "8.azl3",
64+
},
5365
},
5466
},
5567
{

0 commit comments

Comments
 (0)