2
0
mirror of https://github.com/xcat2/xcat-core.git synced 2025-08-13 15:00:15 +00:00

Fix 3827, add a flag to arrayops to keep the order of result so that (#3839)

the user info in generated passwd.merge file could be kept the previous order.
This commit is contained in:
Bin Xu
2017-09-04 11:20:46 +08:00
committed by yangsong
parent 51ad6fd511
commit 0c42bef81e

View File

@@ -184,7 +184,7 @@ sub updateUserInfo {
# update the merge file
my $mergefile = $cfmdir . "/" . $file . ".merge";
my @diff = xCAT::CFMUtils->arrayops("D", \@newrecords, \@oldrecords);
my @diff = xCAT::CFMUtils->arrayops("D", \@newrecords, \@oldrecords, 1);
# output the diff to merge files
my $fp;
@@ -865,6 +865,7 @@ sub trim {
$flag - "U"/"I"/"D"
\@array1 - reference to an arrary
\@array2 - reference to an arrary
$odered - flag to keep pervious order
Returns:
@union/@intersection/@difference
Globals:
@@ -878,7 +879,7 @@ sub trim {
#-----------------------------------------------------------------------------
sub arrayops {
my ($class, $ops, $array1, $array2) = @_;
my ($class, $ops, $array1, $array2, $ordered) = @_;
my @union = ();
my @intersection = ();
@@ -886,21 +887,23 @@ sub arrayops {
my %count = ();
foreach my $element (@$array1, @$array2)
{
$count{$element}++
$count{$element}++;
push @union, $element unless ( $count{$element} > 1 );
}
foreach my $element (keys %count) {
push @union, $element;
unless( defined($ordered) and $ordered ) {
@union = keys %count;
}
foreach my $element (@union) {
push @{ $count{$element} > 1 ? \@intersection : \@difference }, $element;
}
if ($ops eq "U") { return @union; }
if ($ops eq "I") { return @intersection; }
if ($ops eq "D") { return @difference; }
#return (\@union, \@intersection, \@difference);
}