@@ -261,58 +261,43 @@ func extractBasePackageNameFromFile(fullName string) string {
261261 return name
262262 }
263263
264- // First, try to find dist/arch markers and work backwards
265- // This handles the <name>-<version>-<release>.<dist>.<arch> format
264+ // First, check if this is a full RPM filename format by looking for architecture markers
265+ // This allows us to use different strategies for full filenames vs simplified names
266+ hasArchMarker := false
267+ archMarkerIndex := - 1
266268 for i := len (parts ) - 1 ; i >= 0 ; i -- {
267269 part := parts [i ]
268-
269- // Check if this part contains a known architecture
270- // Split by '.' and check if the last segment is a known arch
271270 dotParts := strings .Split (part , "." )
272271 if len (dotParts ) > 1 {
273272 lastSegment := dotParts [len (dotParts )- 1 ]
274273 if knownRPMArches [lastSegment ] {
275- // This is the release part with arch. Work backwards to find where version starts
276- for j := i - 1 ; j >= 1 ; j -- {
277- if len (parts [j ]) > 0 && (parts [j ][0 ] >= '0' && parts [j ][0 ] <= '9' ) {
278- // This is likely the start of the version
279- return strings .Join (parts [:j ], "-" )
280- }
281- }
274+ hasArchMarker = true
275+ archMarkerIndex = i
276+ break
282277 }
283278 }
279+ }
284280
285- // Check if this part contains a dist marker
286- if isDistMarker ( part ) {
287- // This is the release part with dist marker. Work backwards to find where version starts
288- for j := i - 1 ; j >= 1 ; j -- {
289- if len ( parts [ j ]) > 0 && ( parts [ j ][ 0 ] >= '0' && parts [ j ][ 0 ] <= '9' ) {
290- // This is likely the start of the version
291- return strings . Join ( parts [: j ], "-" )
292- }
281+ // If we have a full RPM filename with architecture marker, use backward search from arch
282+ if hasArchMarker {
283+ // Work backwards from the arch marker to find where version starts
284+ // Prefer parts with dots (more likely to be version) over plain numbers
285+ for j := archMarkerIndex - 1 ; j >= 1 ; j -- {
286+ if len ( parts [ j ]) > 0 && ( parts [ j ][ 0 ] >= '0' && parts [ j ][ 0 ] <= '9' ) && strings . Contains ( parts [ j ], "." ) {
287+ // This looks like a version part (starts with digit and contains dot )
288+ return strings . Join ( parts [: j ], "-" )
293289 }
294290 }
295- }
296-
297- // Fallback: Find the first part that looks like a version (starts with digit and contains dot+digit)
298- // This handles simple cases where there's no clear dist marker
299- // Requires digit-dot-digit pattern to avoid matching release+arch like "1.ppc64le" or "1.s390x"
300- for i := 1 ; i < len (parts ); i ++ {
301- part := parts [i ]
302- if len (part ) > 0 && (part [0 ] >= '0' && part [0 ] <= '9' ) {
303- // Check if it matches version pattern (e.g., "8.8.0", "10.42") with digit after dot
304- dotIdx := strings .Index (part , "." )
305- if dotIdx > 0 && dotIdx < len (part )- 1 {
306- // Check if character after dot is a digit (to avoid "1.ppc64le")
307- if part [dotIdx + 1 ] >= '0' && part [dotIdx + 1 ] <= '9' {
308- // This looks like a version (e.g., "8.8.0")
309- return strings .Join (parts [:i ], "-" )
310- }
291+ // If no dotted version found, take first digit-starting part
292+ for j := archMarkerIndex - 1 ; j >= 1 ; j -- {
293+ if len (parts [j ]) > 0 && (parts [j ][0 ] >= '0' && parts [j ][0 ] <= '9' ) {
294+ return strings .Join (parts [:j ], "-" )
311295 }
312296 }
313297 }
314298
315- // Second fallback: Find first numeric part
299+ // No architecture marker found - use simpler forward search (for test cases and simplified names)
300+ // Find the first part that looks like a version (starts with digit)
316301 for i := 1 ; i < len (parts ); i ++ {
317302 if len (parts [i ]) > 0 && (parts [i ][0 ] >= '0' && parts [i ][0 ] <= '9' ) {
318303 return strings .Join (parts [:i ], "-" )
0 commit comments