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

Commit27c033e

Browse files
committed
Make pg_dump and friends consistently report both the filename and the
errno string when complaining of fopen failures. Per gripe from BobPawley, it's not always instantly obvious to the user which name wetried to open.
1 parent006f42c commit27c033e

File tree

5 files changed

+95
-38
lines changed

5 files changed

+95
-38
lines changed

‎src/bin/pg_dump/pg_backup_archiver.c

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*
1616
*
1717
* IDENTIFICATION
18-
*$PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.147 2007/10/13 20:18:41 tgl Exp $
18+
*$PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.148 2007/10/28 21:55:52 tgl Exp $
1919
*
2020
*-------------------------------------------------------------------------
2121
*/
@@ -799,8 +799,8 @@ SortTocFromFile(Archive *AHX, RestoreOptions *ropt)
799799
/* Setup the file */
800800
fh=fopen(ropt->tocFile,PG_BINARY_R);
801801
if (!fh)
802-
die_horribly(AH,modulename,"could not open TOC file: %s\n",
803-
strerror(errno));
802+
die_horribly(AH,modulename,"could not open TOC file \"%s\": %s\n",
803+
ropt->tocFile,strerror(errno));
804804

805805
while (fgets(buf,sizeof(buf),fh)!=NULL)
806806
{
@@ -957,7 +957,14 @@ SetOutput(ArchiveHandle *AH, char *filename, int compression)
957957
}
958958

959959
if (!AH->OF)
960-
die_horribly(AH,modulename,"could not open output file: %s\n",strerror(errno));
960+
{
961+
if (filename)
962+
die_horribly(AH,modulename,"could not open output file \"%s\": %s\n",
963+
filename,strerror(errno));
964+
else
965+
die_horribly(AH,modulename,"could not open output file: %s\n",
966+
strerror(errno));
967+
}
961968

962969
returnsav;
963970
}
@@ -1512,12 +1519,17 @@ _discoverArchiveFormat(ArchiveHandle *AH)
15121519
{
15131520
wantClose=1;
15141521
fh=fopen(AH->fSpec,PG_BINARY_R);
1522+
if (!fh)
1523+
die_horribly(AH,modulename,"could not open input file \"%s\": %s\n",
1524+
AH->fSpec,strerror(errno));
15151525
}
15161526
else
1527+
{
15171528
fh=stdin;
1518-
1519-
if (!fh)
1520-
die_horribly(AH,modulename,"could not open input file: %s\n",strerror(errno));
1529+
if (!fh)
1530+
die_horribly(AH,modulename,"could not open input file: %s\n",
1531+
strerror(errno));
1532+
}
15211533

15221534
cnt=fread(sig,1,5,fh);
15231535

‎src/bin/pg_dump/pg_backup_custom.c

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
*
2020
*
2121
* IDENTIFICATION
22-
*$PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_custom.c,v 1.39 2007/08/06 01:38:14 tgl Exp $
22+
*$PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_custom.c,v 1.40 2007/10/28 21:55:52 tgl Exp $
2323
*
2424
*-------------------------------------------------------------------------
2525
*/
@@ -169,23 +169,38 @@ InitArchiveFmt_Custom(ArchiveHandle *AH)
169169
if (AH->mode==archModeWrite)
170170
{
171171
if (AH->fSpec&&strcmp(AH->fSpec,"")!=0)
172+
{
172173
AH->FH=fopen(AH->fSpec,PG_BINARY_W);
174+
if (!AH->FH)
175+
die_horribly(AH,modulename,"could not open output file \"%s\": %s\n",
176+
AH->fSpec,strerror(errno));
177+
}
173178
else
179+
{
174180
AH->FH=stdout;
175-
176-
if (!AH->FH)
177-
die_horribly(AH,modulename,"could not open output file \"%s\": %s\n",AH->fSpec,strerror(errno));
181+
if (!AH->FH)
182+
die_horribly(AH,modulename,"could not open output file: %s\n",
183+
strerror(errno));
184+
}
178185

179186
ctx->hasSeek=checkSeek(AH->FH);
180187
}
181188
else
182189
{
183190
if (AH->fSpec&&strcmp(AH->fSpec,"")!=0)
191+
{
184192
AH->FH=fopen(AH->fSpec,PG_BINARY_R);
193+
if (!AH->FH)
194+
die_horribly(AH,modulename,"could not open input file \"%s\": %s\n",
195+
AH->fSpec,strerror(errno));
196+
}
185197
else
198+
{
186199
AH->FH=stdin;
187-
if (!AH->FH)
188-
die_horribly(AH,modulename,"could not open input file \"%s\": %s\n",AH->fSpec,strerror(errno));
200+
if (!AH->FH)
201+
die_horribly(AH,modulename,"could not open input file: %s\n",
202+
strerror(errno));
203+
}
189204

190205
ctx->hasSeek=checkSeek(AH->FH);
191206

‎src/bin/pg_dump/pg_backup_files.c

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
*
2121
*
2222
* IDENTIFICATION
23-
*$PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_files.c,v 1.33 2007/08/06 01:38:15 tgl Exp $
23+
*$PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_files.c,v 1.34 2007/10/28 21:55:52 tgl Exp $
2424
*
2525
*-------------------------------------------------------------------------
2626
*/
@@ -121,12 +121,19 @@ InitArchiveFmt_Files(ArchiveHandle *AH)
121121
" normal use. Files will be written in the current working directory.\n");
122122

123123
if (AH->fSpec&&strcmp(AH->fSpec,"")!=0)
124+
{
124125
AH->FH=fopen(AH->fSpec,PG_BINARY_W);
126+
if (AH->FH==NULL)
127+
die_horribly(NULL,modulename,"could not open output file \"%s\": %s\n",
128+
AH->fSpec,strerror(errno));
129+
}
125130
else
131+
{
126132
AH->FH=stdout;
127-
128-
if (AH->FH==NULL)
129-
die_horribly(NULL,modulename,"could not open output file: %s\n",strerror(errno));
133+
if (AH->FH==NULL)
134+
die_horribly(NULL,modulename,"could not open output file: %s\n",
135+
strerror(errno));
136+
}
130137

131138
ctx->hasSeek=checkSeek(AH->FH);
132139

@@ -139,12 +146,19 @@ InitArchiveFmt_Files(ArchiveHandle *AH)
139146
{/* Read Mode */
140147

141148
if (AH->fSpec&&strcmp(AH->fSpec,"")!=0)
149+
{
142150
AH->FH=fopen(AH->fSpec,PG_BINARY_R);
151+
if (AH->FH==NULL)
152+
die_horribly(NULL,modulename,"could not open input file \"%s\": %s\n",
153+
AH->fSpec,strerror(errno));
154+
}
143155
else
156+
{
144157
AH->FH=stdin;
145-
146-
if (AH->FH==NULL)
147-
die_horribly(NULL,modulename,"could not open input file: %s\n",strerror(errno));
158+
if (AH->FH==NULL)
159+
die_horribly(NULL,modulename,"could not open input file: %s\n",
160+
strerror(errno));
161+
}
148162

149163
ctx->hasSeek=checkSeek(AH->FH);
150164

@@ -242,7 +256,8 @@ _StartData(ArchiveHandle *AH, TocEntry *te)
242256
#endif
243257

244258
if (tctx->FH==NULL)
245-
die_horribly(AH,modulename,"could not open output file: %s\n",strerror(errno));
259+
die_horribly(AH,modulename,"could not open output file \"%s\": %s\n",
260+
tctx->filename,strerror(errno));
246261
}
247262

248263
staticsize_t
@@ -286,7 +301,8 @@ _PrintFileData(ArchiveHandle *AH, char *filename, RestoreOptions *ropt)
286301
#endif
287302

288303
if (AH->FH==NULL)
289-
die_horribly(AH,modulename,"could not open input file: %s\n",strerror(errno));
304+
die_horribly(AH,modulename,"could not open input file \"%s\": %s\n",
305+
filename,strerror(errno));
290306

291307
while ((cnt=GZREAD(buf,1,4095,AH->FH))>0)
292308
{
@@ -507,7 +523,8 @@ _StartBlob(ArchiveHandle *AH, TocEntry *te, Oid oid)
507523
#endif
508524

509525
if (tctx->FH==NULL)
510-
die_horribly(AH,modulename,"could not open large object file for input: %s\n",strerror(errno));
526+
die_horribly(AH,modulename,"could not open large object file \"%s\" for input: %s\n",
527+
fname,strerror(errno));
511528
}
512529

513530
/*

‎src/bin/pg_dump/pg_backup_tar.c

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*
1717
*
1818
* IDENTIFICATION
19-
*$PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_tar.c,v 1.60 2007/08/29 16:31:36 tgl Exp $
19+
*$PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_tar.c,v 1.61 2007/10/28 21:55:52 tgl Exp $
2020
*
2121
*-------------------------------------------------------------------------
2222
*/
@@ -172,15 +172,22 @@ InitArchiveFmt_Tar(ArchiveHandle *AH)
172172
*/
173173
if (AH->mode==archModeWrite)
174174
{
175-
176175
if (AH->fSpec&&strcmp(AH->fSpec,"")!=0)
176+
{
177177
ctx->tarFH=fopen(AH->fSpec,PG_BINARY_W);
178+
if (ctx->tarFH==NULL)
179+
die_horribly(NULL,modulename,
180+
"could not open TOC file \"%s\" for output: %s\n",
181+
AH->fSpec,strerror(errno));
182+
}
178183
else
184+
{
179185
ctx->tarFH=stdout;
180-
181-
if (ctx->tarFH==NULL)
182-
die_horribly(NULL,modulename,
183-
"could not open TOC file for output: %s\n",strerror(errno));
186+
if (ctx->tarFH==NULL)
187+
die_horribly(NULL,modulename,
188+
"could not open TOC file for output: %s\n",
189+
strerror(errno));
190+
}
184191

185192
ctx->tarFHpos=0;
186193

@@ -210,14 +217,20 @@ InitArchiveFmt_Tar(ArchiveHandle *AH)
210217
}
211218
else
212219
{/* Read Mode */
213-
214220
if (AH->fSpec&&strcmp(AH->fSpec,"")!=0)
221+
{
215222
ctx->tarFH=fopen(AH->fSpec,PG_BINARY_R);
223+
if (ctx->tarFH==NULL)
224+
die_horribly(NULL,modulename,"could not open TOC file \"%s\" for input: %s\n",
225+
AH->fSpec,strerror(errno));
226+
}
216227
else
228+
{
217229
ctx->tarFH=stdin;
218-
219-
if (ctx->tarFH==NULL)
220-
die_horribly(NULL,modulename,"could not open TOC file for input: %s\n",strerror(errno));
230+
if (ctx->tarFH==NULL)
231+
die_horribly(NULL,modulename,"could not open TOC file for input: %s\n",
232+
strerror(errno));
233+
}
221234

222235
/*
223236
* Make unbuffered since we will dup() it, and the buffers screw each

‎src/bin/pg_dump/pg_dumpall.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Portions Copyright (c) 1994, Regents of the University of California
77
*
88
*
9-
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_dumpall.c,v 1.93 2007/10/13 20:18:41 tgl Exp $
9+
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_dumpall.c,v 1.94 2007/10/28 21:55:52 tgl Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -398,8 +398,8 @@ main(int argc, char *argv[])
398398
OPF=fopen(filename,PG_BINARY_W);
399399
if (!OPF)
400400
{
401-
fprintf(stderr,_("%s: could not open the output file \"%s\"\n"),
402-
progname,filename);
401+
fprintf(stderr,_("%s: could not open the output file \"%s\": %s\n"),
402+
progname,filename,strerror(errno));
403403
exit(1);
404404
}
405405
}
@@ -1210,8 +1210,8 @@ dumpDatabases(PGconn *conn)
12101210
OPF=fopen(filename,PG_BINARY_A);
12111211
if (!OPF)
12121212
{
1213-
fprintf(stderr,_("%s: could not re-open the output file \"%s\"\n"),
1214-
progname,filename);
1213+
fprintf(stderr,_("%s: could not re-open the output file \"%s\": %s\n"),
1214+
progname,filename,strerror(errno));
12151215
exit(1);
12161216
}
12171217
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp