2
0
mirror of https://github.com/xcat2/xcat-core.git synced 2025-06-20 05:00:34 +00:00

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.
This commit is contained in:
Miro
2017-11-26 21:20:49 -05:00
committed by yangsong
parent 80f587b7fc
commit aaacca80cd

View File

@ -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"