@@ -3,7 +3,6 @@ package rpmutils
33import (
44 "fmt"
55 "net/url"
6- "path/filepath"
76 "sort"
87 "strings"
98 "unicode"
@@ -222,8 +221,19 @@ func extractBasePackageNameFromFile(fullName string) string {
222221 // Find the first part that looks like a version (starts with digit)
223222 for i := 1 ; i < len (parts ); i ++ {
224223 if len (parts [i ]) > 0 && (parts [i ][0 ] >= '0' && parts [i ][0 ] <= '9' ) {
225- // Everything before this index is the package name
226- return strings .Join (parts [:i ], "-" )
224+ // get the name
225+ maybe_name := strings .Join (parts [:i ], "-" )
226+ // check if version is part of the name
227+ // full name contains version, if package name has version,
228+ // it will be repeated in the full name
229+ for j := i + 1 ; j < len (parts ); j ++ {
230+ if len (parts [j ]) > 0 && strings .Contains (parts [j ], parts [i ]) {
231+ maybe_name = strings .Join (parts [:j ], "-" )
232+ break
233+ }
234+ }
235+ // return name or name-version
236+ return maybe_name
227237 }
228238 }
229239
@@ -295,15 +305,10 @@ func findAllCandidates(parent ospackage.PackageInfo, depName string, all []ospac
295305}
296306
297307// ResolvePackage finds the best matching package for a given package name
298- func ResolveTopPackageConflicts (want , pkgType string , all []ospackage.PackageInfo ) (ospackage.PackageInfo , bool ) {
308+ func ResolveTopPackageConflicts (want string , all []ospackage.PackageInfo ) (ospackage.PackageInfo , bool ) {
299309 var candidates []ospackage.PackageInfo
300310 for _ , pi := range all {
301- // 1) exact name and version matched with .deb filenamae, e.g. acct_7.6.4-5+b1_amd64
302- if filepath .Base (pi .URL ) == want + "." + pkgType {
303- candidates = append (candidates , pi )
304- break
305- }
306- // 2) exact name, e.g. acct-205-25.azl3.noarch.rpm
311+ // 1) exact name, e.g. acct-205-25.azl3.noarch.rpm
307312 if pi .Name == want {
308313 candidates = append (candidates , pi )
309314 break
@@ -314,28 +319,27 @@ func ResolveTopPackageConflicts(want, pkgType string, all []ospackage.PackageInf
314319 candidates = append (candidates , pi )
315320 continue
316321 }
317- // // 3) prefix by want-version ("acl-")
318- // if strings.HasPrefix(pi.Name, want+"-") {
319- // candidates = append(candidates, pi)
320- // continue
321- // }
322- // // 4) prefix by want.release ("acl-2.3.1-2.")
323- // if strings.HasPrefix(cleanName, want+".") {
324- // candidates = append(candidates, pi)
325- // continue
326- // }
327- // // 5) Debian package format (packagename_version_arch.deb)
328- // if strings.HasPrefix(cleanName, want+"_") {
329- // candidates = append(candidates, pi)
330- // }
322+ // 3) prefix by want-version ("acl-")
323+ // expected pi.Name should look like openvino-2025.3.0-2025.3.0.19807-1.noarch.rpm
324+ // want = openvino-2025.3.0
325+ if strings .HasPrefix (pi .Name , want ) {
326+ // Extract string after "-" and compare with pi.Version
327+ if dashIdx := strings .LastIndex (want , "-" ); dashIdx != - 1 {
328+ verStr := want [dashIdx + 1 :]
329+ if strings .Contains (pi .Version , verStr ) {
330+ candidates = append (candidates , pi )
331+ continue
332+ }
333+ }
334+ }
331335 }
332336
333337 if len (candidates ) == 0 {
334338 return ospackage.PackageInfo {}, false
335339 }
336340
337341 // If we got an exact match in step (1), it's the only candidate
338- if len (candidates ) == 1 && (candidates [0 ].Name == want || candidates [0 ].Name == want + "." + pkgType ) {
342+ if len (candidates ) == 1 && (candidates [0 ].Name == want || extractBasePackageNameFromFile ( candidates [0 ].Name ) == want ) {
339343 return candidates [0 ], true
340344 }
341345
0 commit comments