Consolidate cross-option checks in pg_restore
authorMichael Paquier <michael@paquier.xyz>
Tue, 30 Oct 2018 02:38:35 +0000 (11:38 +0900)
committerMichael Paquier <michael@paquier.xyz>
Tue, 30 Oct 2018 02:38:35 +0000 (11:38 +0900)
This moves one check for conflicting options from the archive restore
code to the main function where other similar checks are performed.
Also reword the error message to be consistent with other messages.

The only option combination impacted is --create specified with
--single-transaction, and informing the caller at an early step saves
from opening the archive worked on.  A TAP test is added for this
combination.

Author: Daniel Gustafsson
Reviewed-by: Fabien Coelho
Discussion: https://postgr.es/m/616808BD-4B59-4E6C-97A9-7317F62D5570@yesql.se

src/bin/pg_dump/pg_backup_archiver.c
src/bin/pg_dump/pg_restore.c
src/bin/pg_dump/t/001_basic.pl

index e976def42aa452588ff8f82f6a120c08bd7b2032..defa8a41b774fdd18e33b7189eda40248d968f75 100644 (file)
@@ -358,15 +358,6 @@ RestoreArchive(Archive *AHX)
 
        AH->stage = STAGE_INITIALIZING;
 
-       /*
-        * Check for nonsensical option combinations.
-        *
-        * -C is not compatible with -1, because we can't create a database inside
-        * a transaction block.
-        */
-       if (ropt->createDB && ropt->single_txn)
-               exit_horribly(modulename, "-C and -1 are incompatible options\n");
-
        /*
         * If we're going to do parallel restore, there are some restrictions.
         */
index 34d93ab472b0378641334d2baffb3abf84f03823..44012ff44d16922a7ccd399948eac1b4e6c0de37 100644 (file)
@@ -331,6 +331,17 @@ main(int argc, char **argv)
                exit_nicely(1);
        }
 
+       /*
+        * -C is not compatible with -1, because we can't create a database inside
+        * a transaction block.
+        */
+       if (opts->createDB && opts->single_txn)
+       {
+               fprintf(stderr, _("%s: options -C/--create and -1/--single-transaction cannot be used together\n"),
+                               progname);
+               exit_nicely(1);
+       }
+
        if (numWorkers <= 0)
        {
                fprintf(stderr, _("%s: invalid number of parallel jobs\n"), progname);
index 17edf444b2599e48a76970beea610bb4ee473248..de00dbca39244b376cd088236d4c59115c5cafe4 100644 (file)
@@ -4,7 +4,7 @@ use warnings;
 use Config;
 use PostgresNode;
 use TestLib;
-use Test::More tests => 70;
+use Test::More tests => 72;
 
 my $tempdir       = TestLib::tempdir;
 my $tempdir_short = TestLib::tempdir_short;
@@ -150,3 +150,9 @@ command_fails_like(
        [ 'pg_dumpall', '--if-exists' ],
        qr/\Qpg_dumpall: option --if-exists requires option -c\/--clean\E/,
        'pg_dumpall: option --if-exists requires option -c/--clean');
+
+command_fails_like(
+       [ 'pg_restore', '-C', '-1' ],
+       qr/\Qpg_restore: options -C\/--create and -1\/--single-transaction cannot be used together\E/,
+       'pg_restore: options -C\/--create and -1\/--single-transaction cannot be used together'
+);