Commit 3b64171e authored by Tom Lane's avatar Tom Lane

Complain if pg_restore is given both -d and -f options; this suggests

the user is confused about whether -f is input or output file.
parent 1df7a455
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.78 2003/10/03 20:10:59 tgl Exp $ * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.79 2003/10/20 21:05:11 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -381,7 +381,7 @@ RestoreArchive(Archive *AHX, RestoreOptions *ropt) ...@@ -381,7 +381,7 @@ RestoreArchive(Archive *AHX, RestoreOptions *ropt)
/* /*
* Clean up & we're done. * Clean up & we're done.
*/ */
if (ropt->filename) if (ropt->filename || ropt->compression)
ResetOutput(AH, sav); ResetOutput(AH, sav);
if (ropt->useDB) if (ropt->useDB)
...@@ -596,7 +596,7 @@ PrintTOCSummary(Archive *AHX, RestoreOptions *ropt) ...@@ -596,7 +596,7 @@ PrintTOCSummary(Archive *AHX, RestoreOptions *ropt)
char *fmtName; char *fmtName;
if (ropt->filename) if (ropt->filename)
sav = SetOutput(AH, ropt->filename, ropt->compression); sav = SetOutput(AH, ropt->filename, 0 /* no compression */);
ahprintf(AH, ";\n; Archive created at %s", ctime(&AH->createDate)); ahprintf(AH, ";\n; Archive created at %s", ctime(&AH->createDate));
ahprintf(AH, "; dbname: %s\n; TOC Entries: %d\n; Compression: %d\n", ahprintf(AH, "; dbname: %s\n; TOC Entries: %d\n; Compression: %d\n",
...@@ -1039,23 +1039,19 @@ OutputContext ...@@ -1039,23 +1039,19 @@ OutputContext
SetOutput(ArchiveHandle *AH, char *filename, int compression) SetOutput(ArchiveHandle *AH, char *filename, int compression)
{ {
OutputContext sav; OutputContext sav;
int fn;
#ifdef HAVE_LIBZ
char fmode[10];
#endif
int fn = 0;
/* Replace the AH output file handle */ /* Replace the AH output file handle */
sav.OF = AH->OF; sav.OF = AH->OF;
sav.gzOut = AH->gzOut; sav.gzOut = AH->gzOut;
if (filename) if (filename)
fn = 0; 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)
{ {
fn = 0; fn = -1;
filename = AH->fSpec; filename = AH->fSpec;
} }
else else
...@@ -1065,27 +1061,25 @@ SetOutput(ArchiveHandle *AH, char *filename, int compression) ...@@ -1065,27 +1061,25 @@ SetOutput(ArchiveHandle *AH, char *filename, int compression)
#ifdef HAVE_LIBZ #ifdef HAVE_LIBZ
if (compression != 0) if (compression != 0)
{ {
char fmode[10];
/* Don't use PG_BINARY_x since this is zlib */
sprintf(fmode, "wb%d", compression); sprintf(fmode, "wb%d", compression);
if (fn) if (fn >= 0)
{ AH->OF = gzdopen(dup(fn), fmode);
AH->OF = gzdopen(dup(fn), fmode); /* Don't use PG_BINARY_x
* since this is zlib */
}
else else
AH->OF = gzopen(filename, fmode); AH->OF = gzopen(filename, fmode);
AH->gzOut = 1; AH->gzOut = 1;
} }
else else
{ /* Use fopen */
#endif #endif
if (fn) { /* Use fopen */
if (fn >= 0)
AH->OF = fdopen(dup(fn), PG_BINARY_W); AH->OF = fdopen(dup(fn), PG_BINARY_W);
else else
AH->OF = fopen(filename, PG_BINARY_W); AH->OF = fopen(filename, PG_BINARY_W);
AH->gzOut = 0; AH->gzOut = 0;
#ifdef HAVE_LIBZ
} }
#endif
if (!AH->OF) if (!AH->OF)
die_horribly(AH, modulename, "could not open output file: %s\n", strerror(errno)); die_horribly(AH, modulename, "could not open output file: %s\n", strerror(errno));
...@@ -1104,7 +1098,8 @@ ResetOutput(ArchiveHandle *AH, OutputContext sav) ...@@ -1104,7 +1098,8 @@ ResetOutput(ArchiveHandle *AH, OutputContext sav)
res = fclose(AH->OF); res = fclose(AH->OF);
if (res != 0) if (res != 0)
die_horribly(AH, modulename, "could not close output file: %s\n", strerror(errno)); die_horribly(AH, modulename, "could not close output file: %s\n",
strerror(errno));
AH->gzOut = sav.gzOut; AH->gzOut = sav.gzOut;
AH->OF = sav.OF; AH->OF = sav.OF;
......
...@@ -34,7 +34,7 @@ ...@@ -34,7 +34,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_restore.c,v 1.52 2003/09/23 22:48:53 tgl Exp $ * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_restore.c,v 1.53 2003/10/20 21:05:12 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -78,7 +78,7 @@ main(int argc, char **argv) ...@@ -78,7 +78,7 @@ main(int argc, char **argv)
RestoreOptions *opts; RestoreOptions *opts;
int c; int c;
Archive *AH; Archive *AH;
char *fileSpec = NULL; char *inputFileSpec;
extern int optind; extern int optind;
extern char *optarg; extern char *optarg;
static int use_setsessauth = 0; static int use_setsessauth = 0;
...@@ -163,11 +163,7 @@ main(int argc, char **argv) ...@@ -163,11 +163,7 @@ main(int argc, char **argv)
opts->create = 1; opts->create = 1;
break; break;
case 'd': case 'd':
if (strlen(optarg) != 0) opts->dbname = strdup(optarg);
{
opts->dbname = strdup(optarg);
opts->useDB = 1;
}
break; break;
case 'f': /* output file name */ case 'f': /* output file name */
opts->filename = strdup(optarg); opts->filename = strdup(optarg);
...@@ -286,9 +282,23 @@ main(int argc, char **argv) ...@@ -286,9 +282,23 @@ main(int argc, char **argv)
} }
if (optind < argc) if (optind < argc)
fileSpec = argv[optind]; inputFileSpec = argv[optind];
else else
fileSpec = NULL; inputFileSpec = NULL;
/* Should get at most one of -d and -f, else user is confused */
if (opts->dbname)
{
if (opts->filename)
{
fprintf(stderr, _("%s: cannot specify both -d and -f output\n"),
progname);
fprintf(stderr, _("Try \"%s --help\" for more information.\n"),
progname);
exit(1);
}
opts->useDB = 1;
}
opts->disable_triggers = disable_triggers; opts->disable_triggers = disable_triggers;
...@@ -320,7 +330,7 @@ main(int argc, char **argv) ...@@ -320,7 +330,7 @@ main(int argc, char **argv)
} }
} }
AH = OpenArchive(fileSpec, opts->format); AH = OpenArchive(inputFileSpec, opts->format);
/* Let the archiver know how noisy to be */ /* Let the archiver know how noisy to be */
AH->verbose = opts->verbose; AH->verbose = opts->verbose;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment