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
No known key found for this signature in database
GPG Key ID: 5CB45AE22BAB7EA7

View File

@ -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
}