From 300e0cc6a76131b622fd487d06aa8fa4ef8b24fb Mon Sep 17 00:00:00 2001 From: =?utf8?q?Petr=20P=C3=ADsa=C5=99?= Date: Tue, 31 May 2011 14:25:09 +0200 Subject: [PATCH] Implement F:R:RPM::is_satisfied --- Fedora/Rebuild/RPM.pm | 64 +++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 60 insertions(+), 4 deletions(-) diff --git a/Fedora/Rebuild/RPM.pm b/Fedora/Rebuild/RPM.pm index 5dfc888..b7350e9 100644 --- a/Fedora/Rebuild/RPM.pm +++ b/Fedora/Rebuild/RPM.pm @@ -6,6 +6,7 @@ use Set::Object; use Carp; use File::Path; use RPM2; +use RPM::VersionCompare; use namespace::clean; use version 0.77; our $VERSION = version->declare("v0.0.1"); @@ -46,8 +47,10 @@ sub adddeps { } # Check whether a requires tripplet (name, flag, version) is fulfilled by -# hash of requires. Return true or false; +# hash of requires. Return true or false (even in parser error). # Hash format is { NAME1 => [ [FLAG1, VERSION1], [FLAG2, VERSION2] ] }. +# XXX: FLAG cannot contain LESS|GREATER. No implemented. +# XXX: FLAG cannot be 0 in lower bits. # XXX: This is not a method. sub is_satisfied { my ($rname, $rflag, $rversion, $provides) = @_; @@ -57,10 +60,63 @@ sub is_satisfied { } for my $provide (@{$$provides{$rname}}) { - if ($provide[0] eq - # FIXME: Here we want to call librpm to do the comparison - ...; + if (($rflag & ANY) || ($provides & ANY)) { + return 1; + } + + my $pflag = $$provide[0]; + my $pversion = $$provide[1]; + my $order = RPM::CompareVersion::labelCompare($rversion, $pversion); + if (!defined $order) { + # Parser error; + return 0; + } + + # Satisfaction matrix: + # + # (labelCompare($rversion,$pversion) = $order) == 0: + # pflag + # < <= == >= > + # rflag < 1 1 0 0 0 + # <= 1 1 1 1 0 + # == 0 1 1 1 0 + # => 0 1 1 1 1 + # > 0 0 0 1 1 + # + if ($order == 0) { + if (($rflag & EQUAL) && ($pflag & EQUAL)) { return 1; } + if (($rflag & LESS) && ($pflag & LESS)) { return 1; } + if (($rflag & GREATER) && ($pflag & GREATER)) { return 1; } + } + + # (labelCompare($rversion,$pversion) = $order) > 0: + # pflag + # < <= == >= > + # rflag < 1 1 1 1 1 + # <= 1 1 1 1 1 + # == 0 0 0 1 1 + # => 0 0 0 1 1 + # > 0 0 0 1 1 + # + if ($order > 0) { + if ($rflags & LESS) || ($pflags & LESS)) { return 1; } + } + + # (labelCompare($rversion,$pversion) = $order) < 0: + # pflag + # < <= == >= > + # rflag < 1 1 0 0 0 + # <= 1 1 0 0 0 + # == 1 1 0 0 0 + # => 1 1 1 1 1 + # > 1 1 1 1 1 + # + if ($order < 0) { + if (($rflags & GREATER) || ($pflags & GREATER)) { return 1; } + } } + + return 0; } -- 2.11.4.GIT