From: Peter Wu Date: Wed, 17 Oct 2018 10:22:17 +0000 (+0200) Subject: validate-diameter-xml.sh: do not hard-code temporary directory X-Git-Url: http://git.samba.org/?p=metze%2Fwireshark%2Fwip.git;a=commitdiff_plain;h=ca50195f1148b855c9fd788725dba77aa4b08315 validate-diameter-xml.sh: do not hard-code temporary directory In the event that validation fails, the hard-coded temporary directory would remain present. Use of a fixed hard-coded directory also prevents concurrent runs. Change-Id: I29f09dc004b1ab3578b4a9c51ea7e1a5b526159f Reviewed-on: https://code.wireshark.org/review/30231 Reviewed-by: Jeff Morriss --- diff --git a/tools/validate-diameter-xml.sh b/tools/validate-diameter-xml.sh index 3fad9c8632..36b6fb2976 100755 --- a/tools/validate-diameter-xml.sh +++ b/tools/validate-diameter-xml.sh @@ -37,24 +37,27 @@ then exit 1 fi +if ! tmpdir=$(mktemp -d); then + echo "Could not create temporary directory" >&2 + exit 1 +fi +trap 'rm -rf "$tmpdir"' EXIT + # First edit all the AVP names that start with "3GPP" to indicate "TGPP". # XML doesn't allow ID's to start with a digit but: # 1) We don't *really* care if it's valid XML # 2) (but) we do want to use xmllint to find problems # 3) (and) users see the AVP names. Showing them "TGPP" instead of "3GPP" # is annoying enough to warrant this extra work. -mkdir /tmp/diameter || exit 1 -cp diameter/dictionary.dtd /tmp/diameter || exit 1 +cp diameter/dictionary.dtd "$tmpdir" || exit 1 for f in diameter/*.xml do - sed 's/name="3GPP/name="TGPP/g' $f > /tmp/$f || exit 1 + sed 's/name="3GPP/name="TGPP/g' "$f" > "$tmpdir/${f##*/}" || exit 1 done -xmllint --noout --noent --postvalid /tmp/diameter/dictionary.xml && +xmllint --noout --noent --postvalid "$tmpdir/dictionary.xml" && echo "Diameter dictionary is (mostly) valid XML." -rm -rf /tmp/diameter - # # Editor modelines - https://www.wireshark.org/tools/modelines.html #