mirror of
https://git.postgresql.org/git/postgresql.git
synced 2024-08-24 07:57:18 +02:00
pg_restore: Require "-f -" to mean stdout
The previous convention that stdout was selected by default when nothing is specified was just too error-prone. After a suggestion from Andrew Gierth. Author: Euler Taveira Reviewed-by: Yoshikazu Imai, José Arthur Benetasso Villanova Discussion: https://postgr.es/m/87sgwrmhdv.fsf@news-spur.riddles.org.uk
This commit is contained in:
parent
9c703c169a
commit
413ccaa74d
@ -176,8 +176,8 @@
|
|||||||
<listitem>
|
<listitem>
|
||||||
<para>
|
<para>
|
||||||
Specify output file for generated script, or for the listing
|
Specify output file for generated script, or for the listing
|
||||||
when used with <option>-l</option>. Default is the standard
|
when used with <option>-l</option>. Use <literal>-</literal>
|
||||||
output.
|
for <systemitem>stdout</systemitem>.
|
||||||
</para>
|
</para>
|
||||||
</listitem>
|
</listitem>
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
|
@ -1512,7 +1512,12 @@ SetOutput(ArchiveHandle *AH, const char *filename, int compression)
|
|||||||
int fn;
|
int fn;
|
||||||
|
|
||||||
if (filename)
|
if (filename)
|
||||||
|
{
|
||||||
|
if (strcmp(filename, "-") == 0)
|
||||||
|
fn = fileno(stdout);
|
||||||
|
else
|
||||||
fn = -1;
|
fn = -1;
|
||||||
|
}
|
||||||
else if (AH->FH)
|
else if (AH->FH)
|
||||||
fn = fileno(AH->FH);
|
fn = fileno(AH->FH);
|
||||||
else if (AH->fSpec)
|
else if (AH->fSpec)
|
||||||
|
@ -306,6 +306,13 @@ main(int argc, char **argv)
|
|||||||
exit_nicely(1);
|
exit_nicely(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Complain if neither -f nor -d was specified (except if dumping TOC) */
|
||||||
|
if (!opts->dbname && !opts->filename && !opts->tocSummary)
|
||||||
|
{
|
||||||
|
pg_log_error("one of -d/--dbname and -f/--file must be specified");
|
||||||
|
exit_nicely(1);
|
||||||
|
}
|
||||||
|
|
||||||
/* Should get at most one of -d and -f, else user is confused */
|
/* Should get at most one of -d and -f, else user is confused */
|
||||||
if (opts->dbname)
|
if (opts->dbname)
|
||||||
{
|
{
|
||||||
@ -461,7 +468,7 @@ usage(const char *progname)
|
|||||||
|
|
||||||
printf(_("\nGeneral options:\n"));
|
printf(_("\nGeneral options:\n"));
|
||||||
printf(_(" -d, --dbname=NAME connect to database name\n"));
|
printf(_(" -d, --dbname=NAME connect to database name\n"));
|
||||||
printf(_(" -f, --file=FILENAME output file name\n"));
|
printf(_(" -f, --file=FILENAME output file name (- for stdout)\n"));
|
||||||
printf(_(" -F, --format=c|d|t backup file format (should be automatic)\n"));
|
printf(_(" -F, --format=c|d|t backup file format (should be automatic)\n"));
|
||||||
printf(_(" -l, --list print summarized TOC of the archive\n"));
|
printf(_(" -l, --list print summarized TOC of the archive\n"));
|
||||||
printf(_(" -v, --verbose verbose mode\n"));
|
printf(_(" -v, --verbose verbose mode\n"));
|
||||||
|
@ -4,7 +4,7 @@ use warnings;
|
|||||||
use Config;
|
use Config;
|
||||||
use PostgresNode;
|
use PostgresNode;
|
||||||
use TestLib;
|
use TestLib;
|
||||||
use Test::More tests => 72;
|
use Test::More tests => 74;
|
||||||
|
|
||||||
my $tempdir = TestLib::tempdir;
|
my $tempdir = TestLib::tempdir;
|
||||||
my $tempdir_short = TestLib::tempdir_short;
|
my $tempdir_short = TestLib::tempdir_short;
|
||||||
@ -50,7 +50,13 @@ command_fails_like(
|
|||||||
);
|
);
|
||||||
|
|
||||||
command_fails_like(
|
command_fails_like(
|
||||||
[ 'pg_restore', '-s', '-a' ],
|
[ 'pg_restore' ],
|
||||||
|
qr{\Qpg_restore: error: one of -d/--dbname and -f/--file must be specified\E},
|
||||||
|
'pg_restore: error: one of -d/--dbname and -f/--file must be specified'
|
||||||
|
);
|
||||||
|
|
||||||
|
command_fails_like(
|
||||||
|
[ 'pg_restore', '-s', '-a', '-f -' ],
|
||||||
qr/\Qpg_restore: error: options -s\/--schema-only and -a\/--data-only cannot be used together\E/,
|
qr/\Qpg_restore: error: options -s\/--schema-only and -a\/--data-only cannot be used together\E/,
|
||||||
'pg_restore: options -s/--schema-only and -a/--data-only cannot be used together'
|
'pg_restore: options -s/--schema-only and -a/--data-only cannot be used together'
|
||||||
);
|
);
|
||||||
@ -66,7 +72,7 @@ command_fails_like(
|
|||||||
'pg_dump: options -c/--clean and -a/--data-only cannot be used together');
|
'pg_dump: options -c/--clean and -a/--data-only cannot be used together');
|
||||||
|
|
||||||
command_fails_like(
|
command_fails_like(
|
||||||
[ 'pg_restore', '-c', '-a' ],
|
[ 'pg_restore', '-c', '-a', '-f -' ],
|
||||||
qr/\Qpg_restore: error: options -c\/--clean and -a\/--data-only cannot be used together\E/,
|
qr/\Qpg_restore: error: options -c\/--clean and -a\/--data-only cannot be used together\E/,
|
||||||
'pg_restore: options -c/--clean and -a/--data-only cannot be used together'
|
'pg_restore: options -c/--clean and -a/--data-only cannot be used together'
|
||||||
);
|
);
|
||||||
@ -92,12 +98,12 @@ command_fails_like(
|
|||||||
'pg_dump: invalid output format');
|
'pg_dump: invalid output format');
|
||||||
|
|
||||||
command_fails_like(
|
command_fails_like(
|
||||||
[ 'pg_restore', '-j', '-1' ],
|
[ 'pg_restore', '-j', '-1', '-f -' ],
|
||||||
qr/\Qpg_restore: error: invalid number of parallel jobs\E/,
|
qr/\Qpg_restore: error: invalid number of parallel jobs\E/,
|
||||||
'pg_restore: invalid number of parallel jobs');
|
'pg_restore: invalid number of parallel jobs');
|
||||||
|
|
||||||
command_fails_like(
|
command_fails_like(
|
||||||
[ 'pg_restore', '--single-transaction', '-j3' ],
|
[ 'pg_restore', '--single-transaction', '-j3', '-f -' ],
|
||||||
qr/\Qpg_restore: error: cannot specify both --single-transaction and multiple jobs\E/,
|
qr/\Qpg_restore: error: cannot specify both --single-transaction and multiple jobs\E/,
|
||||||
'pg_restore: cannot specify both --single-transaction and multiple jobs');
|
'pg_restore: cannot specify both --single-transaction and multiple jobs');
|
||||||
|
|
||||||
@ -107,12 +113,12 @@ command_fails_like(
|
|||||||
'pg_dump: compression level must be in range 0..9');
|
'pg_dump: compression level must be in range 0..9');
|
||||||
|
|
||||||
command_fails_like(
|
command_fails_like(
|
||||||
[ 'pg_restore', '--if-exists' ],
|
[ 'pg_restore', '--if-exists', '-f -' ],
|
||||||
qr/\Qpg_restore: error: option --if-exists requires option -c\/--clean\E/,
|
qr/\Qpg_restore: error: option --if-exists requires option -c\/--clean\E/,
|
||||||
'pg_restore: option --if-exists requires option -c/--clean');
|
'pg_restore: option --if-exists requires option -c/--clean');
|
||||||
|
|
||||||
command_fails_like(
|
command_fails_like(
|
||||||
[ 'pg_restore', '-F', 'garbage' ],
|
[ 'pg_restore', '-f -', '-F', 'garbage' ],
|
||||||
qr/\Qpg_restore: error: unrecognized archive format "garbage";\E/,
|
qr/\Qpg_restore: error: unrecognized archive format "garbage";\E/,
|
||||||
'pg_dump: unrecognized archive format');
|
'pg_dump: unrecognized archive format');
|
||||||
|
|
||||||
@ -146,7 +152,7 @@ command_fails_like(
|
|||||||
'pg_dumpall: option --if-exists requires option -c/--clean');
|
'pg_dumpall: option --if-exists requires option -c/--clean');
|
||||||
|
|
||||||
command_fails_like(
|
command_fails_like(
|
||||||
[ 'pg_restore', '-C', '-1' ],
|
[ 'pg_restore', '-C', '-1', '-f -' ],
|
||||||
qr/\Qpg_restore: error: options -C\/--create and -1\/--single-transaction cannot be used together\E/,
|
qr/\Qpg_restore: error: 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'
|
'pg_restore: options -C\/--create and -1\/--single-transaction cannot be used together'
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user