Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
rpm: fix package sorting (RHBZ#1696822)
The sorting algorithm for RPMs sorted this way:
- before the packages with the higher versions
- among the packages with the version version, first noarch packages,
  then 64bit packages, and then 32bit packages
This was broken in at least two ways:
- the higher installed version may not be of the same host architecture
- if the host architecture is 32bit, and there is a 64bit package of a
  32bit installed one, the 64bit version was preferred

Instead:
- first sort by architecture, preferring noarch packages, and
  packages of the host architecture
- then sort by version

This way, the higher version of the host architecture is preferred,
otherwise the higher version of any foreign architecture is chosen.
  • Loading branch information
ptoscano committed Apr 12, 2019
1 parent e57e988 commit 72735dd
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/ph_rpm.ml
Expand Up @@ -172,9 +172,14 @@ let rpm_package_of_string str =
* architecture.
*)
let cmp (pkg1, evr1) (pkg2, evr2) =
let i = rpm_vercmp evr2 evr2 in
let weight_of_arch = function
| "noarch" -> 100
| a when a = !rpm_arch -> 50
| _ -> 0
in
let i = compare (weight_of_arch pkg2.arch) (weight_of_arch pkg1.arch) in
if i <> 0 then i
else compare_architecture pkg2.arch pkg1.arch
else rpm_vercmp evr2 evr2
in
let rpms = List.sort cmp rpms in
fst (List.hd rpms)
Expand Down

0 comments on commit 72735dd

Please sign in to comment.