stabilize json file metadata presenter order

Signed-off-by: Alex Goodman <alex.goodman@anchore.com>
This commit is contained in:
Alex Goodman
2021-03-23 11:00:36 -04:00
parent 0e9c1c1d86
commit 40199096e9
@@ -2,6 +2,7 @@ package poweruser
import ( import (
"fmt" "fmt"
"sort"
"strconv" "strconv"
"github.com/anchore/syft/syft/file" "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 return results, nil
} }