for bug 3919: version compare problem

This commit is contained in:
xq2005 2013-11-22 01:35:37 -08:00
parent 3b1f5fbbf2
commit 47a010573d
2 changed files with 47 additions and 2 deletions

View File

@ -3372,6 +3372,51 @@ sub filter_nostatusupdate{
}
}
}
}
sub version_cmp {
my $ver_a = shift;
if ($ver_a =~ /xCAT::Utils/)
{
$ver_a = shift;
}
my $ver_b = shift;
my @array_a = ($ver_a =~ /([-.]|\d+|[^-.\d]+)/g);
my @array_b = ($ver_b =~ /([-.]|\d+|[^-.\d]+)/g);
my ($a, $b);
my $len_a = @array_a;
my $len_b = @array_b;
my $len = $len_a;
if ( $len_b < $len_a ) {
$len = $len_b;
}
for ( my $i = 0; $i < $len; $i++ ) {
$a = $array_a[$i];
$b = $array_b[$i];
if ($a eq $b) {
next;
} elsif ( $a eq '-' ) {
return -1;
} elsif ( $b eq '-') {
return 1;
} elsif ( $a eq '.' ) {
return -1;
} elsif ( $b eq '.' ) {
return 1;
} elsif ($a =~ /^\d+$/ and $b =~ /^\d+$/) {
if ($a =~ /^0/ || $b =~ /^0/) {
return ($a cmp $b);
} else {
return ($a <=> $b);
}
} else {
$a = uc $a;
$b = uc $b;
return ($a cmp $b);
}
}
return ( $len_a <=> $len_b )
}
1;

View File

@ -2544,7 +2544,7 @@ sub process_request {
unless ($libvirtsupport) {
$libvirtsupport = eval {
require Sys::Virt;
if (Sys::Virt->VERSION < "0.2.0") {
if ( xCAT::Utils::version_cmp(Sys::Virt->VERSION, "0.2.0") < 0 ) {
die;
}
1;