Browse code

Stop filtering Windows manifest lists by version

Signed-off-by: John Stephens <johnstep@docker.com>

John Stephens authored on 2017/10/07 14:19:06
Showing 1 changed files
... ...
@@ -65,52 +65,47 @@ func (ld *v2LayerDescriptor) open(ctx context.Context) (distribution.ReadSeekClo
65 65
 func filterManifests(manifests []manifestlist.ManifestDescriptor, os string) []manifestlist.ManifestDescriptor {
66 66
 	osVersion := ""
67 67
 	if os == "windows" {
68
+		// TODO: Add UBR (Update Build Release) component after build
68 69
 		version := system.GetOSVersion()
69 70
 		osVersion = fmt.Sprintf("%d.%d.%d", version.MajorVersion, version.MinorVersion, version.Build)
70
-		logrus.Debugf("will only match entries with version %s", osVersion)
71
+		logrus.Debugf("will prefer entries with version %s", osVersion)
71 72
 	}
72 73
 
73 74
 	var matches []manifestlist.ManifestDescriptor
74 75
 	for _, manifestDescriptor := range manifests {
76
+		// TODO: Consider filtering out greater versions, including only greater UBR
75 77
 		if manifestDescriptor.Platform.Architecture == runtime.GOARCH && manifestDescriptor.Platform.OS == os {
76
-			if os == "windows" && !versionMatch(manifestDescriptor.Platform.OSVersion, osVersion) {
77
-				logrus.Debugf("skipping %s", manifestDescriptor.Platform.OSVersion)
78
-				continue
79
-			}
80 78
 			matches = append(matches, manifestDescriptor)
81 79
 			logrus.Debugf("found match for %s/%s with media type %s, digest %s", os, runtime.GOARCH, manifestDescriptor.MediaType, manifestDescriptor.Digest.String())
82 80
 		}
83 81
 	}
84 82
 	if os == "windows" {
85
-		sort.Stable(manifestsByVersion(matches))
83
+		sort.Stable(manifestsByVersion{osVersion, matches})
86 84
 	}
87 85
 	return matches
88 86
 }
89 87
 
90 88
 func versionMatch(actual, expected string) bool {
91
-	// Check whether actual and expected are equivalent, or whether
92
-	// expected is a version prefix of actual.
93
-	return actual == "" || expected == "" || actual == expected || strings.HasPrefix(actual, expected+".")
89
+	// Check whether the version matches up to the build, ignoring UBR
90
+	return strings.HasPrefix(actual, expected+".")
94 91
 }
95 92
 
96
-type manifestsByVersion []manifestlist.ManifestDescriptor
93
+type manifestsByVersion struct {
94
+	version string
95
+	list    []manifestlist.ManifestDescriptor
96
+}
97 97
 
98 98
 func (mbv manifestsByVersion) Less(i, j int) bool {
99
-	if mbv[i].Platform.OSVersion == "" {
100
-		return false
101
-	}
102
-	if mbv[j].Platform.OSVersion == "" {
103
-		return true
104
-	}
105 99
 	// TODO: Split version by parts and compare
106 100
 	// TODO: Prefer versions which have a greater version number
107
-	return false
101
+	// Move compatible versions to the top, with no other ordering changes
102
+	return versionMatch(mbv.list[i].Platform.OSVersion, mbv.version) && !versionMatch(mbv.list[j].Platform.OSVersion, mbv.version)
108 103
 }
109 104
 
110 105
 func (mbv manifestsByVersion) Len() int {
111
-	return len(mbv)
106
+	return len(mbv.list)
112 107
 }
113 108
 
114 109
 func (mbv manifestsByVersion) Swap(i, j int) {
115
-	mbv[i], mbv[j] = mbv[j], mbv[i]
110
+	mbv.list[i], mbv.list[j] = mbv.list[j], mbv.list[i]
116 111
 }