Skip to content

Commit f14c7e4

Browse files
committed
✨ Use rpm database path as evidence instead of files contained in the rpm
This alignes the rpm packages with dpkg and Windows: #5399 #5770 Signed-off-by: Christian Zunker <christian@mondoo.com>
1 parent 4a5a0aa commit f14c7e4

File tree

3 files changed

+14
-30
lines changed

3 files changed

+14
-30
lines changed

providers/os/resources/packages/rpm_packages.go

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -297,30 +297,12 @@ func (rpm *RpmPkgManager) staticList() ([]Package, error) {
297297

298298
rpmPkg := newRpmPackage(rpm.platform, pkg.Name, version, pkg.Arch, epoch, cleanupVendorName(pkg.Vendor), pkg.Summary)
299299

300-
// determine all files attached
301-
records := []FileRecord{}
302-
files, err := pkg.InstalledFiles()
303-
if err == nil {
304-
for _, record := range files {
305-
records = append(records, FileRecord{
306-
Path: record.Path,
307-
Digest: PkgDigest{
308-
Value: record.Digest,
309-
Algorithm: pkg.DigestAlgorithm.String(),
310-
},
311-
FileInfo: PkgFileInfo{
312-
Mode: record.Mode,
313-
Flags: int32(record.Flags),
314-
Owner: record.Username,
315-
Group: record.Groupname,
316-
Size: int64(record.Size),
317-
},
318-
})
319-
}
320-
}
321-
322300
rpmPkg.FilesAvailable = PkgFilesIncluded
323-
rpmPkg.Files = records
301+
rpmPkg.Files = []FileRecord{
302+
{
303+
Path: detectedPath,
304+
},
305+
}
324306
resultList = append(resultList, rpmPkg)
325307
}
326308

@@ -338,10 +320,10 @@ func (rpm *RpmPkgManager) Files(name string, version string, arch string) ([]Fil
338320
// nothing to do since the data is already attached to the package
339321
return nil, nil
340322
} else {
341-
// we need to fetch the files from the running system
342-
cmd, err := rpm.conn.RunCommand("rpm -ql " + name)
323+
// This returns the path to the RPM database
324+
cmd, err := rpm.conn.RunCommand("rpm -E '%{_dbpath}'")
343325
if err != nil {
344-
return nil, errors.Wrap(err, "could not read package files")
326+
return nil, errors.Wrap(err, "could not rpm database path")
345327
}
346328
fileRecords := []FileRecord{}
347329
scanner := bufio.NewScanner(cmd.Stdout)

providers/os/resources/packages/rpm_packages_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,8 @@ func TestRedhat8Parser(t *testing.T) {
191191
}
192192
pkgFiles, err := mgr.Files(p.Name, p.Version, p.Arch)
193193
require.NoError(t, err)
194-
assert.Equal(t, 15, len(pkgFiles), "detected the right amount of package files")
195-
assert.Contains(t, pkgFiles, FileRecord{Path: "/usr/share/doc/which"})
196-
assert.Contains(t, pkgFiles, FileRecord{Path: "/usr/share/info/which.info.gz"})
194+
assert.Equal(t, 1, len(pkgFiles), "detected the right amount of package files")
195+
assert.Contains(t, pkgFiles, FileRecord{Path: "/var/lib/rpm/rpmdb.sqlite"})
197196
}
198197

199198
func TestPhoton4ImageParser(t *testing.T) {

providers/os/resources/packages/testdata/packages_redhat8.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
[commands."command -v rpm"]
22
stdout="/usr/bin/rpm"
33

4+
[commands."rpm -E '%{_dbpath}'"]
5+
stdout="/var/lib/rpm/rpmdb.sqlite"
6+
47
[commands."rpm -qa --queryformat '%{NAME} %{EPOCHNUM}:%{VERSION}-%{RELEASE} %{ARCH}__%{VENDOR}__%{SUMMARY}\\n'"]
58
stdout="""
69
tzdata 0:2021c-1.el8 noarch__Red Hat, Inc.__Timezone data
@@ -214,4 +217,4 @@ stdout="""
214217
/usr/share/licenses/which
215218
/usr/share/licenses/which/COPYING
216219
/usr/share/man/man1/which.1.gz
217-
"""
220+
"""

0 commit comments

Comments
 (0)