-
Notifications
You must be signed in to change notification settings - Fork 526
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: C0D3 M4513R <28912031+C0D3-M4513R@users.noreply.github.com>
- Loading branch information
1 parent
5b31935
commit ff260d0
Showing
28 changed files
with
497 additions
and
288 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,16 @@ | ||
package relationship | ||
|
||
import ( | ||
"sort" | ||
|
||
"github.com/anchore/syft/syft/artifact" | ||
"github.com/anchore/syft/syft/pkg" | ||
"github.com/anchore/syft/syft/sort" | ||
"slices" | ||
) | ||
|
||
// Sort takes a set of package-to-package relationships and sorts them in a stable order by name and version. | ||
// Note: this does not consider package-to-other, other-to-package, or other-to-other relationships. | ||
// TODO: ideally this should be replaced with a more type-agnostic sort function that resides in the artifact package. | ||
func Sort(rels []artifact.Relationship) { | ||
sort.SliceStable(rels, func(i, j int) bool { | ||
return less(rels[i], rels[j]) | ||
slices.SortStableFunc(rels, func(i, j artifact.Relationship) int { | ||
return sort.Compare(i, j) | ||
}) | ||
} | ||
|
||
func less(i, j artifact.Relationship) bool { | ||
iFrom, ok1 := i.From.(pkg.Package) | ||
iTo, ok2 := i.To.(pkg.Package) | ||
jFrom, ok3 := j.From.(pkg.Package) | ||
jTo, ok4 := j.To.(pkg.Package) | ||
|
||
if !(ok1 && ok2 && ok3 && ok4) { | ||
return false | ||
} | ||
|
||
if iFrom.Name != jFrom.Name { | ||
return iFrom.Name < jFrom.Name | ||
} | ||
if iFrom.Version != jFrom.Version { | ||
return iFrom.Version < jFrom.Version | ||
} | ||
if iTo.Name != jTo.Name { | ||
return iTo.Name < jTo.Name | ||
} | ||
if iTo.Version != jTo.Version { | ||
return iTo.Version < jTo.Version | ||
} | ||
return i.Type < j.Type | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.