Browse code

distribution: remove custom matcher code

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>

Tonis Tiigi authored on 2018/06/28 07:21:16
Showing 1 changed files
... ...
@@ -18,10 +18,11 @@ func (ld *v2LayerDescriptor) open(ctx context.Context) (distribution.ReadSeekClo
18 18
 }
19 19
 
20 20
 func filterManifests(manifests []manifestlist.ManifestDescriptor, p specs.Platform) []manifestlist.ManifestDescriptor {
21
-	p = withDefault(p)
21
+	p = platforms.Normalize(withDefault(p))
22
+	m := platforms.NewMatcher(p)
22 23
 	var matches []manifestlist.ManifestDescriptor
23 24
 	for _, desc := range manifests {
24
-		if compareNormalized(toOCIPlatform(desc.Platform), p) {
25
+		if m.Match(toOCIPlatform(desc.Platform)) {
25 26
 			matches = append(matches, desc)
26 27
 			logrus.Debugf("found match for %s with media type %s, digest %s", platforms.Format(p), desc.MediaType, desc.Digest.String())
27 28
 		}
... ...
@@ -29,7 +30,7 @@ func filterManifests(manifests []manifestlist.ManifestDescriptor, p specs.Platfo
29 29
 
30 30
 	// deprecated: backwards compatibility with older versions that didn't compare variant
31 31
 	if len(matches) == 0 && p.Architecture == "arm" {
32
-		p = normalize(p)
32
+		p = platforms.Normalize(p)
33 33
 		for _, desc := range manifests {
34 34
 			if desc.Platform.OS == p.OS && desc.Platform.Architecture == p.Architecture {
35 35
 				matches = append(matches, desc)
... ...
@@ -57,26 +58,3 @@ func withDefault(p specs.Platform) specs.Platform {
57 57
 	}
58 58
 	return p
59 59
 }
60
-
61
-func compareNormalized(p1, p2 specs.Platform) bool {
62
-	// remove after https://github.com/containerd/containerd/pull/2414
63
-	return p1.OS == p2.OS &&
64
-		p1.Architecture == p2.Architecture &&
65
-		p1.Variant == p2.Variant
66
-}
67
-
68
-func normalize(p specs.Platform) specs.Platform {
69
-	p = platforms.Normalize(p)
70
-	// remove after https://github.com/containerd/containerd/pull/2414
71
-	if p.Architecture == "arm" {
72
-		if p.Variant == "" {
73
-			p.Variant = "v7"
74
-		}
75
-	}
76
-	if p.Architecture == "arm64" {
77
-		if p.Variant == "" {
78
-			p.Variant = "v8"
79
-		}
80
-	}
81
-	return p
82
-}