check-procedures-tx.sh (2078B)
1 #!/bin/sh 2 3 # This file is part of TALER 4 # Copyright (C) 2026 Taler Systems SA 5 # 6 # TALER is free software; you can redistribute it and/or modify it under the 7 # terms of the GNU General Public License as published by the Free Software 8 # Foundation; either version 3, or (at your option) any later version. 9 # 10 # TALER is distributed in the hope that it will be useful, but WITHOUT ANY 11 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 12 # A PARTICULAR PURPOSE. See the GNU General Public License for more details. 13 # 14 # You should have received a copy of the GNU General Public License along with 15 # TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> 16 # 17 # Checks that none of the SQL files that gen-procedures.sh concatenates into 18 # global_procedures.sql / instance_procedures.sql contains a transaction 19 # control statement at the top level: gen-procedures.sh wraps the WHOLE 20 # concatenation in a single BEGIN ... COMMIT, so a stray COMMIT would close 21 # that transaction early and everything appended after it would be installed 22 # outside of it. Transaction control inside a $$-quoted procedure body is a 23 # plpgsql statement and is fine. 24 25 set -eu 26 27 if [ $# -lt 1 ]; then 28 echo "Usage: $0 SQLFILES..." >&2 29 exit 1 30 fi 31 32 status=0 33 for x in "$@"; do 34 if ! awk -v fname="$x" ' 35 { 36 line = $0; 37 sub(/--.*/, "", line); 38 # An odd number of dollar quotes ($$, $FN$, ...) on a line enters 39 # or leaves a procedure body. 40 n = gsub(/\$[A-Za-z_0-9]*\$/, "", line); 41 if (n % 2 == 1) 42 inbody = ! inbody; 43 if (inbody) 44 next; 45 if (line ~ /^[ \t]*(BEGIN|COMMIT|ROLLBACK|START[ \t]+TRANSACTION)[ \t]*;/) 46 { 47 printf "%s:%d: top-level transaction control statement: %s\n", 48 fname, NR, $0; 49 bad = 1; 50 } 51 } 52 END { exit bad ? 1 : 0 }' "$x" 53 then 54 status=1 55 fi 56 done 57 58 if [ 0 != "$status" ]; then 59 echo "Top-level transaction control found in a procedure file;" >&2 60 echo "gen-procedures.sh already wraps them in BEGIN ... COMMIT." >&2 61 fi 62 exit "$status"