Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/lib/mysql-functions
diff options
context:
space:
mode:
authorErich Eckner <git@eckner.net>2018-03-08 09:13:07 +0100
committerErich Eckner <git@eckner.net>2018-03-08 09:13:07 +0100
commit4a8a8b2408ebf2543bc9fb00165b502a12cef7a2 (patch)
tree9e8d4de91f66591f8158f6b9f98cb1a54c815dfb /lib/mysql-functions
parent1402c0c7565e1a1ecc55c0383727de5b6ad0dba3 (diff)
lib/mysql-functions: mysql_run_query: we save the query in a file and delete that file if the query succeeded
Diffstat (limited to 'lib/mysql-functions')
-rwxr-xr-xlib/mysql-functions73
1 files changed, 55 insertions, 18 deletions
diff --git a/lib/mysql-functions b/lib/mysql-functions
index 97fc2f4..d87b79e 100755
--- a/lib/mysql-functions
+++ b/lib/mysql-functions
@@ -25,33 +25,70 @@ base64_encode_each() {
# mysql_run_query
# wrapper function to query mysql
mysql_run_query() {
+ local query_file
if [ -s "${work_dir}/build-master-sanity" ]; then
# If the build master is insane, the calling command should only check
# if the build master is still insane - we do not want to log that.
${mysql_command} -N --raw --batch "$@"
else
- {
- printf '%s %s: ' "$0" "${mysql_command} -N --raw --batch $*"
- date
- } \
- | tee -a "${work_dir}/mysql.stdin" \
- | tee -a "${work_dir}/mysql.stdout" \
- >> "${work_dir}/mysql.stderr"
- tee -a "${work_dir}/mysql.stdin" \
- | ${mysql_command} -N --raw --batch "$@" \
- 2>> "${work_dir}/mysql.stderr" \
- | tee -a "${work_dir}/mysql.stdout"
- for s in \
- "${work_dir}/mysql.stdin" \
- "${work_dir}/mysql.stdout" \
- "${work_dir}/mysql.stderr"; do
+ # we save the query in a file and delete that file if the query succeeded
+ query_file=$(mktemp "${work_dir}/tmp.mysql-functions.query.$(date +'%Y-%m-%dT%T').XXXXXX")
+ cat > "${query_file}"
+ for i in {1..10}; do
{
- tail -n 10000 "$s"
- printf '%s %s done: ' "$0" "${mysql_command} $*"
+ printf '%s %s: ' "$0" "${mysql_command} -N --raw --batch $*"
date
} \
- | sponge "$s"
+ | tee -a "${work_dir}/mysql.stdin" \
+ | tee -a "${work_dir}/mysql.stdout" \
+ >> "${work_dir}/mysql.stderr"
+ cat "${query_file}" \
+ >> "${work_dir}/mysql.stdin"
+ {
+ ${mysql_command} -N --raw --batch "$@" \
+ < "${query_file}" \
+ 2>> "${work_dir}/mysql.stderr" \
+ && rm "${query_file}"
+ } \
+ | tee -a "${work_dir}/mysql.stdout"
+ if ! [ -f "${query_file}" ]; then
+ # success!
+ for s in \
+ "${work_dir}/mysql.stdin" \
+ "${work_dir}/mysql.stdout" \
+ "${work_dir}/mysql.stderr"; do
+ {
+ tail -n 10000 "$s"
+ printf '%s %s done: ' "$0" "${mysql_command} $*"
+ date
+ } \
+ | sponge "$s"
+ done
+ break
+ fi
+ for s in \
+ "${work_dir}/mysql.stdin" \
+ "${work_dir}/mysql.stdout" \
+ "${work_dir}/mysql.stderr"; do
+ {
+ printf '%s %s FAILED: ' "$0" "${mysql_command} $*"
+ date
+ } \
+ >> "$s"
+ done
done
+ # a present query_file means there was an error
+ if [ -f "${query_file}" ]; then
+ >&2 printf 'I could not complete a mysql query!\n'
+ if [ ! -s "${work_dir}/build-master-sanity" ]; then
+ printf '\001ACTION failed to execute a mysql query - can you have a look at "%s"?.\001\n' \
+ "${query_file##*/}" \
+ | sponge "${irc_dir}/#archlinux-ports/in"
+ fi
+ echo 'A mysql query failed.' > \
+ "${work_dir}/build-master-sanity"
+ return 2
+ fi
fi
}