@@ -199,24 +199,36 @@ images:
199
199
func InstNameFromImageURL (locator , imageArch string ) string {
200
200
// We intentionally call both path.Base and filepath.Base in case we are running on Windows.
201
201
name := strings .ToLower (filepath .Base (path .Base (locator )))
202
- // Remove file format and compression file types
202
+ // Remove file format and compression file types.
203
203
name = imageURLRegex .ReplaceAllString (name , "" )
204
- // The Alpine "nocloud_" prefix does not fit the genericTags pattern
204
+ // The Alpine "nocloud_" prefix does not fit the genericTags pattern.
205
205
name = strings .TrimPrefix (name , "nocloud_" )
206
206
for _ , tag := range genericTags {
207
207
re := regexp .MustCompile (fmt .Sprintf (`[-_.]%s\b` , tag ))
208
208
name = re .ReplaceAllString (name , "" )
209
209
}
210
- // Remove imageArch as well if it is the native arch
210
+ // Remove imageArch as well if it is the native arch.
211
211
if limayaml .IsNativeArch (imageArch ) {
212
212
re := regexp .MustCompile (fmt .Sprintf (`[-_.]%s\b` , imageArch ))
213
213
name = re .ReplaceAllString (name , "" )
214
214
}
215
215
// Remove timestamps from name: 8 digit date, optionally followed by
216
- // a delimiter and one or more digits before a word boundary
216
+ // a delimiter and one or more digits before a word boundary.
217
217
name = regexp .MustCompile (`[-_.]20\d{6}([-_.]\d+)?\b` ).ReplaceAllString (name , "" )
218
218
// Normalize archlinux name
219
219
name = regexp .MustCompile (`^arch\b` ).ReplaceAllString (name , "archlinux" )
220
+ // Remove redundant major version, e.g. "rocky-8-8.10" becomes "rocky-8.10".
221
+ // Unfortunately regexp doesn't support back references, so we have to
222
+ // check manually if both numbers are the same.
223
+ re := regexp .MustCompile (`-(\d+)-(\d+)\.` )
224
+ name = re .ReplaceAllStringFunc (name , func (match string ) string {
225
+ submatch := re .FindStringSubmatch (match )
226
+ if submatch [1 ] == submatch [2 ] {
227
+ // Replace -X-X. with -X.
228
+ return "-" + submatch [1 ] + "."
229
+ }
230
+ return match
231
+ })
220
232
return name
221
233
}
222
234
0 commit comments