From 40199096e9d3c670057fd098ee26d7d11f983b66 Mon Sep 17 00:00:00 2001 From: Alex Goodman Date: Tue, 23 Mar 2021 11:00:36 -0400 Subject: [PATCH] stabilize json file metadata presenter order Signed-off-by: Alex Goodman --- internal/presenter/poweruser/json_file_metadata.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/internal/presenter/poweruser/json_file_metadata.go b/internal/presenter/poweruser/json_file_metadata.go index 368525a91..1b0a8d08e 100644 --- a/internal/presenter/poweruser/json_file_metadata.go +++ b/internal/presenter/poweruser/json_file_metadata.go @@ -2,6 +2,7 @@ package poweruser import ( "fmt" + "sort" "strconv" "github.com/anchore/syft/syft/file" @@ -46,5 +47,13 @@ func NewJSONFileMetadata(data map[source.Location]source.FileMetadata, digests m }, }) } + + // sort by real path then virtual path to ensure the result is stable across multiple runs + sort.SliceStable(results, func(i, j int) bool { + if results[i].Location.RealPath != results[j].Location.RealPath { + return results[i].Location.VirtualPath < results[j].Location.VirtualPath + } + return false + }) return results, nil }