clarify default collection value + fix appending conffiles location

Signed-off-by: Alex Goodman <alex.goodman@anchore.com>
This commit is contained in:
Alex Goodman 2021-04-09 11:41:44 -04:00
parent c56690fc52
commit 0511972dfa
No known key found for this signature in database
GPG Key ID: 5CB45AE22BAB7EA7
2 changed files with 6 additions and 8 deletions

View File

@ -117,7 +117,7 @@ loopNewFiles:
} }
func getAdditionalFileListing(resolver source.FileResolver, dbLocation source.Location, p *pkg.Package) ([]pkg.DpkgFileRecord, []source.Location) { func getAdditionalFileListing(resolver source.FileResolver, dbLocation source.Location, p *pkg.Package) ([]pkg.DpkgFileRecord, []source.Location) {
// ensure the file list is an empty collection (not nil) // ensure the default value for a collection is never nil since this may be shown as JSON
var files = make([]pkg.DpkgFileRecord, 0) var files = make([]pkg.DpkgFileRecord, 0)
var locations []source.Location var locations []source.Location
@ -140,7 +140,7 @@ func getAdditionalFileListing(resolver source.FileResolver, dbLocation source.Lo
files = append(files, parseDpkgConffileInfo(md5Reader)...) files = append(files, parseDpkgConffileInfo(md5Reader)...)
// keep a record of the file where this was discovered // keep a record of the file where this was discovered
if md5Location != nil { if conffilesLocation != nil {
locations = append(locations, *conffilesLocation) locations = append(locations, *conffilesLocation)
} }
} }

View File

@ -61,7 +61,10 @@ func parseDpkgStatusEntry(reader *bufio.Reader) (pkg.DpkgMetadata, error) {
retErr = err retErr = err
} }
var entry pkg.DpkgMetadata entry := pkg.DpkgMetadata{
// ensure the default value for a collection is never nil since this may be shown as JSON
Files: make([]pkg.DpkgFileRecord, 0),
}
err = mapstructure.Decode(dpkgFields, &entry) err = mapstructure.Decode(dpkgFields, &entry)
if err != nil { if err != nil {
return pkg.DpkgMetadata{}, err return pkg.DpkgMetadata{}, err
@ -80,11 +83,6 @@ func parseDpkgStatusEntry(reader *bufio.Reader) (pkg.DpkgMetadata, error) {
} }
} }
if entry.Files == nil {
// ensure that the collection is always allocated
entry.Files = make([]pkg.DpkgFileRecord, 0)
}
return entry, retErr return entry, retErr
} }