added a function to compare the version numbers
git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@2814 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd
This commit is contained in:
parent
703b56e08c
commit
47386fb1d3
@ -3161,4 +3161,46 @@ sub logEventsToDatabase
|
||||
return (0, "");
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
=head3 CheckVersion
|
||||
Checks the two versions numbers to see which one is greater.
|
||||
Arguments:
|
||||
ver_a the version number in format of d.d.d.d...
|
||||
ver_b the version number in format of d.d.d.d...
|
||||
Returns:
|
||||
1 if ver_a is greater than ver_b
|
||||
0 if ver_a is eaqual to ver_b
|
||||
-1 if ver_a is smaller than ver_b
|
||||
|
||||
=cut
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
sub CheckVersion {
|
||||
my $ver_a=shift;
|
||||
if ($ver_a =~ /xCAT::Utils/) {
|
||||
$ver_a=shift;
|
||||
}
|
||||
my $ver_b=shift;
|
||||
|
||||
my @a=split(/\./,$ver_a);
|
||||
my @b=split(/\./,$ver_b);
|
||||
my $len_a=@a;
|
||||
my $len_b=@b;
|
||||
|
||||
my $index=0;
|
||||
my $max_index=($len_a>$len_b) ? $len_a : $len_b;
|
||||
|
||||
for ($index=0; $index <= $max_index; $index++) {
|
||||
my $val_a=($len_a < $index) ? 0 : $a[$index];
|
||||
my $val_b=($len_b < $index) ? 0 : $b[$index];
|
||||
if ($val_a > $val_b) { return 1;}
|
||||
if ($val_a < $val_b) { return -1;}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
1;
|
||||
|
Loading…
Reference in New Issue
Block a user