Accepting request 69617 from Base:System
- rpmsort + Fix comparison function to match rpm (bnc#644515, thanks to Michael Schroeder). + Add --test option to verify result against zypper vcmp. (forwarded request 69563 from michal-m) OBS-URL: https://build.opensuse.org/request/show/69617 OBS-URL: https://build.opensuse.org/package/show/openSUSE:Factory/rpm?expand=0&rev=126
This commit is contained in:
parent
c3b37d48f1
commit
c6226665ac
@ -1,3 +1,11 @@
|
||||
-------------------------------------------------------------------
|
||||
Wed May 4 12:42:33 UTC 2011 - mmarek@novell.com
|
||||
|
||||
- rpmsort
|
||||
+ Fix comparison function to match rpm (bnc#644515, thanks to
|
||||
Michael Schroeder).
|
||||
+ Add --test option to verify result against zypper vcmp.
|
||||
|
||||
-------------------------------------------------------------------
|
||||
Sat Feb 19 12:39:31 CET 2011 - vuntz@opensuse.org
|
||||
|
||||
|
36
rpmsort
36
rpmsort
@ -17,7 +17,7 @@
|
||||
|
||||
use Getopt::Long qw(:config gnu_getopt);
|
||||
|
||||
sub rpm_cmp_versions {
|
||||
sub do_rpm_cmp_versions {
|
||||
my ($evr1, $evr2) = @_;
|
||||
|
||||
sub _rpm_cmp {
|
||||
@ -31,8 +31,10 @@ sub rpm_cmp_versions {
|
||||
$s1 =~ s/^[^a-zA-Z0-9]+//;
|
||||
$s2 =~ s/^[^a-zA-Z0-9]+//;
|
||||
if ($s1 =~ /^\d/ || $s2 =~ /^\d/) {
|
||||
$s1 =~ s/^0*(\d*)//; $x1 = $1;
|
||||
$s2 =~ s/^0*(\d*)//; $x2 = $1;
|
||||
$s1 =~ s/^(0*(\d*))//; $x1 = $2;
|
||||
return -1 if $1 eq '';
|
||||
$s2 =~ s/^(0*(\d*))//; $x2 = $2;
|
||||
return 1 if $1 eq '';
|
||||
$r = length $x1 <=> length $x2 || $x1 cmp $x2;
|
||||
} else {
|
||||
$s1 =~ s/^([a-zA-Z]*)//; $x1 = $1;
|
||||
@ -57,11 +59,35 @@ sub rpm_cmp_versions {
|
||||
|
||||
my $reorder = sub { return @_ };
|
||||
my $key = 0;
|
||||
my $test = 0;
|
||||
|
||||
sub rpm_cmp_versions {
|
||||
my ($evr1, $evr2) = @_;
|
||||
|
||||
chomp($evr1, $evr2);
|
||||
my $res1 = do_rpm_cmp_versions($evr1, $evr2);
|
||||
if ($test) {
|
||||
open(my $fd, '-|', 'zypper', '--terse', 'versioncmp',
|
||||
$evr1, $evr2) or die "zypper: $!\n";
|
||||
my $res2 = <$fd>;
|
||||
close($fd) or die "zypper: $!\n";
|
||||
chomp $res2;
|
||||
if ($res1 != $res2) {
|
||||
my @operators = qw(< == >);
|
||||
my $op1 = $operators[$res1 + 1];
|
||||
my $op2 = $operators[$res2 + 1];
|
||||
|
||||
print STDERR "BUG: $evr1 $op1 $evr2 vs. zypper: $evr1 $op2 $evr2\n";
|
||||
}
|
||||
}
|
||||
return $res1;
|
||||
}
|
||||
|
||||
GetOptions ("r|reverse" => sub { $reorder = sub { return reverse @_ } },
|
||||
"k|key=i" => \$key)
|
||||
"k|key=i" => \$key,
|
||||
"test" => \$test)
|
||||
or do {
|
||||
print STDERR "Usage\n";
|
||||
print STDERR "Usage $0 [-r, --reverse] [-k N, --key=N] [--test]\n";
|
||||
exit 1;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user