From 0c42bef81e6f81376c3f0bd2487886ce99704262 Mon Sep 17 00:00:00 2001 From: Bin Xu Date: Mon, 4 Sep 2017 11:20:46 +0800 Subject: [PATCH] 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. --- perl-xCAT/xCAT/CFMUtils.pm | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/perl-xCAT/xCAT/CFMUtils.pm b/perl-xCAT/xCAT/CFMUtils.pm index e2563cfa4..d6a36c659 100644 --- a/perl-xCAT/xCAT/CFMUtils.pm +++ b/perl-xCAT/xCAT/CFMUtils.pm @@ -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); }