amprolla

devuan's apt repo merger
git clone git://parazyd.org/amprolla.git
Log | Files | Refs | README | LICENSE

commit 5a2e7d0f6ababbcdcfdd8fd31f474618ae72665b
parent e61dd7086ea88097c36143c4ee37e37ffb83ede0
Author: parazyd <parazyd@dyne.org>
Date:   Sat, 16 Dec 2017 23:52:16 +0100

Implement new algorithm for package_newer().

This patch should bring more robustness to package version detection and
avoid false positives and false negatives that have been appearing.

Diffstat:
Mlib/package.py | 34+++++++++++++++++++++++++++++-----
1 file changed, 29 insertions(+), 5 deletions(-)

diff --git a/lib/package.py b/lib/package.py @@ -106,15 +106,39 @@ def package_banned(pkg, banned_pkgs): def package_newer(pkg1, pkg2): """ - Checks whether the package of a lower priority is newer than the package - of the higher priority and returns True if so. + Checks whether the package of a lower priority has a higher version than + the package of the higher priority and returns True if so. + + Ref: https://www.debian.org/doc/debian-policy/#version """ - higher_prio = pkg1.get('Version').split('+') - lower_prio = pkg2.get('Version').split('+') + # The choice of dropping [1:] is because we don't care for +deb or +devuan + hi_prio = pkg1.get('Version').split('+')[0] + lo_prio = pkg2.get('Version').split('+')[0] + + # Epoch check + hi_ep = 0 + lo_ep = 0 + if ':' in hi_prio: + hi_ep = int(hi_prio.split(':')[0]) + hi_prio = hi_prio.split(':')[1] + if ':' in lo_prio: + lo_ep = int(lo_prio.split(':')[0]) + lo_prio = lo_prio.split(':')[1] + if lo_ep > hi_ep: + return True - if lower_prio[0] > higher_prio[0]: + # [0] will be upstream, [1] should be the package build + hi_prio = hi_prio.split('-') + lo_prio = lo_prio.split('-') + if lo_prio[0] > hi_prio[0]: return True + if len(hi_prio) > 1 and len(lo_prio) > 1: + hi_prio[1] = hi_prio[1].replace('.', '') + lo_prio[1] = lo_prio[1].replace('.', '') + if int(lo_prio[1]) > int(hi_prio[1]): + return True + return False