summaryrefslogtreecommitdiff
path: root/pkg/platforms/platforms.go
blob: e232b4ddb2a1661cd7ca0a512b3e48a3227fce0f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
package platforms

import (
	cplatforms "github.com/containerd/containerd/platforms"
	ocispec "github.com/opencontainers/image-spec/specs-go/v1"
)

type allPlatformsWithPreferenceMatcher struct {
	preferred cplatforms.MatchComparer
}

// AllPlatformsWithPreference will return a platform matcher that matches all
// platforms but will order platforms matching the preferred matcher first.
func AllPlatformsWithPreference(preferred cplatforms.MatchComparer) cplatforms.MatchComparer {
	return allPlatformsWithPreferenceMatcher{
		preferred: preferred,
	}
}

func (c allPlatformsWithPreferenceMatcher) Match(_ ocispec.Platform) bool {
	return true
}

func (c allPlatformsWithPreferenceMatcher) Less(p1, p2 ocispec.Platform) bool {
	return c.preferred.Less(p1, p2)
}