diff options
Diffstat (limited to 'src/bin/pg_dump/pg_backup_directory.c')
-rw-r--r-- | src/bin/pg_dump/pg_backup_directory.c | 72 |
1 files changed, 29 insertions, 43 deletions
diff --git a/src/bin/pg_dump/pg_backup_directory.c b/src/bin/pg_dump/pg_backup_directory.c index e6261252c7f..70eca82c914 100644 --- a/src/bin/pg_dump/pg_backup_directory.c +++ b/src/bin/pg_dump/pg_backup_directory.c @@ -61,9 +61,6 @@ typedef struct char *filename; /* filename excluding the directory (basename) */ } lclTocEntry; -/* translator: this is a module name */ -static const char *modulename = gettext_noop("directory archiver"); - /* prototypes for private functions */ static void _ArchiveEntry(ArchiveHandle *AH, TocEntry *te); static void _StartData(ArchiveHandle *AH, TocEntry *te); @@ -156,7 +153,7 @@ InitArchiveFmt_Directory(ArchiveHandle *AH) */ if (!AH->fSpec || strcmp(AH->fSpec, "") == 0) - exit_horribly(modulename, "no output directory specified\n"); + fatal("no output directory specified"); ctx->directory = AH->fSpec; @@ -185,18 +182,18 @@ InitArchiveFmt_Directory(ArchiveHandle *AH) } if (errno) - exit_horribly(modulename, "could not read directory \"%s\": %s\n", - ctx->directory, strerror(errno)); + fatal("could not read directory \"%s\": %m", + ctx->directory); if (closedir(dir)) - exit_horribly(modulename, "could not close directory \"%s\": %s\n", - ctx->directory, strerror(errno)); + fatal("could not close directory \"%s\": %m", + ctx->directory); } } if (!is_empty && mkdir(ctx->directory, 0700) < 0) - exit_horribly(modulename, "could not create directory \"%s\": %s\n", - ctx->directory, strerror(errno)); + fatal("could not create directory \"%s\": %m", + ctx->directory); } else { /* Read Mode */ @@ -207,9 +204,7 @@ InitArchiveFmt_Directory(ArchiveHandle *AH) tocFH = cfopen_read(fname, PG_BINARY_R); if (tocFH == NULL) - exit_horribly(modulename, - "could not open input file \"%s\": %s\n", - fname, strerror(errno)); + fatal("could not open input file \"%s\": %m", fname); ctx->dataFH = tocFH; @@ -224,8 +219,7 @@ InitArchiveFmt_Directory(ArchiveHandle *AH) /* Nothing else in the file, so close it again... */ if (cfclose(tocFH) != 0) - exit_horribly(modulename, "could not close TOC file: %s\n", - strerror(errno)); + fatal("could not close TOC file: %m"); ctx->dataFH = NULL; } } @@ -335,8 +329,7 @@ _StartData(ArchiveHandle *AH, TocEntry *te) ctx->dataFH = cfopen_write(fname, PG_BINARY_W, AH->compression); if (ctx->dataFH == NULL) - exit_horribly(modulename, "could not open output file \"%s\": %s\n", - fname, strerror(errno)); + fatal("could not open output file \"%s\": %m", fname); } /* @@ -354,7 +347,7 @@ _WriteData(ArchiveHandle *AH, const void *data, size_t dLen) lclContext *ctx = (lclContext *) AH->formatData; if (dLen > 0 && cfwrite(data, dLen, ctx->dataFH) != dLen) - exit_horribly(modulename, "could not write to output file: %s\n", + fatal("could not write to output file: %s", get_cfp_error(ctx->dataFH)); @@ -395,8 +388,7 @@ _PrintFileData(ArchiveHandle *AH, char *filename) cfp = cfopen_read(filename, PG_BINARY_R); if (!cfp) - exit_horribly(modulename, "could not open input file \"%s\": %s\n", - filename, strerror(errno)); + fatal("could not open input file \"%s\": %m", filename); buf = pg_malloc(ZLIB_OUT_SIZE); buflen = ZLIB_OUT_SIZE; @@ -408,8 +400,7 @@ _PrintFileData(ArchiveHandle *AH, char *filename) free(buf); if (cfclose(cfp) !=0) - exit_horribly(modulename, "could not close data file: %s\n", - strerror(errno)); + fatal("could not close data file: %m"); } /* @@ -449,8 +440,8 @@ _LoadBlobs(ArchiveHandle *AH) ctx->blobsTocFH = cfopen_read(fname, PG_BINARY_R); if (ctx->blobsTocFH == NULL) - exit_horribly(modulename, "could not open large object TOC file \"%s\" for input: %s\n", - fname, strerror(errno)); + fatal("could not open large object TOC file \"%s\" for input: %m", + fname); /* Read the blobs TOC file line-by-line, and process each blob */ while ((cfgets(ctx->blobsTocFH, line, MAXPGPATH)) != NULL) @@ -460,7 +451,7 @@ _LoadBlobs(ArchiveHandle *AH) /* Can't overflow because line and fname are the same length. */ if (sscanf(line, "%u %s\n", &oid, fname) != 2) - exit_horribly(modulename, "invalid line in large object TOC file \"%s\": \"%s\"\n", + fatal("invalid line in large object TOC file \"%s\": \"%s\"", fname, line); StartRestoreBlob(AH, oid, AH->public.ropt->dropSchema); @@ -469,12 +460,12 @@ _LoadBlobs(ArchiveHandle *AH) EndRestoreBlob(AH, oid); } if (!cfeof(ctx->blobsTocFH)) - exit_horribly(modulename, "error reading large object TOC file \"%s\"\n", + fatal("error reading large object TOC file \"%s\"", fname); if (cfclose(ctx->blobsTocFH) != 0) - exit_horribly(modulename, "could not close large object TOC file \"%s\": %s\n", - fname, strerror(errno)); + fatal("could not close large object TOC file \"%s\": %m", + fname); ctx->blobsTocFH = NULL; @@ -494,7 +485,7 @@ _WriteByte(ArchiveHandle *AH, const int i) lclContext *ctx = (lclContext *) AH->formatData; if (cfwrite(&c, 1, ctx->dataFH) != 1) - exit_horribly(modulename, "could not write to output file: %s\n", + fatal("could not write to output file: %s", get_cfp_error(ctx->dataFH)); return 1; @@ -524,7 +515,7 @@ _WriteBuf(ArchiveHandle *AH, const void *buf, size_t len) lclContext *ctx = (lclContext *) AH->formatData; if (cfwrite(buf, len, ctx->dataFH) != len) - exit_horribly(modulename, "could not write to output file: %s\n", + fatal("could not write to output file: %s", get_cfp_error(ctx->dataFH)); return; @@ -545,8 +536,7 @@ _ReadBuf(ArchiveHandle *AH, void *buf, size_t len) * exit on short reads. */ if (cfread(buf, len, ctx->dataFH) != len) - exit_horribly(modulename, - "could not read from input file: end of file\n"); + fatal("could not read from input file: end of file"); return; } @@ -581,8 +571,7 @@ _CloseArchive(ArchiveHandle *AH) /* The TOC is always created uncompressed */ tocFH = cfopen_write(fname, PG_BINARY_W, 0); if (tocFH == NULL) - exit_horribly(modulename, "could not open output file \"%s\": %s\n", - fname, strerror(errno)); + fatal("could not open output file \"%s\": %m", fname); ctx->dataFH = tocFH; /* @@ -595,8 +584,7 @@ _CloseArchive(ArchiveHandle *AH) AH->format = archDirectory; WriteToc(AH); if (cfclose(tocFH) != 0) - exit_horribly(modulename, "could not close TOC file: %s\n", - strerror(errno)); + fatal("could not close TOC file: %m"); WriteDataChunks(AH, ctx->pstate); ParallelBackupEnd(AH, ctx->pstate); @@ -606,7 +594,7 @@ _CloseArchive(ArchiveHandle *AH) * individually. Just recurse once through all the files generated. */ if (AH->dosync) - fsync_dir_recurse(ctx->directory, progname); + fsync_dir_recurse(ctx->directory); } AH->FH = NULL; } @@ -646,8 +634,7 @@ _StartBlobs(ArchiveHandle *AH, TocEntry *te) /* The blob TOC file is never compressed */ ctx->blobsTocFH = cfopen_write(fname, "ab", 0); if (ctx->blobsTocFH == NULL) - exit_horribly(modulename, "could not open output file \"%s\": %s\n", - fname, strerror(errno)); + fatal("could not open output file \"%s\": %m", fname); } /* @@ -666,8 +653,7 @@ _StartBlob(ArchiveHandle *AH, TocEntry *te, Oid oid) ctx->dataFH = cfopen_write(fname, PG_BINARY_W, AH->compression); if (ctx->dataFH == NULL) - exit_horribly(modulename, "could not open output file \"%s\": %s\n", - fname, strerror(errno)); + fatal("could not open output file \"%s\": %m", fname); } /* @@ -689,7 +675,7 @@ _EndBlob(ArchiveHandle *AH, TocEntry *te, Oid oid) /* register the blob in blobs.toc */ len = snprintf(buf, sizeof(buf), "%u blob_%u.dat\n", oid, oid); if (cfwrite(buf, len, ctx->blobsTocFH) != len) - exit_horribly(modulename, "could not write to blobs TOC file\n"); + fatal("could not write to blobs TOC file"); } /* @@ -721,7 +707,7 @@ setFilePath(ArchiveHandle *AH, char *buf, const char *relativeFilename) dname = ctx->directory; if (strlen(dname) + 1 + strlen(relativeFilename) + 1 > MAXPGPATH) - exit_horribly(modulename, "file name too long: \"%s\"\n", dname); + fatal("file name too long: \"%s\"", dname); strcpy(buf, dname); strcat(buf, "/"); |