diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2007-10-28 21:55:52 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2007-10-28 21:55:52 +0000 |
commit | 27c033ed98d0ed8ee05caf440ae648f42fa5f9d6 (patch) | |
tree | 5e4bda42662ec4fb2237e3ee25b5bd0b3e97f452 /src/bin/pg_dump/pg_backup_files.c | |
parent | 006f42c74d46505b2b4dc753be25c91b0f9efec5 (diff) |
Make pg_dump and friends consistently report both the filename and the
errno string when complaining of fopen failures. Per gripe from Bob
Pawley, it's not always instantly obvious to the user which name we
tried to open.
Diffstat (limited to 'src/bin/pg_dump/pg_backup_files.c')
-rw-r--r-- | src/bin/pg_dump/pg_backup_files.c | 37 |
1 files changed, 27 insertions, 10 deletions
diff --git a/src/bin/pg_dump/pg_backup_files.c b/src/bin/pg_dump/pg_backup_files.c index 6520ca227aa..47a4ddd77cb 100644 --- a/src/bin/pg_dump/pg_backup_files.c +++ b/src/bin/pg_dump/pg_backup_files.c @@ -20,7 +20,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_files.c,v 1.33 2007/08/06 01:38:15 tgl Exp $ + * $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_files.c,v 1.34 2007/10/28 21:55:52 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -121,12 +121,19 @@ InitArchiveFmt_Files(ArchiveHandle *AH) " normal use. Files will be written in the current working directory.\n"); if (AH->fSpec && strcmp(AH->fSpec, "") != 0) + { AH->FH = fopen(AH->fSpec, PG_BINARY_W); + if (AH->FH == NULL) + die_horribly(NULL, modulename, "could not open output file \"%s\": %s\n", + AH->fSpec, strerror(errno)); + } else + { AH->FH = stdout; - - if (AH->FH == NULL) - die_horribly(NULL, modulename, "could not open output file: %s\n", strerror(errno)); + if (AH->FH == NULL) + die_horribly(NULL, modulename, "could not open output file: %s\n", + strerror(errno)); + } ctx->hasSeek = checkSeek(AH->FH); @@ -139,12 +146,19 @@ InitArchiveFmt_Files(ArchiveHandle *AH) { /* Read Mode */ if (AH->fSpec && strcmp(AH->fSpec, "") != 0) + { AH->FH = fopen(AH->fSpec, PG_BINARY_R); + if (AH->FH == NULL) + die_horribly(NULL, modulename, "could not open input file \"%s\": %s\n", + AH->fSpec, strerror(errno)); + } else + { AH->FH = stdin; - - if (AH->FH == NULL) - die_horribly(NULL, modulename, "could not open input file: %s\n", strerror(errno)); + if (AH->FH == NULL) + die_horribly(NULL, modulename, "could not open input file: %s\n", + strerror(errno)); + } ctx->hasSeek = checkSeek(AH->FH); @@ -242,7 +256,8 @@ _StartData(ArchiveHandle *AH, TocEntry *te) #endif if (tctx->FH == NULL) - die_horribly(AH, modulename, "could not open output file: %s\n", strerror(errno)); + die_horribly(AH, modulename, "could not open output file \"%s\": %s\n", + tctx->filename, strerror(errno)); } static size_t @@ -286,7 +301,8 @@ _PrintFileData(ArchiveHandle *AH, char *filename, RestoreOptions *ropt) #endif if (AH->FH == NULL) - die_horribly(AH, modulename, "could not open input file: %s\n", strerror(errno)); + die_horribly(AH, modulename, "could not open input file \"%s\": %s\n", + filename, strerror(errno)); while ((cnt = GZREAD(buf, 1, 4095, AH->FH)) > 0) { @@ -507,7 +523,8 @@ _StartBlob(ArchiveHandle *AH, TocEntry *te, Oid oid) #endif if (tctx->FH == NULL) - die_horribly(AH, modulename, "could not open large object file for input: %s\n", strerror(errno)); + die_horribly(AH, modulename, "could not open large object file \"%s\" for input: %s\n", + fname, strerror(errno)); } /* |