From 2ce177d155960f10ca5f6c30ad1795cd25ec7fc3 Mon Sep 17 00:00:00 2001 From: xq2005 Date: Fri, 22 Nov 2013 01:38:23 -0800 Subject: [PATCH] for bug 3919: version compare problem --- perl-xCAT/xCAT/Utils.pm | 44 +++++++++++++++++++++++++++++ xCAT-server/lib/xcat/plugins/kvm.pm | 2 +- 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/perl-xCAT/xCAT/Utils.pm b/perl-xCAT/xCAT/Utils.pm index 558df696f..e0cc04c37 100644 --- a/perl-xCAT/xCAT/Utils.pm +++ b/perl-xCAT/xCAT/Utils.pm @@ -3406,4 +3406,48 @@ 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; diff --git a/xCAT-server/lib/xcat/plugins/kvm.pm b/xCAT-server/lib/xcat/plugins/kvm.pm index 8c68dd488..20463759c 100644 --- a/xCAT-server/lib/xcat/plugins/kvm.pm +++ b/xCAT-server/lib/xcat/plugins/kvm.pm @@ -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;