File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11#! /bin/bash
22
33ytox () {
4- echo " <?xml version=\" 1.0\" encoding=\" UTF-8\" ?><xml>$( yq -ox -I0 " $1 " | sed ' s/"/\\"/g' ) </xml>" > " ${1% .* } .xml" 2> /dev/null
5- stat -c %s " ${1% .* } .xml" || echo -1
4+ local source_file
5+ local normalized_file
6+ local normalized_tmp=" "
7+ local xml_body
8+
9+ source_file=" $1 "
10+ normalized_file=" $source_file "
11+
12+ if jq -e ' type == "array"' " $source_file " > /dev/null 2>&1 ; then
13+ normalized_tmp=$( mktemp " ${TMPDIR:-/ tmp} /ytoxt.XXXXXX" ) || return 1
14+ jq -c ' {"package": .}' " $source_file " > " $normalized_tmp " || {
15+ rm -f " $normalized_tmp "
16+ return 1
17+ }
18+ normalized_file=" $normalized_tmp "
19+ fi
20+
21+ xml_body=$( yq -ox -I0 " $normalized_file " 2> /dev/null) || {
22+ [ -n " $normalized_tmp " ] && rm -f " $normalized_tmp "
23+ return 1
24+ }
25+
26+ [ -n " $normalized_tmp " ] && rm -f " $normalized_tmp "
27+ printf ' <?xml version="1.0" encoding="UTF-8"?><xml>%s</xml>' " $( printf ' %s' " $xml_body " | sed ' s/"/\\"/g' ) " > " ${source_file% .* } .xml" 2> /dev/null
28+ stat -c %s " ${source_file% .* } .xml" || echo -1
629}
730
831# ytox + trim: if the json or xml is over 50MB, remove oldest versions
You can’t perform that action at this time.
0 commit comments