From 92f9598910e40c8a4979eda7004949fe06f8cdd4 Mon Sep 17 00:00:00 2001 From: Daniel Ceregatti Date: Fri, 19 May 2023 23:41:34 -0700 Subject: [PATCH] WIP XML merging. Handle files without XML document node, as well as without their root node. This means we need a matrix of what file has what root node AND the names of the child nodes! --- server/bin/dz | 43 ++++++++++++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/server/bin/dz b/server/bin/dz index 3d78926..cbfea4c 100755 --- a/server/bin/dz +++ b/server/bin/dz @@ -147,38 +147,51 @@ report() { mergexml(){ # Start with the upstream XML files from a pristine mpmissions directory echo "Copying upstream XML files from mpmissions..." - pushd /mpmissions > /dev/null - for var in CFGEVENTSPAWNS CFGSPAWNABLETYPES EVENTS TYPES +ffff for var in CFGEVENTSPAWNS CFGSPAWNABLETYPES EVENTS TYPES do - find -name "${var,,}.xml" -exec cp -vf {} ${SERVER_FILES}/mpmissions/{} \; + find /mpmissions -name "${var,,}.xml" -exec cp -vf {} ${SERVER_FILES}/{} \; done for link in $(ls -tdr ${SERVER_PROFILE}/@* 2> /dev/null) do ID=$(readlink ${link} | awk -F/ '{print $NF}') MODNAME=$(get_mod_name ${ID}) -# for var in CFGEVENTSPAWNS CFGSPAWNABLETYPES EVENTS TYPES - for var in EVENTS TYPES + # Going to have to maintain a matrix of file names -> root node -> child node permutations + for i in "CFGEVENTSPAWNS:eventposdef:event" "CFGSPAWNABLETYPES:spawnabletypes:type" "EVENTS:events:event" "TYPES:types:type" do + var=$(echo ${i} | cut -d: -f1) + CHECK=$(echo ${i} | cut -d: -f2) + CHILD=$(echo ${i} | cut -d: -f3) if [ -f "${WORKSHOP_DIR}/${ID}/${var,,}.xml" ] then echo "Merging ${WORKSHOP_DIR}/${ID}/${var,,}.xml..." - if ! grep -q '' /tmp/x then - # When we have no XML or root node - echo "The file has no root node" -# xmlstarlet ed -s / -t elem -n "eventposdef" -m /event /eventposdef ${WORKSHOP_DIR}/${ID}/${var,,}.xml + echo " - has no root node <${CHECK}>. fixing..." + xmlstarlet ed -s / -t elem -n "${CHECK}" -m /${CHILD} /${CHECK} /tmp/x > /tmp/y + mv /tmp/y /tmp/x fi - if ! grep -q ' /tmp/y + mv /tmp/y /tmp/x fi + + xmllint --noout /tmp/x || { + echo "The final file failed lint tests, aborting..." + exit 1 + } + + # At this point it's normalized. Merge to the mpmissions file. + echo " - merging to mpmissions..." +# xmlstarlet ed -s / -t elem -n "eventposdef" -m /event /eventposdef ${WORKSHOP_DIR}/${ID}/${var,,}.xml + fi done done - popd > /dev/null exit 0 }