From aaacca80cda61d257d17ab4aff869a81cf257bd4 Mon Sep 17 00:00:00 2001 From: Miro Date: Sun, 26 Nov 2017 21:20:49 -0500 Subject: [PATCH] Fix merging in xdcpmerge.sh (#4328) * Fixes in xdcpmerge.sh Two fixes: 1. The grep pattern when finding duplicate usernames is missing ":" at the end. So, for example user "test" would also match "test2, etc.". Adding the ":" delimiter fixes the issue. 2. Another issue happens when the file to be merged is a superset of the files on the nodes. For example, if a new user is added and entire passwd file (that is otherwise identical) is sent to be merged. In this case, the $filebackup.nodups file, i.e. the original file with duplicates removed, becomes empty and the condition "if [ -s "$filebackup.nodups" ]" does not execute. Then the merged file ends up being original file with the merge file fully appended, clearly not what was intended. This is solved by changing the condition to check for file existence "-a" rather then for size. Additionally, I also turn the logic around so that the duplicates are removed from the merge file and then added to the original file. I think this makes logic a bit cleaner and also ensures that existing entries are not reordered or changed in any way. * Streamlining previous commit Adjustment to previous commit, streamlining and simplifying logic. Once $mergefile.nodups is created, just concatenate it the original file. * Update to xdcpmerge No need to copy $filebackup to $curfile, they are the same. --- xCAT-server/share/xcat/scripts/xdcpmerge.sh | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/xCAT-server/share/xcat/scripts/xdcpmerge.sh b/xCAT-server/share/xcat/scripts/xdcpmerge.sh index b7724e9f1..39922add6 100755 --- a/xCAT-server/share/xcat/scripts/xdcpmerge.sh +++ b/xCAT-server/share/xcat/scripts/xdcpmerge.sh @@ -82,24 +82,22 @@ for i in $*; do done # remove the last delimiter userlisttmp="${userlist%?}" - listend=")'" + listend="):'" userlist=$userlisttmp$listend grepcmd=$grepcmd$userlist #set -x - grepcmd="$grepcmd $filebackup > $filebackup.nodups" + grepcmd="$grepcmd $mergefile > $mergefile.nodups" #echo "grepcmd=$grepcmd" # now run it eval $grepcmd - # if no dups file created - if [ -s "$filebackup.nodups" ]; then - cp -p $filebackup.nodups $filebackup - #echo "cp -p $filebackup.nodups $filebackup" - rm $filebackup.nodups - fi fi - # Now update the currentfile - cat $filebackup $mergefile > $curfile - #echo "cat $filebackup $mergefile > $curfile" + + # add new entries from mergefile, if any + if [ -a "$mergefile.nodups" ]; then + cat $mergefile.nodups >> $curfile + rm $mergefile.nodups + fi + # now cleanup rm $filebackup.userlist # echo "rm $filebackup.userlist"