[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

[dak/master] error out if sql query fails



Using "echo ... | psql" does not generate an error when something goes
wrong.  Using "psql -c ..." instead does:

  $ echo "SELECT * FROM does_not_exist" | psql projectb 2>/dev/null; echo $?
  0

  $ q="SELECT * FROM does_not_exist"; psql -c "$q" projectb 2>/dev/null; echo $?
  1

This patch switches dak to use the second form to avoid silenty ignoring
errors.

Signed-off-by: Ansgar Burchardt <ansgar@debian.org>
---
 config/backports/dinstall.functions |   12 ++++++++----
 config/debian/dinstall.functions    |   12 ++++++++----
 2 files changed, 16 insertions(+), 8 deletions(-)

diff --git a/config/backports/dinstall.functions b/config/backports/dinstall.functions
index 8709e6e..dc3457b 100644
--- a/config/backports/dinstall.functions
+++ b/config/backports/dinstall.functions
@@ -263,7 +263,8 @@ function mkfilesindices() {
     ARCHLIST=$(tempfile)
 
     log "Querying postgres"
-    echo 'SELECT l.path, f.filename, a.arch_string FROM location l JOIN files f ON (f.location = l.id) LEFT OUTER JOIN (binaries b JOIN architecture a ON (b.architecture = a.id)) ON (f.id = b.file)' | psql -At | sed 's/|//;s,^/srv/ftp-master.debian.org/ftp,.,' | sort >$ARCHLIST
+    local query='SELECT l.path, f.filename, a.arch_string FROM location l JOIN files f ON (f.location = l.id) LEFT OUTER JOIN (binaries b JOIN architecture a ON (b.architecture = a.id)) ON (f.id = b.file)'
+    psql -At -c "$query" | sed 's/|//;s,^/srv/ftp-master.debian.org/ftp,.,' | sort >$ARCHLIST
 
     includedirs () {
         perl -ne 'print; while (m,/[^/]+$,) { $_=$`; print $_ . "\n" unless $d{$_}++; }'
@@ -296,12 +297,15 @@ function mkfilesindices() {
     log "Generating suite lists"
 
     suite_list () {
-        printf 'SELECT DISTINCT l.path, f.filename FROM (SELECT sa.source AS source FROM src_associations sa WHERE sa.suite = %d UNION SELECT b.source AS source FROM bin_associations ba JOIN binaries b ON (ba.bin = b.id) WHERE ba.suite = %d) s JOIN dsc_files df ON (s.source = df.source) JOIN files f ON (df.file = f.id) JOIN location l ON (f.location = l.id)\n' $1 $1 | psql -F' ' -A -t
+        local query
+	query="$(printf 'SELECT DISTINCT l.path, f.filename FROM (SELECT sa.source AS source FROM src_associations sa WHERE sa.suite = %d UNION SELECT b.source AS source FROM bin_associations ba JOIN binaries b ON (ba.bin = b.id) WHERE ba.suite = %d) s JOIN dsc_files df ON (s.source = df.source) JOIN files f ON (df.file = f.id) JOIN location l ON (f.location = l.id)' $1 $1)"
+	psql -F' ' -A -t -c "$query"
 
-        printf 'SELECT l.path, f.filename FROM bin_associations ba JOIN binaries b ON (ba.bin = b.id) JOIN files f ON (b.file = f.id) JOIN location l ON (f.location = l.id) WHERE ba.suite = %d\n' $1 | psql -F' ' -A -t
+        query="$(printf 'SELECT l.path, f.filename FROM bin_associations ba JOIN binaries b ON (ba.bin = b.id) JOIN files f ON (b.file = f.id) JOIN location l ON (f.location = l.id) WHERE ba.suite = %d' $1)"
+	psql -F' ' -A -t -c "$query"
     }
 
-    printf 'SELECT id, suite_name FROM suite\n' | psql -F' ' -At |
+    psql -F' ' -At -c 'SELECT id, suite_name FROM suite' |
     while read id suite; do
         [ -e $base/ftp/dists/$suite ] || continue
         (
diff --git a/config/debian/dinstall.functions b/config/debian/dinstall.functions
index b7679dc..a7bf95c 100644
--- a/config/debian/dinstall.functions
+++ b/config/debian/dinstall.functions
@@ -246,7 +246,8 @@ function mkfilesindices() {
     ARCHLIST=$(tempfile)
 
     log "Querying postgres"
-    echo 'SELECT l.path, f.filename, a.arch_string FROM location l JOIN files f ON (f.location = l.id) LEFT OUTER JOIN (binaries b JOIN architecture a ON (b.architecture = a.id)) ON (f.id = b.file)' | psql -At | sed 's/|//;s,^/srv/ftp-master.debian.org/ftp,.,' | sort >$ARCHLIST
+    local query='SELECT l.path, f.filename, a.arch_string FROM location l JOIN files f ON (f.location = l.id) LEFT OUTER JOIN (binaries b JOIN architecture a ON (b.architecture = a.id)) ON (f.id = b.file)'
+    psql -At -c "$query" | sed 's/|//;s,^/srv/ftp-master.debian.org/ftp,.,' | sort >$ARCHLIST
 
     includedirs () {
         perl -ne 'print; while (m,/[^/]+$,) { $_=$`; print $_ . "\n" unless $d{$_}++; }'
@@ -279,12 +280,15 @@ function mkfilesindices() {
     log "Generating suite lists"
 
     suite_list () {
-        printf 'SELECT DISTINCT l.path, f.filename FROM (SELECT sa.source AS source FROM src_associations sa WHERE sa.suite = %d UNION SELECT b.source AS source FROM bin_associations ba JOIN binaries b ON (ba.bin = b.id) WHERE ba.suite = %d) s JOIN dsc_files df ON (s.source = df.source) JOIN files f ON (df.file = f.id) JOIN location l ON (f.location = l.id)\n' $1 $1 | psql -F' ' -A -t
+	local query
+	query="$(printf 'SELECT DISTINCT l.path, f.filename FROM (SELECT sa.source AS source FROM src_associations sa WHERE sa.suite = %d UNION SELECT b.source AS source FROM bin_associations ba JOIN binaries b ON (ba.bin = b.id) WHERE ba.suite = %d) s JOIN dsc_files df ON (s.source = df.source) JOIN files f ON (df.file = f.id) JOIN location l ON (f.location = l.id)' $1 $1)"
+	psql -F' ' -A -t -c "$query"
 
-        printf 'SELECT l.path, f.filename FROM bin_associations ba JOIN binaries b ON (ba.bin = b.id) JOIN files f ON (b.file = f.id) JOIN location l ON (f.location = l.id) WHERE ba.suite = %d\n' $1 | psql -F' ' -A -t
+	query="$(printf 'SELECT l.path, f.filename FROM bin_associations ba JOIN binaries b ON (ba.bin = b.id) JOIN files f ON (b.file = f.id) JOIN location l ON (f.location = l.id) WHERE ba.suite = %d' $1)"
+	psql -F' ' -A -t -c "$query"
     }
 
-    printf 'SELECT id, suite_name FROM suite\n' | psql -F' ' -At |
+    psql -F' ' -At -c "SELECT id, suite_name FROM suite" |
     while read id suite; do
         [ -e $base/ftp/dists/$suite ] || continue
         (
-- 
1.7.2.5



Reply to: