From 72735dd11c83eb59d90e04b3c1e580af43b1ba0a Mon Sep 17 00:00:00 2001 From: Pino Toscano Date: Fri, 12 Apr 2019 12:38:46 +0200 Subject: [PATCH 08/12] 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. --- src/ph_rpm.ml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/ph_rpm.ml b/src/ph_rpm.ml index e27d226..dbe3bda 100644 --- a/src/ph_rpm.ml +++ b/src/ph_rpm.ml @@ -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) -- 2.23.0