Skip to content

Commit 778cce8

Browse files
authored
✨ Use debian package list as evidence instead of its contents. (#5399)
* ✨ Use debian package list as evidence instead of its contents. Signed-off-by: Vasil Sirakov <sirakov97@gmail.com> * Check if dpkg list file exists before adding it as evidence of package. Signed-off-by: Vasil Sirakov <sirakov97@gmail.com> --------- Signed-off-by: Vasil Sirakov <sirakov97@gmail.com>
1 parent 635ad20 commit 778cce8

2 files changed

Lines changed: 8 additions & 25 deletions

File tree

providers/os/resources/packages/dpkg_packages.go

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -217,36 +217,20 @@ func (dpm *DebPkgManager) Available() (map[string]PackageUpdate, error) {
217217
func (dpm *DebPkgManager) Files(name string, version string, arch string) ([]FileRecord, error) {
218218
fs := dpm.conn.FileSystem()
219219

220-
files := []string{
220+
dpkgListFiles := []string{
221221
"/var/lib/dpkg/info/" + name + ".list",
222222
}
223+
223224
if arch != "" {
224-
files = append(files, "/var/lib/dpkg/info/"+name+":"+arch+".list")
225+
dpkgListFiles = append(dpkgListFiles, "/var/lib/dpkg/info/"+name+":"+arch+".list")
225226
}
226227

227228
fileRecords := []FileRecord{}
228-
for i := range files {
229-
file := files[i]
230-
_, err := fs.Stat(file)
231-
if err != nil {
229+
for _, file := range dpkgListFiles {
230+
if _, err := fs.Stat(file); err != nil {
232231
continue
233232
}
234-
235-
fi, err := fs.Open(file)
236-
if err != nil {
237-
return nil, err
238-
}
239-
defer fi.Close()
240-
241-
scanner := bufio.NewScanner(fi)
242-
for scanner.Scan() {
243-
line := scanner.Text()
244-
fileRecords = append(fileRecords, FileRecord{
245-
Path: line,
246-
})
247-
}
248-
// we only need the first file that exists
249-
break
233+
fileRecords = append(fileRecords, FileRecord{Path: file})
250234
}
251235

252236
return fileRecords, nil

providers/os/resources/packages/dpkg_packages_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,8 @@ It was originally inspired by the Multics SubSystem library.`,
116116
}
117117
pkgFiles, err := mgr.Files(p.Name, p.Version, p.Arch)
118118
require.NoError(t, err)
119-
assert.Equal(t, 11, len(pkgFiles), "detected the right amount of package files")
120-
assert.Contains(t, pkgFiles, FileRecord{Path: "/lib/aarch64-linux-gnu/libss.so.2.0"})
121-
assert.Contains(t, pkgFiles, FileRecord{Path: "/lib/aarch64-linux-gnu/libss.so.2"})
119+
assert.Equal(t, 1, len(pkgFiles), "detected the right amount of package files")
120+
assert.Contains(t, pkgFiles, FileRecord{Path: "/var/lib/dpkg/info/libss2:amd64.list"})
122121
}
123122

124123
func TestDpkgParserStatusD(t *testing.T) {

0 commit comments

Comments
 (0)