Skip to content

Commit 5b2b4ea

Browse files
AliDatadoglebauceknqyf263
authored
feat(report): Add InstalledFiles field to Package (#4706)
Co-authored-by: Sylvain Baubeau <[email protected]> Co-authored-by: knqyf263 <[email protected]>
1 parent cbbd1ce commit 5b2b4ea

File tree

9 files changed

+7372
-364
lines changed

9 files changed

+7372
-364
lines changed

integration/testdata/conda-spdx.json.golden

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
"dataLicense": "CC0-1.0",
44
"SPDXID": "SPDXRef-DOCUMENT",
55
"name": "testdata/fixtures/repo/conda",
6-
"documentNamespace": "http://aquasecurity.github.io/trivy/filesystem/testdata/fixtures/repo/conda-08df146c-0996-4718-8648-b2a45769ab79",
6+
"documentNamespace": "http://aquasecurity.github.io/trivy/filesystem/testdata/fixtures/repo/conda-3ff14136-e09f-4df9-80ea-000000000001",
77
"creationInfo": {
88
"licenseListVersion": "",
99
"creators": [
1010
"Organization: aquasecurity",
1111
"Tool: trivy-dev"
1212
],
13-
"created": "2023-06-27T05:37:40Z"
13+
"created": "2020-09-10T14:20:30Z"
1414
},
1515
"packages": [
1616
{
@@ -23,7 +23,7 @@
2323
},
2424
{
2525
"name": "openssl",
26-
"SPDXID": "SPDXRef-Package-950f99cb9edd281",
26+
"SPDXID": "SPDXRef-Package-c75d9dc75200186f",
2727
"versionInfo": "1.1.1q",
2828
"supplier": "NOASSERTION",
2929
"downloadLocation": "NONE",
@@ -41,7 +41,7 @@
4141
},
4242
{
4343
"name": "pip",
44-
"SPDXID": "SPDXRef-Package-39020c06af94ca53",
44+
"SPDXID": "SPDXRef-Package-195557cddf18e4a9",
4545
"versionInfo": "22.2.2",
4646
"supplier": "NOASSERTION",
4747
"downloadLocation": "NONE",
@@ -105,21 +105,21 @@
105105
},
106106
{
107107
"spdxElementId": "SPDXRef-Application-ee5ef1aa4ac89125",
108-
"relatedSpdxElement": "SPDXRef-Package-950f99cb9edd281",
108+
"relatedSpdxElement": "SPDXRef-Package-c75d9dc75200186f",
109109
"relationshipType": "CONTAINS"
110110
},
111111
{
112-
"spdxElementId": "SPDXRef-Package-950f99cb9edd281",
112+
"spdxElementId": "SPDXRef-Package-c75d9dc75200186f",
113113
"relatedSpdxElement": "SPDXRef-File-600e5e0110a84891",
114114
"relationshipType": "CONTAINS"
115115
},
116116
{
117117
"spdxElementId": "SPDXRef-Application-ee5ef1aa4ac89125",
118-
"relatedSpdxElement": "SPDXRef-Package-39020c06af94ca53",
118+
"relatedSpdxElement": "SPDXRef-Package-195557cddf18e4a9",
119119
"relationshipType": "CONTAINS"
120120
},
121121
{
122-
"spdxElementId": "SPDXRef-Package-39020c06af94ca53",
122+
"spdxElementId": "SPDXRef-Package-195557cddf18e4a9",
123123
"relatedSpdxElement": "SPDXRef-File-7eb62e2a3edddc0a",
124124
"relationshipType": "CONTAINS"
125125
}

pkg/fanal/analyzer/analyzer_test.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -335,14 +335,15 @@ func TestAnalyzerGroup_AnalyzeFile(t *testing.T) {
335335
FilePath: "/lib/apk/db/installed",
336336
Packages: types.Packages{
337337
{
338-
339-
Name: "musl",
340-
Version: "1.1.24-r2",
341-
SrcName: "musl",
342-
SrcVersion: "1.1.24-r2",
343-
Licenses: []string{"MIT"},
344-
Arch: "x86_64",
345-
Digest: "sha1:cb2316a189ebee5282c4a9bd98794cc2477a74c6",
338+
339+
Name: "musl",
340+
Version: "1.1.24-r2",
341+
SrcName: "musl",
342+
SrcVersion: "1.1.24-r2",
343+
Licenses: []string{"MIT"},
344+
Arch: "x86_64",
345+
Digest: "sha1:cb2316a189ebee5282c4a9bd98794cc2477a74c6",
346+
InstalledFiles: []string{"lib/libc.musl-x86_64.so.1", "lib/ld-musl-x86_64.so.1"},
346347
},
347348
},
348349
},

pkg/fanal/analyzer/pkg/apk/apk.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,9 @@ func (a alpinePkgAnalyzer) parseApkInfo(scanner *bufio.Scanner) ([]types.Package
8989
case "F:":
9090
dir = line[2:]
9191
case "R:":
92-
installedFiles = append(installedFiles, path.Join(dir, line[2:]))
92+
absPath := path.Join(dir, line[2:])
93+
pkg.InstalledFiles = append(pkg.InstalledFiles, absPath)
94+
installedFiles = append(installedFiles, absPath)
9395
case "p:": // provides (corresponds to provides in PKGINFO, concatenated by spaces into a single line)
9496
a.parseProvides(line, pkg.ID, provides)
9597
case "D:": // dependencies (corresponds to depend in PKGINFO, concatenated by spaces into a single line)

0 commit comments

Comments
 (0)