From 114200a9c3b183cae9c9ea3bb2aacf8ae6a3cb3c Mon Sep 17 00:00:00 2001 From: Erich Eckner Date: Tue, 4 Sep 2018 10:19:43 +0200 Subject: lib/mysql-functions: mysql_run_query() if a query containing "LOAD DATA LOCAL INFILE ..." failed, save those files for furhter inspection --- lib/mysql-functions | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) (limited to 'lib') diff --git a/lib/mysql-functions b/lib/mysql-functions index e0715c3..d38169b 100755 --- a/lib/mysql-functions +++ b/lib/mysql-functions @@ -22,9 +22,6 @@ base64_encode_each() { done } -# TODO: if a query containing 'LOAD DATA LOCAL INFILE ...' failed, save -# those files for furhter inspection! - # mysql_run_query # wrapper function to query mysql mysql_run_query() { @@ -34,6 +31,8 @@ mysql_run_query() { local file_name_extra local file + local files + loval number file_name_extra='' if [ "x$1" = 'xunimportant' ]; then @@ -62,6 +61,18 @@ mysql_run_query() { # a present query_file means there was an error if [ -f "${query_stdin}" ]; then >&2 printf 'I could not complete a mysql query!\n' + files="${query_stdin} ${query_stdout} ${query_stderr}$( + sed -n ' + s/^.*INFILE "\(\S\+\)".*$/\1/ + T + p + ' "${query_stdin}" | \ + cat -n | \ + while read -r number file; do + cp "${file}" "${query_stdin%.stdin}.infile.${number}" + printf ' %s' "${query_stdin%.stdin}.infile.${number}" + done + )" if ${i_am_the_master}; then if [ ! -s "${work_dir}/build-master-sanity" ] && \ [ -z "${file_name_extra}" ]; then @@ -69,10 +80,7 @@ mysql_run_query() { "${query_stdin##*/}" \ | irc_say fi - for file in \ - "${query_stdin}" \ - "${query_stdout}" \ - "${query_stderr}"; do + for file in ${files}; do cp "${file}" "${webserver_directory}/mysql-queries/${file##*/}.txt" chmod go+r "${webserver_directory}/mysql-queries/${file##*/}.txt" done @@ -81,10 +89,8 @@ mysql_run_query() { echo 'A mysql query failed.' > \ "${work_dir}/build-master-sanity" else - rm -f \ - "${query_stdin}" \ - "${query_stdout}" \ - "${query_stderr}" + # shellcheck disable=SC2086 + rm -f ${files} fi return 2 fi -- cgit v1.2.3-70-g09d2