mirror of
https://github.com/anchore/syft.git
synced 2025-11-17 16:33:21 +01:00
Use cataloger Sorted() output instead of Enumerate() for stable result sorting in presenters. Fixes #331
Also adds artifact location to sort key for Sorted() to ensure consistent sorts when artifacts of same name, version, and type are found in different locations in the image. Location should be sufficient since we assume only one package of a given name and version can exist in one location, even if that location is an package-db like rpmdb. Signed-off-by: Zach Hill <zach@anchore.com>
This commit is contained in:
parent
485caa1ea3
commit
c332ba0867
@ -34,7 +34,7 @@ func NewCycloneDxDocument(catalog *pkg.Catalog, srcMetadata source.Metadata) Cyc
|
|||||||
}
|
}
|
||||||
|
|
||||||
// attach components
|
// attach components
|
||||||
for p := range catalog.Enumerate() {
|
for _, p := range catalog.Sorted() {
|
||||||
component := CycloneDxComponent{
|
component := CycloneDxComponent{
|
||||||
Type: "library", // TODO: this is not accurate
|
Type: "library", // TODO: this is not accurate
|
||||||
Name: p.Name,
|
Name: p.Name,
|
||||||
|
|||||||
@ -25,7 +25,7 @@ func (pres *TablePresenter) Present(output io.Writer) error {
|
|||||||
rows := make([][]string, 0)
|
rows := make([][]string, 0)
|
||||||
|
|
||||||
columns := []string{"Name", "Version", "Type"}
|
columns := []string{"Name", "Version", "Type"}
|
||||||
for p := range pres.catalog.Enumerate() {
|
for _, p := range pres.catalog.Sorted() {
|
||||||
row := []string{
|
row := []string{
|
||||||
p.Name,
|
p.Name,
|
||||||
p.Version,
|
p.Version,
|
||||||
|
|||||||
@ -164,6 +164,9 @@ func (c *Catalog) Sorted(types ...Type) []*Package {
|
|||||||
sort.SliceStable(pkgs, func(i, j int) bool {
|
sort.SliceStable(pkgs, func(i, j int) bool {
|
||||||
if pkgs[i].Name == pkgs[j].Name {
|
if pkgs[i].Name == pkgs[j].Name {
|
||||||
if pkgs[i].Version == pkgs[j].Version {
|
if pkgs[i].Version == pkgs[j].Version {
|
||||||
|
if pkgs[i].Type == pkgs[j].Type {
|
||||||
|
return pkgs[i].Locations[0].String() < pkgs[j].Locations[0].String()
|
||||||
|
}
|
||||||
return pkgs[i].Type < pkgs[j].Type
|
return pkgs[i].Type < pkgs[j].Type
|
||||||
}
|
}
|
||||||
return pkgs[i].Version < pkgs[j].Version
|
return pkgs[i].Version < pkgs[j].Version
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user