mirror of
https://github.com/anchore/syft.git
synced 2026-11-03 16:06:36 +01:00
order locations by container layer order (#3858)
Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
This commit is contained in:
+27
-4
@@ -64,15 +64,38 @@ func (s *LicenseSet) Add(licenses ...License) {
|
||||
}
|
||||
}
|
||||
|
||||
func (s LicenseSet) ToSlice() []License {
|
||||
func (s LicenseSet) ToSlice(sorters ...func(a, b License) int) []License {
|
||||
licenses := s.ToUnorderedSlice()
|
||||
|
||||
var sorted bool
|
||||
for _, sorter := range sorters {
|
||||
if sorter == nil {
|
||||
continue
|
||||
}
|
||||
sort.Slice(licenses, func(i, j int) bool {
|
||||
return sorter(licenses[i], licenses[j]) < 0
|
||||
})
|
||||
sorted = true
|
||||
break
|
||||
}
|
||||
|
||||
if !sorted {
|
||||
sort.Sort(Licenses(licenses))
|
||||
}
|
||||
|
||||
return licenses
|
||||
}
|
||||
|
||||
func (s LicenseSet) ToUnorderedSlice() []License {
|
||||
if s.set == nil {
|
||||
return nil
|
||||
}
|
||||
var licenses []License
|
||||
licenses := make([]License, len(s.set))
|
||||
idx := 0
|
||||
for _, v := range s.set {
|
||||
licenses = append(licenses, v)
|
||||
licenses[idx] = v
|
||||
idx++
|
||||
}
|
||||
sort.Sort(Licenses(licenses))
|
||||
return licenses
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user