Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3b64171

Browse files
committed
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.
1 parent1df7a45 commit3b64171

File tree

2 files changed

+35
-30
lines changed

2 files changed

+35
-30
lines changed

‎src/bin/pg_dump/pg_backup_archiver.c

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*
1616
*
1717
* IDENTIFICATION
18-
*$Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.78 2003/10/03 20:10:59 tgl Exp $
18+
*$Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.79 2003/10/20 21:05:11 tgl Exp $
1919
*
2020
*-------------------------------------------------------------------------
2121
*/
@@ -381,7 +381,7 @@ RestoreArchive(Archive *AHX, RestoreOptions *ropt)
381381
/*
382382
* Clean up & we're done.
383383
*/
384-
if (ropt->filename)
384+
if (ropt->filename||ropt->compression)
385385
ResetOutput(AH,sav);
386386

387387
if (ropt->useDB)
@@ -596,7 +596,7 @@ PrintTOCSummary(Archive *AHX, RestoreOptions *ropt)
596596
char*fmtName;
597597

598598
if (ropt->filename)
599-
sav=SetOutput(AH,ropt->filename,ropt->compression);
599+
sav=SetOutput(AH,ropt->filename,0/* nocompression */);
600600

601601
ahprintf(AH,";\n; Archive created at %s",ctime(&AH->createDate));
602602
ahprintf(AH,"; dbname: %s\n; TOC Entries: %d\n; Compression: %d\n",
@@ -1039,23 +1039,19 @@ OutputContext
10391039
SetOutput(ArchiveHandle*AH,char*filename,intcompression)
10401040
{
10411041
OutputContextsav;
1042-
1043-
#ifdefHAVE_LIBZ
1044-
charfmode[10];
1045-
#endif
1046-
intfn=0;
1042+
intfn;
10471043

10481044
/* Replace the AH output file handle */
10491045
sav.OF=AH->OF;
10501046
sav.gzOut=AH->gzOut;
10511047

10521048
if (filename)
1053-
fn=0;
1049+
fn=-1;
10541050
elseif (AH->FH)
10551051
fn=fileno(AH->FH);
10561052
elseif (AH->fSpec)
10571053
{
1058-
fn=0;
1054+
fn=-1;
10591055
filename=AH->fSpec;
10601056
}
10611057
else
@@ -1065,27 +1061,25 @@ SetOutput(ArchiveHandle *AH, char *filename, int compression)
10651061
#ifdefHAVE_LIBZ
10661062
if (compression!=0)
10671063
{
1064+
charfmode[10];
1065+
1066+
/* Don't use PG_BINARY_x since this is zlib */
10681067
sprintf(fmode,"wb%d",compression);
1069-
if (fn)
1070-
{
1071-
AH->OF=gzdopen(dup(fn),fmode);/* Don't use PG_BINARY_x
1072-
* since this is zlib */
1073-
}
1068+
if (fn >=0)
1069+
AH->OF=gzdopen(dup(fn),fmode);
10741070
else
10751071
AH->OF=gzopen(filename,fmode);
10761072
AH->gzOut=1;
10771073
}
10781074
else
1079-
{/* Use fopen */
10801075
#endif
1081-
if (fn)
1076+
{/* Use fopen */
1077+
if (fn >=0)
10821078
AH->OF=fdopen(dup(fn),PG_BINARY_W);
10831079
else
10841080
AH->OF=fopen(filename,PG_BINARY_W);
10851081
AH->gzOut=0;
1086-
#ifdefHAVE_LIBZ
10871082
}
1088-
#endif
10891083

10901084
if (!AH->OF)
10911085
die_horribly(AH,modulename,"could not open output file: %s\n",strerror(errno));
@@ -1104,7 +1098,8 @@ ResetOutput(ArchiveHandle *AH, OutputContext sav)
11041098
res=fclose(AH->OF);
11051099

11061100
if (res!=0)
1107-
die_horribly(AH,modulename,"could not close output file: %s\n",strerror(errno));
1101+
die_horribly(AH,modulename,"could not close output file: %s\n",
1102+
strerror(errno));
11081103

11091104
AH->gzOut=sav.gzOut;
11101105
AH->OF=sav.OF;

‎src/bin/pg_dump/pg_restore.c

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
*
3535
*
3636
* IDENTIFICATION
37-
*$Header: /cvsroot/pgsql/src/bin/pg_dump/pg_restore.c,v 1.52 2003/09/23 22:48:53 tgl Exp $
37+
*$Header: /cvsroot/pgsql/src/bin/pg_dump/pg_restore.c,v 1.53 2003/10/20 21:05:12 tgl Exp $
3838
*
3939
*-------------------------------------------------------------------------
4040
*/
@@ -78,7 +78,7 @@ main(int argc, char **argv)
7878
RestoreOptions*opts;
7979
intc;
8080
Archive*AH;
81-
char*fileSpec=NULL;
81+
char*inputFileSpec;
8282
externintoptind;
8383
externchar*optarg;
8484
staticintuse_setsessauth=0;
@@ -163,11 +163,7 @@ main(int argc, char **argv)
163163
opts->create=1;
164164
break;
165165
case'd':
166-
if (strlen(optarg)!=0)
167-
{
168-
opts->dbname=strdup(optarg);
169-
opts->useDB=1;
170-
}
166+
opts->dbname=strdup(optarg);
171167
break;
172168
case'f':/* output file name */
173169
opts->filename=strdup(optarg);
@@ -286,9 +282,23 @@ main(int argc, char **argv)
286282
}
287283

288284
if (optind<argc)
289-
fileSpec=argv[optind];
285+
inputFileSpec=argv[optind];
290286
else
291-
fileSpec=NULL;
287+
inputFileSpec=NULL;
288+
289+
/* Should get at most one of -d and -f, else user is confused */
290+
if (opts->dbname)
291+
{
292+
if (opts->filename)
293+
{
294+
fprintf(stderr,_("%s: cannot specify both -d and -f output\n"),
295+
progname);
296+
fprintf(stderr,_("Try \"%s --help\" for more information.\n"),
297+
progname);
298+
exit(1);
299+
}
300+
opts->useDB=1;
301+
}
292302

293303
opts->disable_triggers=disable_triggers;
294304

@@ -320,7 +330,7 @@ main(int argc, char **argv)
320330
}
321331
}
322332

323-
AH=OpenArchive(fileSpec,opts->format);
333+
AH=OpenArchive(inputFileSpec,opts->format);
324334

325335
/* Let the archiver know how noisy to be */
326336
AH->verbose=opts->verbose;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp