National language support for pg_dump and pg_restore. Combined with big

message clean up.
This commit is contained in:
Peter Eisentraut 2001-06-27 21:21:37 +00:00
parent 14807a3c98
commit b559382134
15 changed files with 2059 additions and 690 deletions

View File

@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/bin/pg_dump/common.c,v 1.55 2001/04/03 08:52:59 pjw Exp $
* $Header: /cvsroot/pgsql/src/bin/pg_dump/common.c,v 1.56 2001/06/27 21:21:36 petere Exp $
*
* Modifications - 6/12/96 - dave@bensoft.com - version 1.13.dhb.2
*
@ -31,7 +31,9 @@
*-------------------------------------------------------------------------
*/
#include "postgres_fe.h"
#include "pg_dump.h"
#include "pg_backup_archiver.h"
#include <ctype.h>
@ -44,7 +46,7 @@ static char **findParentsByOid(TableInfo *tbinfo, int numTables,
InhInfo *inhinfo, int numInherits,
const char *oid,
int *numParents,
int (**parentIndices)[]);
int (**parentIndexes)[]);
static int findTableByOid(TableInfo *tbinfo, int numTables, const char *oid);
static void flagInhAttrs(TableInfo *tbinfo, int numTables,
InhInfo *inhinfo, int numInherits);
@ -116,8 +118,7 @@ findOprByOid(OprInfo *oprinfo, int numOprs, const char *oid)
}
/* should never get here */
fprintf(stderr, "failed sanity check, opr with oid %s was not found\n",
oid);
write_msg(NULL, "failed sanity check, operator with oid %s not found\n", oid);
/* no suitable operator name was found */
return (NULL);
@ -127,7 +128,7 @@ findOprByOid(OprInfo *oprinfo, int numOprs, const char *oid)
/*
* findParentsByOid
* given the oid of a class, return the names of its parent classes
* and assign the number of parents, and parent indices to the last arguments.
* and assign the number of parents, and parent indexes to the last arguments.
*
*
* returns NULL if none
@ -136,7 +137,7 @@ findOprByOid(OprInfo *oprinfo, int numOprs, const char *oid)
static char **
findParentsByOid(TableInfo *tblinfo, int numTables,
InhInfo *inhinfo, int numInherits, const char *oid,
int *numParentsPtr, int (**parentIndices)[])
int *numParentsPtr, int (**parentIndexes)[])
{
int i,
j;
@ -157,7 +158,7 @@ findParentsByOid(TableInfo *tblinfo, int numTables,
if (numParents > 0)
{
result = (char **) malloc(sizeof(char *) * numParents);
(*parentIndices) = malloc(sizeof(int) * numParents);
(*parentIndexes) = malloc(sizeof(int) * numParents);
j = 0;
for (i = 0; i < numInherits; i++)
{
@ -168,14 +169,19 @@ findParentsByOid(TableInfo *tblinfo, int numTables,
if (parentInd < 0)
{
selfInd = findTableByOid(tblinfo, numTables, oid);
fprintf(stderr,
"failed sanity check, parent oid %s of table %s (oid %s) was not found\n",
inhinfo[i].inhparent,
(selfInd >= 0) ? tblinfo[selfInd].relname : "",
oid);
if (selfInd >= 0)
write_msg(NULL, "failed sanity check, parent oid %s of table %s (oid %s) not found\n",
inhinfo[i].inhparent,
tblinfo[selfInd].relname,
oid);
else
write_msg(NULL, "failed sanity check, parent oid %s of table (oid %s) not found\n",
inhinfo[i].inhparent,
oid);
exit(2);
}
(**parentIndices)[j] = parentInd;
(**parentIndexes)[j] = parentInd;
result[j++] = tblinfo[parentInd].relname;
}
}
@ -183,7 +189,7 @@ findParentsByOid(TableInfo *tblinfo, int numTables,
}
else
{
(*parentIndices) = NULL;
(*parentIndexes) = NULL;
return NULL;
}
}
@ -212,7 +218,7 @@ parseNumericArray(const char *str, char **array, int arraysize)
{
if (argNum >= arraysize)
{
fprintf(stderr, "parseNumericArray: too many numbers\n");
write_msg(NULL, "parseNumericArray: too many numbers\n");
exit(2);
}
temp[j] = '\0';
@ -227,7 +233,7 @@ parseNumericArray(const char *str, char **array, int arraysize)
if (!(isdigit((unsigned char) s) || s == '-') ||
j >= sizeof(temp) - 1)
{
fprintf(stderr, "parseNumericArray: bogus number\n");
write_msg(NULL, "parseNumericArray: bogus number\n");
exit(2);
}
temp[j++] = s;
@ -281,7 +287,7 @@ dumpSchema(Archive *fout,
int numInherits;
int numAggregates;
int numOperators;
int numIndices;
int numIndexes;
TypeInfo *tinfo = NULL;
FuncInfo *finfo = NULL;
AggInfo *agginfo = NULL;
@ -316,9 +322,9 @@ dumpSchema(Archive *fout,
tblinfo = getTables(&numTables, finfo, numFuncs);
if (g_verbose)
fprintf(stderr, "%s reading indices information %s\n",
fprintf(stderr, "%s reading indexes information %s\n",
g_comment_start, g_comment_end);
indinfo = getIndices(&numIndices);
indinfo = getIndexes(&numIndexes);
if (g_verbose)
fprintf(stderr, "%s reading table inheritance information %s\n",
@ -355,15 +361,15 @@ dumpSchema(Archive *fout,
fprintf(stderr, "%s dumping out tables %s\n",
g_comment_start, g_comment_end);
dumpTables(fout, tblinfo, numTables, indinfo, numIndices, inhinfo, numInherits,
dumpTables(fout, tblinfo, numTables, indinfo, numIndexes, inhinfo, numInherits,
tinfo, numTypes, tablename, aclsSkip, oids, schemaOnly, dataOnly);
if (fout && !dataOnly)
{
if (g_verbose)
fprintf(stderr, "%s dumping out indices %s\n",
fprintf(stderr, "%s dumping out indexes %s\n",
g_comment_start, g_comment_end);
dumpIndices(fout, indinfo, numIndices, tblinfo, numTables, tablename);
dumpIndexes(fout, indinfo, numIndexes, tblinfo, numTables, tablename);
}
if (!tablename && !dataOnly)
@ -404,7 +410,7 @@ dumpSchema(Archive *fout,
clearTypeInfo(tinfo, numTypes);
clearFuncInfo(finfo, numFuncs);
clearInhInfo(inhinfo, numInherits);
clearIndInfo(indinfo, numIndices);
clearIndInfo(indinfo, numIndexes);
return tblinfo;
}
@ -426,7 +432,7 @@ flagInhAttrs(TableInfo *tblinfo, int numTables,
k;
int parentInd;
int inhAttrInd;
int (*parentIndices)[];
int (*parentIndexes)[];
bool foundAttr; /* Attr was found in a parent */
bool foundNotNull; /* Attr was NOT NULL in a parent */
bool defaultsMatch; /* All non-empty defaults match */
@ -451,7 +457,7 @@ flagInhAttrs(TableInfo *tblinfo, int numTables,
inhinfo, numInherits,
tblinfo[i].oid,
&tblinfo[i].numParents,
&parentIndices);
&parentIndexes);
/*
* For each attr, check the parent info: if no parent has
@ -477,13 +483,13 @@ flagInhAttrs(TableInfo *tblinfo, int numTables,
for (k = 0; k < tblinfo[i].numParents; k++)
{
parentInd = (*parentIndices)[k];
parentInd = (*parentIndexes)[k];
if (parentInd < 0)
{
/* shouldn't happen unless findParentsByOid is broken */
fprintf(stderr, "failed sanity check, table %s not found by flagInhAttrs\n",
tblinfo[i].parentRels[k]);
write_msg(NULL, "failed sanity check, table \"%s\" not found by flagInhAttrs\n",
tblinfo[i].parentRels[k]);
exit(2);
};

1359
src/bin/pg_dump/de.po Normal file

File diff suppressed because it is too large Load Diff

8
src/bin/pg_dump/nls.mk Normal file
View File

@ -0,0 +1,8 @@
# $Header: /cvsroot/pgsql/src/bin/pg_dump/nls.mk,v 1.1 2001/06/27 21:21:37 petere Exp $
CATALOG_NAME := pg_dump
AVAIL_LANGUAGES := de
GETTEXT_FILES := pg_dump.c common.c pg_backup_archiver.c pg_backup_custom.c \
pg_backup_db.c pg_backup_files.c pg_backup_null.c \
pg_backup_tar.c pg_restore.c
GETTEXT_TRIGGERS:= write_msg:2 die_horribly:3 exit_horribly:3 simple_prompt \
ExecuteSqlCommand:3

View File

@ -15,7 +15,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup.h,v 1.12 2001/05/17 21:12:48 petere Exp $
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup.h,v 1.13 2001/06/27 21:21:37 petere Exp $
*
* Modifications - 28-Jun-2000 - pjw@rhyme.com.au
*
@ -129,7 +129,7 @@ typedef struct _restoreOptions
* Main archiver interface.
*/
extern void exit_horribly(Archive *AH, const char *fmt,...);
extern void exit_horribly(Archive *AH, const char *modulename, const char *fmt, ...) __attribute__((format(printf,3,4)));
extern char *
simple_prompt(const char *prompt, int maxlen, bool echo);

View File

@ -15,7 +15,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.27 2001/05/17 21:12:48 petere Exp $
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.28 2001/06/27 21:21:37 petere Exp $
*
* Modifications - 28-Jun-2000 - pjw@rhyme.com.au
*
@ -64,13 +64,9 @@
#include "pg_backup_archiver.h"
#include "pg_backup_db.h"
#include <string.h>
#include <errno.h>
#include <unistd.h> /* for dup */
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include "pqexpbuffer.h"
#include "libpq/libpq-fs.h"
@ -94,9 +90,11 @@ static int _discoverArchiveFormat(ArchiveHandle *AH);
static void _fixupOidInfo(TocEntry *te);
static Oid _findMaxOID(const char *((*deps)[]));
static char *progname = "Archiver";
const char *progname;
static char *modulename = "archiver";
static void _die_horribly(ArchiveHandle *AH, const char *fmt, va_list ap);
static void _write_msg(const char *modulename, const char *fmt, va_list ap);
static void _die_horribly(ArchiveHandle *AH, const char *modulename, const char *fmt, va_list ap);
static int _canRestoreBlobs(ArchiveHandle *AH);
static int _restoringToDB(ArchiveHandle *AH);
@ -148,7 +146,7 @@ CloseArchive(Archive *AHX)
res = fclose(AH->OF);
if (res != 0)
die_horribly(AH, "%s: could not close the output file in CloseArchive\n", progname);
die_horribly(AH, modulename, "could not close the output file in CloseArchive\n");
}
/* Public */
@ -165,7 +163,7 @@ RestoreArchive(Archive *AHX, RestoreOptions *ropt)
AH->ropt = ropt;
if (ropt->create && ropt->noReconnect)
die_horribly(AH, "%s: --create and --no-reconnect are incompatible options\n", progname);
die_horribly(AH, modulename, "-C and -R are incompatible options\n");
/*
* If we're using a DB connection, then connect it.
@ -174,7 +172,7 @@ RestoreArchive(Archive *AHX, RestoreOptions *ropt)
{
ahlog(AH, 1, "Connecting to database for restore\n");
if (AH->version < K_VERS_1_3)
die_horribly(AH, "Direct database connections are not supported in pre-1.3 archives");
die_horribly(AH, modulename, "direct database connections are not supported in pre-1.3 archives\n");
/* XXX Should get this from the archive */
AHX->minRemoteVersion = 070100;
@ -226,11 +224,10 @@ RestoreArchive(Archive *AHX, RestoreOptions *ropt)
}
if (!ropt->superuser)
fprintf(stderr, "\n%s: ******** WARNING ******** \n"
" Data restoration may fail since any defined triggers\n"
" can not be disabled (no superuser username specified).\n"
" This is only a problem for restoration into a database\n"
" with triggers already defined.\n\n", progname);
write_msg(modulename, "WARNING:\n"
" Data restoration may fail because existing triggers cannot be disabled\n"
" (no superuser user name specified). This is only a problem when\n"
" restoring into a database with already existing triggers.\n");
/*
* Setup the output file if necessary.
@ -275,12 +272,9 @@ RestoreArchive(Archive *AHX, RestoreOptions *ropt)
if (!ropt->suppressDumpWarnings && strcmp(te->desc, "WARNING") == 0)
{
if (!ropt->dataOnly && te->defn != NULL && strlen(te->defn) != 0)
{
fprintf(stderr, "%s: Warning from original dump file:\n%s\n", progname, te->defn);
} else if (te->copyStmt != NULL && strlen(te->copyStmt) != 0)
{
fprintf(stderr, "%s: Warning from original dump file:\n%s\n", progname, te->copyStmt);
}
write_msg(modulename, "warning from original dump file: %s\n", te->defn);
else if (te->copyStmt != NULL && strlen(te->copyStmt) != 0)
write_msg(modulename, "warning from original dump file: %s\n", te->copyStmt);
}
defnDumped = false;
@ -320,8 +314,7 @@ RestoreArchive(Archive *AHX, RestoreOptions *ropt)
{
#ifndef HAVE_LIBZ
if (AH->compression != 0)
die_horribly(AH, "%s: Unable to restore data from a compressed archive\n",
progname);
die_horribly(AH, modulename, "unable to restore from compressed archive (not configured for compression support)\n");
#endif
_printTocEntry(AH, te, ropt, true);
@ -339,7 +332,7 @@ RestoreArchive(Archive *AHX, RestoreOptions *ropt)
* warnings.
*/
if (!AH->CustomOutPtr)
fprintf(stderr, "%s: WARNING - skipping BLOB restoration\n", progname);
write_msg(modulename, "WARNING: skipping BLOB restoration\n");
}
else
@ -599,8 +592,7 @@ WriteData(Archive *AHX, const void *data, int dLen)
ArchiveHandle *AH = (ArchiveHandle *) AHX;
if (!AH->currToc)
die_horribly(AH, "%s: WriteData can not be called outside the context of "
"a DataDumper routine\n", progname);
die_horribly(AH, modulename, "WriteData cannot be called outside the context of a DataDumper routine\n");
return (*AH->WriteDataPtr) (AH, data, dLen);
}
@ -625,7 +617,7 @@ ArchiveEntry(Archive *AHX, const char *oid, const char *name,
newToc = (TocEntry *) calloc(1, sizeof(TocEntry));
if (!newToc)
die_horribly(AH, "Archiver: unable to allocate memory for TOC entry\n");
die_horribly(AH, modulename, "out of memory\n");
newToc->prev = AH->toc->prev;
newToc->next = AH->toc;
@ -720,7 +712,7 @@ StartBlob(Archive *AHX, Oid oid)
ArchiveHandle *AH = (ArchiveHandle *) AHX;
if (!AH->StartBlobPtr)
die_horribly(AH, "%s: BLOB output not supported in chosen format\n", progname);
die_horribly(AH, modulename, "BLOB output not supported in chosen format\n");
(*AH->StartBlobPtr) (AH, AH->currToc, oid);
@ -784,7 +776,7 @@ StartRestoreBlob(ArchiveHandle *AH, Oid oid)
if (!AH->createdBlobXref)
{
if (!AH->connection)
die_horribly(AH, "%s: can not restore BLOBs without a database connection", progname);
die_horribly(AH, modulename, "cannot restore BLOBs without a database connection");
CreateBlobXrefTable(AH);
AH->createdBlobXref = 1;
@ -803,7 +795,7 @@ StartRestoreBlob(ArchiveHandle *AH, Oid oid)
loOid = lo_creat(AH->connection, INV_READ | INV_WRITE);
if (loOid == 0)
die_horribly(AH, "%s: unable to create BLOB\n", progname);
die_horribly(AH, modulename, "could not create BLOB\n");
ahlog(AH, 2, "Restoring BLOB oid %d as %d\n", oid, loOid);
@ -811,7 +803,7 @@ StartRestoreBlob(ArchiveHandle *AH, Oid oid)
AH->loFd = lo_open(AH->connection, loOid, INV_WRITE);
if (AH->loFd == -1)
die_horribly(AH, "%s: unable to open BLOB\n", progname);
die_horribly(AH, modulename, "could not open BLOB\n");
AH->writingBlob = 1;
}
@ -951,7 +943,7 @@ SortTocFromFile(Archive *AHX, RestoreOptions *ropt)
/* Setup the file */
fh = fopen(ropt->tocFile, PG_BINARY_R);
if (!fh)
die_horribly(AH, "%s: could not open TOC file\n", progname);
die_horribly(AH, modulename, "could not open TOC file\n");
while (fgets(buf, 1024, fh) != NULL)
{
@ -972,14 +964,14 @@ SortTocFromFile(Archive *AHX, RestoreOptions *ropt)
id = strtol(buf, &endptr, 10);
if (endptr == buf)
{
fprintf(stderr, "%s: WARNING - line ignored: %s\n", progname, buf);
write_msg(modulename, "WARNING: line ignored: %s\n", buf);
continue;
}
/* Find TOC entry */
te = _getTocEntry(AH, id);
if (!te)
die_horribly(AH, "%s: could not find entry for id %d\n", progname, id);
die_horribly(AH, modulename, "could not find entry for id %d\n", id);
ropt->idWanted[id - 1] = 1;
@ -988,7 +980,7 @@ SortTocFromFile(Archive *AHX, RestoreOptions *ropt)
}
if (fclose(fh) != 0)
die_horribly(AH, "%s: could not close TOC file\n", progname);
die_horribly(AH, modulename, "could not close TOC file: %s\n", strerror(errno));
}
/**********************
@ -1035,7 +1027,7 @@ archprintf(Archive *AH, const char *fmt,...)
bSize *= 2;
p = (char *) malloc(bSize);
if (p == NULL)
exit_horribly(AH, "%s: could not allocate buffer for archprintf\n", progname);
exit_horribly(AH, modulename, "out of memory\n");
va_start(ap, fmt);
cnt = vsnprintf(p, bSize, fmt, ap);
va_end(ap);
@ -1104,7 +1096,7 @@ SetOutput(ArchiveHandle *AH, char *filename, int compression)
#endif
if (!AH->OF)
die_horribly(AH, "%s: could not set output\n", progname);
die_horribly(AH, modulename, "could not open output file: %s\n", strerror(errno));
return sav;
}
@ -1120,7 +1112,7 @@ ResetOutput(ArchiveHandle *AH, OutputContext sav)
res = fclose(AH->OF);
if (res != 0)
die_horribly(AH, "%s: could not reset the output file\n", progname);
die_horribly(AH, modulename, "could not close output file: %s\n", strerror(errno));
AH->gzOut = sav.gzOut;
AH->OF = sav.OF;
@ -1155,7 +1147,7 @@ ahprintf(ArchiveHandle *AH, const char *fmt,...)
bSize *= 2;
p = (char *) malloc(bSize);
if (p == NULL)
die_horribly(AH, "%s: could not allocate buffer for ahprintf\n", progname);
die_horribly(AH, modulename, "out of memory\n");
va_start(ap, fmt);
cnt = vsnprintf(p, bSize, fmt, ap);
va_end(ap);
@ -1203,8 +1195,8 @@ ahwrite(const void *ptr, size_t size, size_t nmemb, ArchiveHandle *AH)
res = lo_write(AH->connection, AH->loFd, (void *) ptr, size * nmemb);
ahlog(AH, 5, "Wrote %d bytes of BLOB data (result = %d)\n", size * nmemb, res);
if (res < size * nmemb)
die_horribly(AH, "%s: could not write to large object (result = %d, expected %d)\n",
progname, res, size * nmemb);
die_horribly(AH, modulename, "could not write to large object (result: %d, expected: %d)\n",
res, size * nmemb);
return res;
}
@ -1212,7 +1204,7 @@ ahwrite(const void *ptr, size_t size, size_t nmemb, ArchiveHandle *AH)
{
res = GZWRITE((void *) ptr, size, nmemb, AH->OF);
if (res != (nmemb * size))
die_horribly(AH, "%s: could not write to archive\n", progname);
die_horribly(AH, modulename, "could not write to compressed archive\n");
return res;
}
else if (AH->CustomOutPtr)
@ -1220,7 +1212,7 @@ ahwrite(const void *ptr, size_t size, size_t nmemb, ArchiveHandle *AH)
res = AH->CustomOutPtr (AH, ptr, size * nmemb);
if (res != (nmemb * size))
die_horribly(AH, "%s: could not write to custom output routine\n", progname);
die_horribly(AH, modulename, "could not write to custom output routine\n");
return res;
}
else
@ -1236,7 +1228,7 @@ ahwrite(const void *ptr, size_t size, size_t nmemb, ArchiveHandle *AH)
{
res = fwrite((void *) ptr, size, nmemb, AH->OF);
if (res != nmemb)
die_horribly(AH, "%s: could not write to output file (%d != %d)\n", progname, res, nmemb);
die_horribly(AH, modulename, "could not write to output file (%d != %d)\n", res, nmemb);
return res;
}
}
@ -1244,9 +1236,30 @@ ahwrite(const void *ptr, size_t size, size_t nmemb, ArchiveHandle *AH)
/* Common exit code */
static void
_die_horribly(ArchiveHandle *AH, const char *fmt, va_list ap)
_write_msg(const char *modulename, const char *fmt, va_list ap)
{
vfprintf(stderr, fmt, ap);
if (modulename)
fprintf(stderr, "%s[%s]: ", progname, gettext(modulename));
else
fprintf(stderr, "%s: ", progname);
vfprintf(stderr, gettext(fmt), ap);
}
void
write_msg(const char *modulename, const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
_write_msg(modulename, fmt, ap);
va_end(ap);
}
static void
_die_horribly(ArchiveHandle *AH, const char *modulename, const char *fmt, va_list ap)
{
_write_msg(modulename, fmt, ap);
if (AH)
if (AH->connection)
@ -1259,22 +1272,22 @@ _die_horribly(ArchiveHandle *AH, const char *fmt, va_list ap)
/* External use */
void
exit_horribly(Archive *AH, const char *fmt,...)
exit_horribly(Archive *AH, const char *modulename, const char *fmt,...)
{
va_list ap;
va_start(ap, fmt);
_die_horribly((ArchiveHandle *) AH, fmt, ap);
_die_horribly((ArchiveHandle *) AH, modulename, fmt, ap);
}
/* Archiver use (just different arg declaration) */
void
die_horribly(ArchiveHandle *AH, const char *fmt,...)
die_horribly(ArchiveHandle *AH, const char *modulename, const char *fmt,...)
{
va_list ap;
va_start(ap, fmt);
_die_horribly(AH, fmt, ap);
_die_horribly(AH, modulename, fmt, ap);
}
@ -1420,7 +1433,7 @@ ReadStr(ArchiveHandle *AH)
{
buf = (char *) malloc(l + 1);
if (!buf)
die_horribly(AH, "%s: Unable to allocate sufficient memory in ReadStr - " "requested %d (0x%x) bytes\n", progname, l, l);
die_horribly(AH, modulename, "out of memory\n");
(*AH->ReadBufPtr) (AH, (void *) buf, l);
buf[l] = '\0';
@ -1437,10 +1450,9 @@ _discoverArchiveFormat(ArchiveHandle *AH)
int cnt;
int wantClose = 0;
/*
* fprintf(stderr, "%s: Attempting to ascertain archive format\n",
* progname);
*/
#if 0
write_msg(modulename, "attempting to ascertain archive format\n");
#endif
if (AH->lookahead)
free(AH->lookahead);
@ -1459,13 +1471,17 @@ _discoverArchiveFormat(ArchiveHandle *AH)
fh = stdin;
if (!fh)
die_horribly(AH, "Archiver: could not open input file\n");
die_horribly(AH, modulename, "could not open input file: %s\n", strerror(errno));
cnt = fread(sig, 1, 5, fh);
if (cnt != 5)
die_horribly(AH, "%s: input file is too short, or is unreadable (read %d, expected 5)\n",
progname, cnt);
{
if (ferror(fh))
die_horribly(AH, modulename, "could not read input file: %s\n", strerror(errno));
else
die_horribly(AH, modulename, "input file is too short (read %d, expected 5)\n", cnt);
}
/* Save it, just in case we need it later */
strncpy(&AH->lookahead[0], sig, 5);
@ -1509,11 +1525,10 @@ _discoverArchiveFormat(ArchiveHandle *AH)
AH->lookaheadLen += cnt;
if (AH->lookaheadLen != 512)
die_horribly(AH, "%s: input file does not appear to be a valid archive (too short?)\n",
progname);
die_horribly(AH, modulename, "input file does not appear to be a valid archive (too short?)\n");
if (!isValidTarHeader(AH->lookahead))
die_horribly(AH, "%s: input file does not appear to be a valid archive\n", progname);
die_horribly(AH, modulename, "input file does not appear to be a valid archive\n");
AH->format = archTar;
}
@ -1531,15 +1546,15 @@ _discoverArchiveFormat(ArchiveHandle *AH)
else
AH->lookaheadLen = 0; /* Don't bother since we've reset the file */
/*
* fprintf(stderr, "%s: read %d bytes into lookahead buffer\n",
* progname, AH->lookaheadLen);
*/
#if 0
write_msg(modulename, "read %d bytes into lookahead buffer\n", AH->lookaheadLen);
#endif
/* Close the file */
if (wantClose)
if (fclose(fh) != 0)
die_horribly(AH, "%s: could not close the input file after reading header\n", progname);
die_horribly(AH, modulename, "could not close the input file after reading header: %s\n",
strerror(errno));
return AH->format;
}
@ -1554,14 +1569,13 @@ _allocAH(const char *FileSpec, const ArchiveFormat fmt,
{
ArchiveHandle *AH;
/*
* fprintf(stderr, "%s: allocating AH for %s, format %d\n", progname,
* FileSpec, fmt);
*/
#if 0
write_msg(modulename, "allocating AH for %s, format %d\n", FileSpec, fmt);
#endif
AH = (ArchiveHandle *) calloc(1, sizeof(ArchiveHandle));
if (!AH)
die_horribly(AH, "Archiver: Could not allocate archive handle\n");
die_horribly(AH, modulename, "out of memory\n");
AH->vmaj = K_VERS_MAJOR;
AH->vmin = K_VERS_MINOR;
@ -1590,7 +1604,7 @@ _allocAH(const char *FileSpec, const ArchiveFormat fmt,
AH->toc = (TocEntry *) calloc(1, sizeof(TocEntry));
if (!AH->toc)
die_horribly(AH, "Archiver: Could not allocate TOC header\n");
die_horribly(AH, modulename, "out of memory\n");
AH->toc->next = AH->toc;
AH->toc->prev = AH->toc;
@ -1605,9 +1619,9 @@ _allocAH(const char *FileSpec, const ArchiveFormat fmt,
AH->gzOut = 0;
AH->OF = stdout;
/*
* fprintf(stderr, "%s: archive format is %d\n", progname, fmt);
*/
#if 0
write_msg(modulename, "archive format is %d\n", fmt);
#endif
if (fmt == archUnknown)
AH->format = _discoverArchiveFormat(AH);
@ -1634,7 +1648,7 @@ _allocAH(const char *FileSpec, const ArchiveFormat fmt,
break;
default:
die_horribly(AH, "Archiver: Unrecognized file format '%d'\n", fmt);
die_horribly(AH, modulename, "unrecognized file format '%d'\n", fmt);
}
return AH;
@ -1748,7 +1762,7 @@ ReadToc(ArchiveHandle *AH)
/* Sanity check */
if (te->id <= 0 || te->id > AH->tocCount)
die_horribly(AH, "Archiver: failed sanity check (bad entry id) - perhaps a corrupt TOC\n");
die_horribly(AH, modulename, "failed sanity check (bad entry id) - perhaps a corrupt TOC\n");
te->hadDumper = ReadInt(AH);
te->oid = ReadStr(AH);
@ -1778,22 +1792,20 @@ ReadToc(ArchiveHandle *AH)
deps = realloc(deps, sizeof(char*) * depSize);
}
(*deps)[depIdx] = ReadStr(AH);
/*
* if ((*deps)[depIdx])
* fprintf(stderr, "Read Dependency for %s -> %s\n", te->name, (*deps)[depIdx]);
*/
#if 0
if ((*deps)[depIdx])
write_msg(modulename, "read dependency for %s -> %s\n",
te->name, (*deps)[depIdx]);
#endif
} while ( (*deps)[depIdx++] != NULL);
if (depIdx > 1) /* We have a non-null entry */
{
/* Trim it */
te->depOid = realloc(deps, sizeof(char*) * depIdx);
} else { /* No deps */
te->depOid = NULL;
}
} else {
te->depOid = NULL;
te->depOid = realloc(deps, sizeof(char*) * depIdx); /* trim it */
else
te->depOid = NULL; /* no deps */
}
else
te->depOid = NULL;
/* Set maxOidVal etc for use in sorting */
_fixupOidInfo(te);
@ -1946,11 +1958,10 @@ WriteHead(ArchiveHandle *AH)
#ifndef HAVE_LIBZ
if (AH->compression != 0)
fprintf(stderr, "%s: WARNING - requested compression not available in this installation - "
"archive will be uncompressed \n", progname);
write_msg(modulename, "WARNING: requested compression not available in this "
"installation - archive will be uncompressed\n");
AH->compression = 0;
#endif
WriteInt(AH, AH->compression);
@ -1980,7 +1991,7 @@ ReadHead(ArchiveHandle *AH)
(*AH->ReadBufPtr) (AH, tmpMag, 5);
if (strncmp(tmpMag, "PGDMP", 5) != 0)
die_horribly(AH, "Archiver: Did not fing magic PGDMP in file header\n");
die_horribly(AH, modulename, "did not find magic string in file header\n");
AH->vmaj = (*AH->ReadBytePtr) (AH);
AH->vmin = (*AH->ReadBytePtr) (AH);
@ -1994,22 +2005,21 @@ ReadHead(ArchiveHandle *AH)
if (AH->version < K_VERS_1_0 || AH->version > K_VERS_MAX)
die_horribly(AH, "%s: unsupported version (%d.%d) in file header\n",
progname, AH->vmaj, AH->vmin);
die_horribly(AH, modulename, "unsupported version (%d.%d) in file header\n",
AH->vmaj, AH->vmin);
AH->intSize = (*AH->ReadBytePtr) (AH);
if (AH->intSize > 32)
die_horribly(AH, "Archiver: sanity check on integer size (%d) failes\n", AH->intSize);
die_horribly(AH, modulename, "sanity check on integer size (%d) failed\n", AH->intSize);
if (AH->intSize > sizeof(int))
fprintf(stderr, "\n%s: WARNING - archive was made on a machine with larger integers, "
"some operations may fail\n", progname);
write_msg(modulename, "WARNING: archive was made on a machine with larger integers, some operations may fail\n");
fmt = (*AH->ReadBytePtr) (AH);
if (AH->format != fmt)
die_horribly(AH, "%s: expected format (%d) differs from format found in file (%d)\n",
progname, AH->format, fmt);
die_horribly(AH, modulename, "expected format (%d) differs from format found in file (%d)\n",
AH->format, fmt);
}
if (AH->version >= K_VERS_1_2)
@ -2024,8 +2034,7 @@ ReadHead(ArchiveHandle *AH)
#ifndef HAVE_LIBZ
if (AH->compression != 0)
fprintf(stderr, "%s: WARNING - archive is compressed - any data will not be available\n",
progname);
write_msg(modulename, "WARNING: archive is compressed, but this installation does not support compression - no data will be available\n");
#endif
if (AH->version >= K_VERS_1_4)
@ -2043,7 +2052,7 @@ ReadHead(ArchiveHandle *AH)
AH->createDate = mktime(&crtm);
if (AH->createDate == (time_t) -1)
fprintf(stderr, "%s: WARNING - bad creation date in header\n", progname);
write_msg(modulename, "WARNING: bad creation date in header\n");
}
}

View File

@ -17,7 +17,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_archiver.h,v 1.34 2001/05/17 21:12:48 petere Exp $
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_archiver.h,v 1.35 2001/06/27 21:21:37 petere Exp $
*
* Modifications - 28-Jun-2000 - pjw@rhyme.com.au
* - Initial version.
@ -38,6 +38,7 @@
#include "postgres_fe.h"
#include <time.h>
#include <errno.h>
#include "pqexpbuffer.h"
@ -271,7 +272,9 @@ typedef struct _tocEntry
} TocEntry;
/* Used everywhere */
extern void die_horribly(ArchiveHandle *AH, const char *fmt,...);
extern const char *progname;
extern void die_horribly(ArchiveHandle *AH, const char *modulename, const char *fmt, ...) __attribute__((format(printf,3,4)));
extern void write_msg(const char *modulename, const char *fmt, ...) __attribute__((format(printf,2,3)));
extern void WriteTOC(ArchiveHandle *AH);
extern void ReadTOC(ArchiveHandle *AH);

View File

@ -19,7 +19,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_custom.c,v 1.11 2001/04/25 07:03:19 pjw Exp $
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_custom.c,v 1.12 2001/06/27 21:21:37 petere Exp $
*
* Modifications - 28-Jun-2000 - pjw@rhyme.com.au
*
@ -35,7 +35,6 @@
#include "pg_backup.h"
#include "pg_backup_archiver.h"
#include <stdlib.h>
#include <errno.h>
/*--------
@ -103,7 +102,7 @@ static void _EndDataCompressor(ArchiveHandle *AH, TocEntry *te);
static int _getFilePos(ArchiveHandle *AH, lclContext *ctx);
static int _DoDeflate(ArchiveHandle *AH, lclContext *ctx, int flush);
static char *progname = "Archiver(custom)";
static char *modulename = "custom archiver";
@ -147,12 +146,12 @@ InitArchiveFmt_Custom(ArchiveHandle *AH)
*/
ctx = (lclContext *) malloc(sizeof(lclContext));
if (ctx == NULL)
die_horribly(AH, "%s: Unable to allocate archive context", progname);
die_horribly(AH, modulename, "out of memory\n");
AH->formatData = (void *) ctx;
ctx->zp = (z_streamp) malloc(sizeof(z_stream));
if (ctx->zp == NULL)
die_horribly(AH, "%s: unable to allocate zlib stream archive context", progname);
die_horribly(AH, modulename, "out of memory\n");
/*
* zlibOutSize is the buffer size we tell zlib it can output to. We
@ -167,7 +166,7 @@ InitArchiveFmt_Custom(ArchiveHandle *AH)
ctx->filePos = 0;
if (ctx->zlibOut == NULL || ctx->zlibIn == NULL)
die_horribly(AH, "%s: unable to allocate buffers in archive context", progname);
die_horribly(AH, modulename, "out of memory\n");
/*
* Now open the file
@ -181,7 +180,7 @@ InitArchiveFmt_Custom(ArchiveHandle *AH)
AH->FH = stdout;
if (!AH->FH)
die_horribly(AH, "%s: unable to open archive file %s", progname, AH->fSpec);
die_horribly(AH, modulename, "could not open archive file %s: %s\n", AH->fSpec, strerror(errno));
ctx->hasSeek = (fseek(AH->FH, 0, SEEK_CUR) == 0);
@ -194,7 +193,7 @@ InitArchiveFmt_Custom(ArchiveHandle *AH)
else
AH->FH = stdin;
if (!AH->FH)
die_horribly(AH, "%s: unable to open archive file %s", progname, AH->fSpec);
die_horribly(AH, modulename, "could not open archive file %s: %s", AH->fSpec, strerror(errno));
ctx->hasSeek = (fseek(AH->FH, 0, SEEK_CUR) == 0);
@ -387,7 +386,7 @@ static void
_StartBlob(ArchiveHandle *AH, TocEntry *te, Oid oid)
{
if (oid == 0)
die_horribly(AH, "%s: illegal OID for BLOB (%d)\n", progname, oid);
die_horribly(AH, modulename, "invalid OID for BLOB\n");
WriteInt(AH, oid);
_StartDataCompressor(AH, te);
@ -446,8 +445,9 @@ _PrintTocData(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt)
{
if ((TocIDRequired(AH, id, ropt) & 2) != 0)
die_horribly(AH, "%s: Dumping a specific TOC data block out of order is not supported"
" without on this input stream (fseek required)\n", progname);
die_horribly(AH, modulename,
"Dumping a specific TOC data block out of order is not supported"
" without id on this input stream (fseek required)\n");
switch (blkType)
{
@ -464,8 +464,9 @@ _PrintTocData(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt)
default: /* Always have a default */
die_horribly(AH, "%s: unrecognized data block type while searching archive %d\n",
progname, blkType);
die_horribly(AH, modulename,
"unrecognized data block type (%d) while searching archive\n",
blkType);
break;
}
@ -480,7 +481,7 @@ _PrintTocData(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt)
/* Grab it */
if (fseek(AH->FH, tctx->dataPos, SEEK_SET) != 0)
die_horribly(AH, "%s: error %d in file seek\n", progname, errno);
die_horribly(AH, modulename, "error during file seek: %s\n", strerror(errno));
_readBlockHeader(AH, &blkType, &id);
@ -488,8 +489,8 @@ _PrintTocData(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt)
/* Are we sane? */
if (id != te->id)
die_horribly(AH, "%s: Found unexpected block ID (%d) when reading data - expected %d\n",
progname, id, te->id);
die_horribly(AH, modulename, "found unexpected block ID (%d) when reading data - expected %d\n",
id, te->id);
switch (blkType)
{
@ -502,15 +503,15 @@ _PrintTocData(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt)
case BLK_BLOBS:
if (!AH->connection)
die_horribly(AH, "%s: BLOBs can not be loaded without a database connection\n", progname);
die_horribly(AH, modulename, "BLOBs cannot be loaded without a database connection\n");
_LoadBlobs(AH);
break;
default: /* Always have a default */
die_horribly(AH, "%s: unrecognized data block type %d while restoring archive\n",
progname, blkType);
die_horribly(AH, modulename, "unrecognized data block type %d while restoring archive\n",
blkType);
break;
}
@ -546,7 +547,7 @@ _PrintData(ArchiveHandle *AH)
zp->opaque = Z_NULL;
if (inflateInit(zp) != Z_OK)
die_horribly(AH, "%s: could not initialize compression library - %s\n", progname, zp->msg);
die_horribly(AH, modulename, "could not initialize compression library: %s\n", zp->msg);
}
#endif
@ -560,7 +561,7 @@ _PrintData(ArchiveHandle *AH)
ctx->zlibIn = NULL;
ctx->zlibIn = (char *) malloc(blkLen + 1);
if (!ctx->zlibIn)
die_horribly(AH, "%s: failed to allocate decompression buffer\n", progname);
die_horribly(AH, modulename, "out of memory\n");
ctx->inSize = blkLen + 1;
in = ctx->zlibIn;
@ -568,7 +569,7 @@ _PrintData(ArchiveHandle *AH)
cnt = fread(in, 1, blkLen, AH->FH);
if (cnt != blkLen)
die_horribly(AH, "%s: could not read data block - expected %d, got %d\n", progname, blkLen, cnt);
die_horribly(AH, modulename, "could not read data block - expected %d, got %d\n", blkLen, cnt);
ctx->filePos += blkLen;
@ -586,7 +587,7 @@ _PrintData(ArchiveHandle *AH)
zp->avail_out = zlibOutSize;
res = inflate(zp, 0);
if (res != Z_OK && res != Z_STREAM_END)
die_horribly(AH, "%s: unable to uncompress data - %s\n", progname, zp->msg);
die_horribly(AH, modulename, "unable to uncompress data: %s\n", zp->msg);
out[zlibOutSize - zp->avail_out] = '\0';
ahwrite(out, 1, zlibOutSize - zp->avail_out, AH);
@ -618,7 +619,7 @@ _PrintData(ArchiveHandle *AH)
zp->avail_out = zlibOutSize;
res = inflate(zp, 0);
if (res != Z_OK && res != Z_STREAM_END)
die_horribly(AH, "%s: unable to uncompress data - %s\n", progname, zp->msg);
die_horribly(AH, modulename, "unable to uncompress data: %s\n", zp->msg);
out[zlibOutSize - zp->avail_out] = '\0';
ahwrite(out, 1, zlibOutSize - zp->avail_out, AH);
@ -692,7 +693,7 @@ _skipData(ArchiveHandle *AH)
}
cnt = fread(in, 1, blkLen, AH->FH);
if (cnt != blkLen)
die_horribly(AH, "%s: could not read data block - expected %d, got %d\n", progname, blkLen, cnt);
die_horribly(AH, modulename, "could not read data block - expected %d, got %d\n", blkLen, cnt);
ctx->filePos += blkLen;
@ -720,7 +721,7 @@ _WriteByte(ArchiveHandle *AH, const int i)
if (res != EOF)
ctx->filePos += 1;
else
die_horribly(AH, "%s: could not write byte./n", progname);
die_horribly(AH, modulename, "could not write byte: %s\n", strerror(errno));
return res;
}
@ -763,7 +764,7 @@ _WriteBuf(ArchiveHandle *AH, const void *buf, int len)
res = fwrite(buf, 1, len, AH->FH);
if (res != len)
die_horribly(AH, "%s: write error in _WriteBuf (%d != %d)\n", progname, res, len);
die_horribly(AH, modulename, "write error in _WriteBuf (%d != %d)\n", res, len);
ctx->filePos += res;
return res;
@ -833,7 +834,7 @@ _CloseArchive(ArchiveHandle *AH)
}
if (fclose(AH->FH) != 0)
die_horribly(AH, "%s: could not close archive file\n", progname);
die_horribly(AH, modulename, "could not close archive file: %s\n", strerror(errno));
AH->FH = NULL;
}
@ -856,7 +857,7 @@ _getFilePos(ArchiveHandle *AH, lclContext *ctx)
pos = ftell(AH->FH);
if (pos != ctx->filePos)
{
fprintf(stderr, "Warning: ftell mismatch with filePos - filePos used\n");
write_msg(modulename, "WARNING: ftell mismatch with filePos - filePos used\n");
pos = ctx->filePos;
}
}
@ -903,7 +904,7 @@ _StartDataCompressor(ArchiveHandle *AH, TocEntry *te)
zp->opaque = Z_NULL;
if (deflateInit(zp, AH->compression) != Z_OK)
die_horribly(AH, "%s: could not initialize compression library - %s\n", progname, zp->msg);
die_horribly(AH, modulename, "could not initialize compression library: %s\n", zp->msg);
}
#else
@ -936,7 +937,7 @@ _DoDeflate(ArchiveHandle *AH, lclContext *ctx, int flush)
{
res = deflate(zp, flush);
if (res == Z_STREAM_ERROR)
die_horribly(AH, "%s: could not compress data - %s\n", progname, zp->msg);
die_horribly(AH, modulename, "could not compress data: %s\n", zp->msg);
if (((flush == Z_FINISH) && (zp->avail_out < zlibOutSize))
|| (zp->avail_out == 0)
@ -958,7 +959,7 @@ _DoDeflate(ArchiveHandle *AH, lclContext *ctx, int flush)
*/
WriteInt(AH, zlibOutSize - zp->avail_out);
if (fwrite(out, 1, zlibOutSize - zp->avail_out, AH->FH) != (zlibOutSize - zp->avail_out))
die_horribly(AH, "%s: could not write compressed chunk\n", progname);
die_horribly(AH, modulename, "could not write compressed chunk\n");
ctx->filePos += zlibOutSize - zp->avail_out;
}
zp->next_out = out;
@ -972,7 +973,7 @@ _DoDeflate(ArchiveHandle *AH, lclContext *ctx, int flush)
{
WriteInt(AH, zp->avail_in);
if (fwrite(zp->next_in, 1, zp->avail_in, AH->FH) != zp->avail_in)
die_horribly(AH, "%s: could not write uncompressed chunk\n", progname);
die_horribly(AH, modulename, "could not write uncompressed chunk\n");
ctx->filePos += zp->avail_in;
zp->avail_in = 0;
}
@ -1021,7 +1022,7 @@ _EndDataCompressor(ArchiveHandle *AH, TocEntry *te)
} while (res != Z_STREAM_END);
if (deflateEnd(zp) != Z_OK)
die_horribly(AH, "%s: error closing compression stream - %s\n", progname, zp->msg);
die_horribly(AH, modulename, "could not close compression stream: %s\n", zp->msg);
}
#endif

View File

@ -5,7 +5,7 @@
* Implements the basic DB functions used by the archiver.
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_db.c,v 1.19 2001/05/17 21:12:48 petere Exp $
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_db.c,v 1.20 2001/06/27 21:21:37 petere Exp $
*
* NOTES
*
@ -38,7 +38,7 @@
#include "strdup.h"
#endif
static const char *progname = "Archiver(db)";
static const char *modulename = "archiver (db)";
static void _check_database_version(ArchiveHandle *AH, bool ignoreVersion);
static PGconn *_connectDB(ArchiveHandle *AH, const char *newdbname, char *newUser);
@ -73,7 +73,7 @@ simple_prompt(const char *prompt, int maxlen, bool echo)
if (!destination)
return NULL;
if (prompt)
fputs(prompt, stderr);
fputs(gettext(prompt), stderr);
#ifdef HAVE_TERMIOS_H
if (!echo)
@ -128,7 +128,7 @@ _parse_version(ArchiveHandle *AH, const char* versionString)
if (cnt < 2)
{
die_horribly(AH, "Unable to parse version string: %s\n", versionString);
die_horribly(AH, modulename, "unable to parse version string \"%s\"\n", versionString);
}
if (cnt == 2)
@ -148,13 +148,12 @@ _check_database_version(ArchiveHandle *AH, bool ignoreVersion)
myversion = _parse_version(AH, PG_VERSION);
res = PQexec(conn, "SELECT version()");
res = PQexec(conn, "SELECT version();");
if (!res ||
PQresultStatus(res) != PGRES_TUPLES_OK ||
PQntuples(res) != 1)
die_horribly(AH, "check_database_version(): command failed. "
"Explanation from backend: '%s'.\n", PQerrorMessage(conn));
die_horribly(AH, modulename, "could not get version from server: %s", PQerrorMessage(conn));
remoteversion_str = PQgetvalue(res, 0, 0);
remoteversion = _parse_version(AH, remoteversion_str + 11);
@ -166,13 +165,12 @@ _check_database_version(ArchiveHandle *AH, bool ignoreVersion)
if (myversion != remoteversion
&& (remoteversion < AH->public.minRemoteVersion || remoteversion > AH->public.maxRemoteVersion) )
{
fprintf(stderr, "Database version: %s\n%s version: %s\n",
remoteversion_str, progname, PG_VERSION);
write_msg(NULL, "server version: %s, %s version: %s\n",
remoteversion_str, progname, PG_VERSION);
if (ignoreVersion)
fprintf(stderr, "Proceeding despite version mismatch.\n");
write_msg(NULL, "proceeding despite version mismatch\n");
else
die_horribly(AH, "Aborting because of version mismatch.\n"
"Use --ignore-version if you think it's safe to proceed anyway.\n");
die_horribly(AH, NULL, "aborting because of version mismatch (Use the -i option to proceed anyway.)\n");
}
}
@ -193,12 +191,11 @@ UserIsSuperuser(ArchiveHandle *AH, char *user)
res = PQexec(AH->connection, qry->data);
if (!res)
die_horribly(AH, "%s: null result checking superuser status of %s.\n",
progname, user);
die_horribly(AH, modulename, "null result checking superuser status of %s\n", user);
if (PQresultStatus(res) != PGRES_TUPLES_OK)
die_horribly(AH, "%s: Could not check superuser status of %s. Explanation from backend: %s\n",
progname, user, PQerrorMessage(AH->connection));
die_horribly(AH, modulename, "could not check superuser status of %s: %s",
user, PQerrorMessage(AH->connection));
ntups = PQntuples(res);
@ -284,7 +281,7 @@ _connectDB(ArchiveHandle *AH, const char *reqdb, char *requser)
{
password = simple_prompt("Password: ", 100, false);
if (password == NULL)
die_horribly(AH, "out of memory");
die_horribly(AH, modulename, "out of memory\n");
}
do
@ -294,7 +291,7 @@ _connectDB(ArchiveHandle *AH, const char *reqdb, char *requser)
NULL, NULL, newdb,
newuser, password);
if (!newConn)
die_horribly(AH, "%s: Failed to reconnect (PQsetdbLogin failed).\n", progname);
die_horribly(AH, modulename, "failed to reconnect to database\n");
if (PQstatus(newConn) == CONNECTION_BAD)
{
@ -318,8 +315,8 @@ _connectDB(ArchiveHandle *AH, const char *reqdb, char *requser)
password = simple_prompt("Password: ", 100, false);
}
else
die_horribly(AH, "%s: Could not reconnect. %s\n",
progname, PQerrorMessage(newConn));
die_horribly(AH, modulename, "could not reconnect to database: %s",
PQerrorMessage(newConn));
}
} while (need_pass);
@ -350,10 +347,10 @@ ConnectDatabase(Archive *AHX,
bool need_pass = false;
if (AH->connection)
die_horribly(AH, "%s: already connected to database\n", progname);
die_horribly(AH, modulename, "already connected to database\n");
if (!dbname && !(dbname = getenv("PGDATABASE")))
die_horribly(AH, "%s: no database name specified\n", progname);
die_horribly(AH, modulename, "no database name specified\n");
AH->dbname = strdup(dbname);
@ -376,7 +373,7 @@ ConnectDatabase(Archive *AHX,
{
password = simple_prompt("Password: ", 100, false);
if (password == NULL)
die_horribly(AH, "out of memory");
die_horribly(AH, modulename, "out of memory\n");
AH->requirePassword = true;
}
else
@ -393,8 +390,7 @@ ConnectDatabase(Archive *AHX,
AH->dbname, AH->username, password);
if (!AH->connection)
die_horribly(AH, "%s: Failed to connect (PQsetdbLogin failed).\n",
progname);
die_horribly(AH, modulename, "failed to connect to database\n");
if (PQstatus(AH->connection) == CONNECTION_BAD &&
strcmp(PQerrorMessage(AH->connection), "fe_sendauth: no password supplied\n") == 0 &&
@ -413,7 +409,7 @@ ConnectDatabase(Archive *AHX,
/* check to see that the backend connection was successfully made */
if (PQstatus(AH->connection) == CONNECTION_BAD)
die_horribly(AH, "Connection to database '%s' failed.\n%s\n",
die_horribly(AH, modulename, "connection to database \"%s\" failed: %s",
AH->dbname, PQerrorMessage(AH->connection));
/* check for version mismatch */
@ -432,9 +428,12 @@ ConnectDatabase(Archive *AHX,
/* Public interface */
/* Convenience function to send a query. Monitors result to handle COPY statements */
int
ExecuteSqlCommand(ArchiveHandle *AH, PQExpBuffer qry, char *desc)
ExecuteSqlCommand(ArchiveHandle *AH, PQExpBuffer qry, char *desc, bool use_blob)
{
return _executeSqlCommand(AH, AH->connection, qry, desc);
if (use_blob)
return _executeSqlCommand(AH, AH->blobConnection, qry, desc);
else
return _executeSqlCommand(AH, AH->connection, qry, desc);
}
/*
@ -450,20 +449,20 @@ _executeSqlCommand(ArchiveHandle *AH, PGconn *conn, PQExpBuffer qry, char *desc)
/* fprintf(stderr, "Executing: '%s'\n\n", qry->data); */
res = PQexec(conn, qry->data);
if (!res)
die_horribly(AH, "%s: %s. No result from backend.\n", progname, desc);
die_horribly(AH, modulename, "%s: no result from backend\n", desc);
if (PQresultStatus(res) != PGRES_COMMAND_OK && PQresultStatus(res) != PGRES_TUPLES_OK)
{
if (PQresultStatus(res) == PGRES_COPY_IN)
{
if (conn != AH->connection)
die_horribly(AH, "%s: COPY command execute in non-primary connection.\n", progname);
die_horribly(AH, modulename, "COPY command executed in non-primary connection\n");
AH->pgCopyIn = 1;
}
else
die_horribly(AH, "%s: %s. Code = %d. Explanation from backend: '%s'.\n",
progname, desc, PQresultStatus(res), PQerrorMessage(AH->connection));
die_horribly(AH, modulename, "%s: %s",
desc, PQerrorMessage(AH->connection));
}
PQclear(res);
@ -545,7 +544,7 @@ ExecuteSqlCommandBuf(ArchiveHandle *AH, void *qryv, int bufLen)
*/
if (PQputline(AH->connection, AH->pgCopyBuf->data) != 0)
die_horribly(AH, "%s: error returned by PQputline\n", progname);
die_horribly(AH, modulename, "error returned by PQputline\n");
resetPQExpBuffer(AH->pgCopyBuf);
@ -557,7 +556,7 @@ ExecuteSqlCommandBuf(ArchiveHandle *AH, void *qryv, int bufLen)
if (isEnd)
{
if (PQendcopy(AH->connection) != 0)
die_horribly(AH, "%s: error returned by PQendcopy\n", progname);
die_horribly(AH, modulename, "error returned by PQendcopy\n");
AH->pgCopyIn = 0;
break;
@ -606,7 +605,7 @@ ExecuteSqlCommandBuf(ArchiveHandle *AH, void *qryv, int bufLen)
* fprintf(stderr, " sending: '%s'\n\n",
* AH->sqlBuf->data);
*/
ExecuteSqlCommand(AH, AH->sqlBuf, "Could not execute query");
ExecuteSqlCommand(AH, AH->sqlBuf, "could not execute query", false);
resetPQExpBuffer(AH->sqlBuf);
AH->sqlparse.lastChar = '\0';
}
@ -696,8 +695,8 @@ FixupBlobRefs(ArchiveHandle *AH, char *tablename)
res = PQexec(AH->blobConnection, tblQry->data);
if (!res)
die_horribly(AH, "%s: could not find OID attrs of %s. Explanation from backend '%s'\n",
progname, tablename, PQerrorMessage(AH->connection));
die_horribly(AH, modulename, "could not find oid columns of table \"%s\": %s",
tablename, PQerrorMessage(AH->connection));
if ((n = PQntuples(res)) == 0)
{
@ -730,14 +729,14 @@ FixupBlobRefs(ArchiveHandle *AH, char *tablename)
uRes = PQexec(AH->blobConnection, tblQry->data);
if (!uRes)
die_horribly(AH, "%s: could not update attr %s of table %s. Explanation from backend '%s'\n",
progname, attr, tablename, PQerrorMessage(AH->blobConnection));
die_horribly(AH, modulename,
"could not update column \"%s\" of table \"%s\": %s",
attr, tablename, PQerrorMessage(AH->blobConnection));
if (PQresultStatus(uRes) != PGRES_COMMAND_OK)
die_horribly(AH, "%s: error while updating attr %s of table %s (result = %d)."
" Explanation from backend '%s'\n",
progname, attr, tablename, PQresultStatus(uRes),
PQerrorMessage(AH->blobConnection));
die_horribly(AH, modulename,
"error while updating column \"%s\" of table \"%s\": %s",
attr, tablename, PQerrorMessage(AH->blobConnection));
PQclear(uRes);
}
@ -762,12 +761,12 @@ CreateBlobXrefTable(ArchiveHandle *AH)
appendPQExpBuffer(qry, "Create Temporary Table %s(oldOid oid, newOid oid);", BLOB_XREF_TABLE);
_executeSqlCommand(AH, AH->blobConnection, qry, "can not create BLOB xref table '" BLOB_XREF_TABLE "'");
ExecuteSqlCommand(AH, qry, "could not create BLOB cross reference table", true);
resetPQExpBuffer(qry);
appendPQExpBuffer(qry, "Create Unique Index %s_ix on %s(oldOid)", BLOB_XREF_TABLE, BLOB_XREF_TABLE);
_executeSqlCommand(AH, AH->blobConnection, qry, "can not create index on BLOB xref table '" BLOB_XREF_TABLE "'");
ExecuteSqlCommand(AH, qry, "could not create index on BLOB cross reference table", true);
}
void
@ -777,7 +776,7 @@ InsertBlobXref(ArchiveHandle *AH, int old, int new)
appendPQExpBuffer(qry, "Insert Into %s(oldOid, newOid) Values (%d, %d);", BLOB_XREF_TABLE, old, new);
_executeSqlCommand(AH, AH->blobConnection, qry, "can not create BLOB xref entry");
ExecuteSqlCommand(AH, qry, "could not create BLOB cross reference entry", true);
}
void
@ -787,7 +786,7 @@ StartTransaction(ArchiveHandle *AH)
appendPQExpBuffer(qry, "Begin;");
ExecuteSqlCommand(AH, qry, "can not start database transaction");
ExecuteSqlCommand(AH, qry, "could not start database transaction", false);
AH->txActive = true;
}
@ -798,7 +797,8 @@ StartTransactionXref(ArchiveHandle *AH)
appendPQExpBuffer(qry, "Begin;");
_executeSqlCommand(AH, AH->blobConnection, qry, "can not start BLOB xref transaction");
ExecuteSqlCommand(AH, qry,
"could not start transaction for BLOB cross references", true);
AH->blobTxActive = true;
}
@ -809,7 +809,7 @@ CommitTransaction(ArchiveHandle *AH)
appendPQExpBuffer(qry, "Commit;");
ExecuteSqlCommand(AH, qry, "can not commit database transaction");
ExecuteSqlCommand(AH, qry, "could not commit database transaction", false);
AH->txActive = false;
}
@ -820,6 +820,6 @@ CommitTransactionXref(ArchiveHandle *AH)
appendPQExpBuffer(qry, "Commit;");
_executeSqlCommand(AH, AH->blobConnection, qry, "can not commit BLOB xref transaction");
ExecuteSqlCommand(AH, qry, "could not commit transaction for BLOB cross references", true);
AH->blobTxActive = false;
}

View File

@ -2,13 +2,13 @@
* Definitions for pg_backup_db.c
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_db.h,v 1.4 2001/03/22 04:00:13 momjian Exp $
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_db.h,v 1.5 2001/06/27 21:21:37 petere Exp $
*/
#define BLOB_XREF_TABLE "dump_blob_xref" /* MUST be lower case */
extern void FixupBlobRefs(ArchiveHandle *AH, char *tablename);
extern int ExecuteSqlCommand(ArchiveHandle *AH, PQExpBuffer qry, char *desc);
extern int ExecuteSqlCommand(ArchiveHandle *AH, PQExpBuffer qry, char *desc, bool use_blob);
extern int ExecuteSqlCommandBuf(ArchiveHandle *AH, void *qry, int bufLen);
extern void CreateBlobXrefTable(ArchiveHandle *AH);

View File

@ -20,7 +20,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_files.c,v 1.10 2001/04/01 05:42:51 pjw Exp $
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_files.c,v 1.11 2001/06/27 21:21:37 petere Exp $
*
* Modifications - 28-Jun-2000 - pjw@rhyme.com.au
*
@ -36,9 +36,6 @@
#include "pg_backup.h"
#include "pg_backup_archiver.h"
#include <stdlib.h>
#include <string.h>
static void _ArchiveEntry(ArchiveHandle *AH, TocEntry *te);
static void _StartData(ArchiveHandle *AH, TocEntry *te);
static int _WriteData(ArchiveHandle *AH, const void *data, int dLen);
@ -77,7 +74,7 @@ typedef struct
char *filename;
} lclTocEntry;
static char *progname = "Archiver(files)";
static char *modulename = "file archiver";
static void _LoadBlobs(ArchiveHandle *AH, RestoreOptions *ropt);
static void _getBlobTocEntry(ArchiveHandle *AH, int *oid, char *fname);
@ -122,11 +119,9 @@ InitArchiveFmt_Files(ArchiveHandle *AH)
if (AH->mode == archModeWrite)
{
fprintf(stderr, "\n*************************************************************\n"
"* WARNING: This format is for demonstration purposes. It is *\n"
"* not intended for general use. Files will be dumped *\n"
"* into the current working directory. *\n"
"***************************************************************\n\n");
write_msg(modulename, "WARNING:\n"
" This format is for demonstration purposes, it is not intended for\n"
" 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);
@ -134,7 +129,7 @@ InitArchiveFmt_Files(ArchiveHandle *AH)
AH->FH = stdout;
if (AH->FH == NULL)
die_horribly(NULL, "%s: Could not open output file\n", progname);
die_horribly(NULL, modulename, "could not open output file: %s\n", strerror(errno));
ctx->hasSeek = (fseek(AH->FH, 0, SEEK_CUR) == 0);
@ -152,7 +147,7 @@ InitArchiveFmt_Files(ArchiveHandle *AH)
AH->FH = stdin;
if (AH->FH == NULL)
die_horribly(NULL, "%s: Could not open input file\n", progname);
die_horribly(NULL, modulename, "could not open input file: %s\n", strerror(errno));
ctx->hasSeek = (fseek(AH->FH, 0, SEEK_CUR) == 0);
@ -160,7 +155,7 @@ InitArchiveFmt_Files(ArchiveHandle *AH)
ReadToc(AH);
/* Nothing else in the file... */
if (fclose(AH->FH) != 0)
die_horribly(AH, "%s: Could not close TOC file (fclose failed).\n", progname);
die_horribly(AH, modulename, "could not close TOC file: %s\n", strerror(errno));
}
}
@ -250,7 +245,7 @@ _StartData(ArchiveHandle *AH, TocEntry *te)
#endif
if (tctx->FH == NULL)
die_horribly(AH, "%s: Could not open data file for output\n", progname);
die_horribly(AH, modulename, "could not open data file for output\n");
}
@ -271,7 +266,7 @@ _EndData(ArchiveHandle *AH, TocEntry *te)
/* Close the file */
if (GZCLOSE(tctx->FH) != 0)
die_horribly(AH, "%s: could not close data file\n", progname);
die_horribly(AH, modulename, "could not close data file\n");
tctx->FH = NULL;
}
@ -295,7 +290,7 @@ _PrintFileData(ArchiveHandle *AH, char *filename, RestoreOptions *ropt)
#endif
if (AH->FH == NULL)
die_horribly(AH, "%s: Could not open data file for input\n", progname);
die_horribly(AH, modulename, "could not open data file for input\n");
while ((cnt = GZREAD(buf, 1, 4095, AH->FH)) > 0)
{
@ -304,7 +299,7 @@ _PrintFileData(ArchiveHandle *AH, char *filename, RestoreOptions *ropt)
}
if (GZCLOSE(AH->FH) != 0)
die_horribly(AH, "%s: could not close data file after reading\n", progname);
die_horribly(AH, modulename, "could not close data file after reading\n");
}
@ -368,7 +363,7 @@ _LoadBlobs(ArchiveHandle *AH, RestoreOptions *ropt)
ctx->blobToc = fopen("blobs.toc", PG_BINARY_R);
if (ctx->blobToc == NULL)
die_horribly(AH, "%s: Could not open BLOB TOC for input\n", progname);
die_horribly(AH, modulename, "could not open BLOB TOC for input: %s\n", strerror(errno));
_getBlobTocEntry(AH, &oid, fname);
@ -381,7 +376,7 @@ _LoadBlobs(ArchiveHandle *AH, RestoreOptions *ropt)
}
if (fclose(ctx->blobToc) != 0)
die_horribly(AH, "%s: could not close BLOB TOC file\n", progname);
die_horribly(AH, modulename, "could not close BLOB TOC file: %s\n", strerror(errno));
EndRestoreBlobs(AH);
}
@ -393,7 +388,7 @@ _WriteByte(ArchiveHandle *AH, const int i)
lclContext *ctx = (lclContext *) AH->formatData;
if (fputc(i, AH->FH) == EOF)
die_horribly(AH, "%s: could not write byte\n", progname);
die_horribly(AH, modulename, "could not write byte\n");
ctx->filePos += 1;
@ -420,7 +415,7 @@ _WriteBuf(ArchiveHandle *AH, const void *buf, int len)
res = fwrite(buf, 1, len, AH->FH);
if (res != len)
die_horribly(AH, "%s: write error in _WriteBuf (%d != %d)\n", progname, res, len);
die_horribly(AH, modulename, "write error in _WriteBuf (%d != %d)\n", res, len);
ctx->filePos += res;
return res;
@ -445,7 +440,7 @@ _CloseArchive(ArchiveHandle *AH)
WriteHead(AH);
WriteToc(AH);
if (fclose(AH->FH) != 0)
die_horribly(AH, "%s: could not close TOC file\n", progname);
die_horribly(AH, modulename, "could not close TOC file: %s\n", strerror(errno));
WriteDataChunks(AH);
}
@ -478,7 +473,8 @@ _StartBlobs(ArchiveHandle *AH, TocEntry *te)
ctx->blobToc = fopen(fname, PG_BINARY_W);
if (ctx->blobToc == NULL)
die_horribly(AH, "%s: could not open BLOB TOC for output\n", progname);
die_horribly(AH, modulename,
"could not open BLOB TOC for output: %s\n", strerror(errno));
}
@ -499,7 +495,7 @@ _StartBlob(ArchiveHandle *AH, TocEntry *te, Oid oid)
char *sfx;
if (oid == 0)
die_horribly(AH, "%s: illegal OID for BLOB (%d)\n", progname, oid);
die_horribly(AH, modulename, "invalid OID for BLOB (%u)\n", oid);
if (AH->compression != 0)
sfx = ".gz";
@ -518,7 +514,7 @@ _StartBlob(ArchiveHandle *AH, TocEntry *te, Oid oid)
#endif
if (tctx->FH == NULL)
die_horribly(AH, "%s: Could not open BLOB file\n", progname);
die_horribly(AH, modulename, "could not open BLOB file\n");
}
/*
@ -533,7 +529,7 @@ _EndBlob(ArchiveHandle *AH, TocEntry *te, Oid oid)
lclTocEntry *tctx = (lclTocEntry *) te->formatData;
if (GZCLOSE(tctx->FH) != 0)
die_horribly(AH, "%s: could not close BLOB file\n", progname);
die_horribly(AH, modulename, "could not close BLOB file\n");
}
/*
@ -551,7 +547,7 @@ _EndBlobs(ArchiveHandle *AH, TocEntry *te)
/* WriteInt(AH, 0); */
if (fclose(ctx->blobToc) != 0)
die_horribly(AH, "%s: could not close BLOB TOC file\n", progname);
die_horribly(AH, modulename, "could not close BLOB TOC file: %s\n", strerror(errno));
}

View File

@ -17,7 +17,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_null.c,v 1.6 2001/03/24 23:11:14 tgl Exp $
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_null.c,v 1.7 2001/06/27 21:21:37 petere Exp $
*
* Modifications - 09-Jul-2000 - pjw@rhyme.com.au
*
@ -63,7 +63,7 @@ InitArchiveFmt_Null(ArchiveHandle *AH)
* Now prevent reading...
*/
if (AH->mode == archModeRead)
die_horribly(AH, "%s: This format can not be read\n");
die_horribly(AH, NULL, "this format cannot be read\n");
}

View File

@ -16,7 +16,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_tar.c,v 1.15 2001/04/25 07:03:19 pjw Exp $
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_tar.c,v 1.16 2001/06/27 21:21:37 petere Exp $
*
* Modifications - 28-Jun-2000 - pjw@rhyme.com.au
*
@ -101,7 +101,7 @@ typedef struct
char *filename;
} lclTocEntry;
static char *progname = "Archiver(tar)";
static char *modulename = "tar archiver";
static void _LoadBlobs(ArchiveHandle *AH, RestoreOptions *ropt);
@ -172,7 +172,8 @@ InitArchiveFmt_Tar(ArchiveHandle *AH)
ctx->tarFH = stdout;
if (ctx->tarFH == NULL)
die_horribly(NULL, "%s: Could not open TOC file for output.\n", progname);
die_horribly(NULL, modulename,
"could not open TOC file for output: %s\n", strerror(errno));
ctx->tarFHpos = 0;
@ -197,7 +198,7 @@ InitArchiveFmt_Tar(ArchiveHandle *AH)
* screws file positioning.
*/
if (AH->compression != 0)
die_horribly(NULL, "%s: Compression not supported in TAR output\n", progname);
die_horribly(NULL, modulename, "compression not supported by tar output format\n");
}
else
@ -209,7 +210,7 @@ InitArchiveFmt_Tar(ArchiveHandle *AH)
ctx->tarFH = stdin;
if (ctx->tarFH == NULL)
die_horribly(NULL, "%s: Could not open TOC file for input\n", progname);
die_horribly(NULL, modulename, "could not open TOC file for input: %s\n", strerror(errno));
/*
* Make unbuffered since we will dup() it, and the buffers screw
@ -332,7 +333,7 @@ tarOpen(ArchiveHandle *AH, const char *filename, char mode)
{
if (filename) /* Couldn't find the requested file.
* Future: DO SEEK(0) and retry. */
die_horribly(AH, "%s: unable to find file '%s' in archive\n", progname, filename);
die_horribly(AH, modulename, "could not find file %s in archive\n", filename);
else
/* Any file OK, non left, so return NULL */
return NULL;
@ -343,7 +344,7 @@ tarOpen(ArchiveHandle *AH, const char *filename, char mode)
if (AH->compression == 0)
tm->nFH = ctx->tarFH;
else
die_horribly(AH, "%s: compression support is disabled in this format\n", progname);
die_horribly(AH, modulename, "compression support is disabled in this format\n");
/* tm->zFH = gzdopen(dup(fileno(ctx->tarFH)), "rb"); */
#else
@ -360,7 +361,7 @@ tarOpen(ArchiveHandle *AH, const char *filename, char mode)
tm->tmpFH = tmpfile();
if (tm->tmpFH == NULL)
die_horribly(AH, "%s: could not generate temp file name.\n", progname);
die_horribly(AH, modulename, "could not generate temporary file name: %s\n", strerror(errno));
#ifdef HAVE_LIBZ
@ -369,7 +370,7 @@ tarOpen(ArchiveHandle *AH, const char *filename, char mode)
sprintf(fmode, "wb%d", AH->compression);
tm->zFH = gzdopen(dup(fileno(tm->tmpFH)), fmode);
if (tm->zFH == NULL)
die_horribly(AH, "%s: could not gzdopen temp file.\n", progname);
die_horribly(AH, modulename, "could not gzdopen temporary file\n");
}
else
@ -401,7 +402,7 @@ tarClose(ArchiveHandle *AH, TAR_MEMBER *th)
*/
if (AH->compression != 0)
if (GZCLOSE(th->zFH) != 0)
die_horribly(AH, "%s: could not close tar member\n", progname);
die_horribly(AH, modulename, "could not close tar member\n");
if (th->mode == 'w')
_tarAddFile(AH, th); /* This will close the temp file */
@ -502,13 +503,13 @@ _tarReadRaw(ArchiveHandle *AH, void *buf, int len, TAR_MEMBER *th, FILE *fh)
res = fread(&((char *) buf)[used], 1, len, th->nFH);
}
else
die_horribly(AH, "%s: neither th nor fh specified in tarReadRaw\n", progname);
die_horribly(AH, modulename, "neither th nor fh specified in tarReadRaw() (internal error)\n");
}
/*
* fprintf(stderr, "%s: requested %d bytes, got %d from lookahead and
* %d from file\n", progname, reqLen, used, res);
*/
#if 0
write_msg(modulename, "requested %d bytes, got %d from lookahead and %d from file\n",
reqLen, used, res);
#endif
ctx->tarFHpos += res + used;
@ -544,7 +545,8 @@ tarWrite(const void *buf, int len, TAR_MEMBER *th)
res = fwrite(buf, 1, len, th->nFH);
if (res != len)
die_horribly(th->AH, "%s: could not write to tar member (%d != %d)\n", progname, res, len);
die_horribly(th->AH, modulename,
"could not write to tar member (wrote %d, attempted %d)\n", res, len);
th->pos += res;
return res;
@ -631,7 +633,8 @@ _PrintTocData(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt)
* OIDS, so we search the string for it in a paranoid sort of way.
*/
if (strncmp(tmpCopy, "copy ", 5) != 0)
die_horribly(AH, "%s: COPY statment badly formatted - could not find 'copy' in '%s'\n", progname, tmpCopy);
die_horribly(AH, modulename,
"bad COPY statement - could not find \"copy\" in string \"%s\"\n", tmpCopy);
pos1 = 5;
for (pos1 = 5; pos1 < strlen(tmpCopy); pos1++)
@ -648,8 +651,9 @@ _PrintTocData(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt)
break;
if (pos2 >= strlen(tmpCopy))
die_horribly(AH, "%s: COPY statment badly formatted - could not find 'from stdin' in '%s' starting at %d\n",
progname, tmpCopy, pos1);
die_horribly(AH, modulename,
"bad COPY statement - could not find \"from stdin\" in string \"%s\" starting at position %d\n",
tmpCopy, pos1);
ahwrite(tmpCopy, 1, pos2, AH); /* 'copy "table" [with oids]' */
ahprintf(AH, " from '$$PATH$$/%s' %s", tctx->filename, &tmpCopy[pos2 + 10]);
@ -849,7 +853,8 @@ _CloseArchive(ArchiveHandle *AH)
for (i = 0; i < 512; i++)
{
if (fputc(0, ctx->tarFH) == EOF)
die_horribly(AH, "%s: could not write null block at end of TAR archive.\n", progname);
die_horribly(AH, modulename,
"could not write null block at end of tar archive\n");
}
}
@ -906,7 +911,7 @@ _StartBlob(ArchiveHandle *AH, TocEntry *te, Oid oid)
char *sfx;
if (oid == 0)
die_horribly(AH, "%s: illegal OID for BLOB (%d)\n", progname, oid);
die_horribly(AH, modulename, "invalid OID for BLOB (%u)\n", oid);
if (AH->compression != 0)
sfx = ".gz";
@ -984,7 +989,7 @@ tarPrintf(ArchiveHandle *AH, TAR_MEMBER *th, const char *fmt,...)
bSize *= 2;
p = (char *) malloc(bSize);
if (p == NULL)
die_horribly(AH, "%s: could not allocate buffer for tarPrintf\n", progname);
die_horribly(AH, modulename, "out of memory\n");
va_start(ap, fmt);
cnt = vsnprintf(p, bSize, fmt, ap);
va_end(ap);
@ -1044,22 +1049,22 @@ _tarAddFile(ArchiveHandle *AH, TAR_MEMBER *th)
{
res = fwrite(&buf[0], 1, cnt, th->tarFH);
if (res != cnt)
die_horribly(AH, "%s: write error appending to TAR archive (%d != %d).\n", progname, res, cnt);
die_horribly(AH, modulename, "write error appending to tar archive (wrote %d, attempted %d)\n", res, cnt);
len += res;
}
if (fclose(tmp) != 0) /* This *should* delete it... */
die_horribly(AH, "%s: Could not close tar member (fclose failed).\n", progname);
die_horribly(AH, modulename, "could not close tar member: %s\n", strerror(errno));
if (len != th->fileLen)
die_horribly(AH, "%s: Actual file length does not match expected (%d vs. %d).\n",
progname, len, th->pos);
die_horribly(AH, modulename, "actual file length (%d) does not match expected (%d)\n",
len, th->pos);
pad = ((len + 511) & ~511) - len;
for (i = 0; i < pad; i++)
{
if (fputc('\0', th->tarFH) == EOF)
die_horribly(AH, "%s: Could not output padding at end of tar member.\n", progname);
die_horribly(AH, modulename, "could not output padding at end of tar member\n");
}
ctx->tarFHpos += len + pad;
@ -1099,7 +1104,7 @@ _tarPositionTo(ArchiveHandle *AH, const char *filename)
if (!_tarGetHeader(AH, th))
{
if (filename)
die_horribly(AH, "%s: unable to find header for %s\n", progname, filename);
die_horribly(AH, modulename, "could not find header for file %s in tar archive\n", filename);
else
/* We're just scanning the archibe for the next file, so return null */
{
@ -1114,9 +1119,9 @@ _tarPositionTo(ArchiveHandle *AH, const char *filename)
id = atoi(th->targetFile);
if ((TocIDRequired(AH, id, AH->ropt) & 2) != 0)
die_horribly(AH, "%s: dumping data out of order is not supported in this archive format: "
"%s is required, but comes before %s in the archive file.\n",
progname, th->targetFile, filename);
die_horribly(AH, modulename, "dumping data out of order is not supported in this archive format: "
"%s is required, but comes before %s in the archive file.\n",
th->targetFile, filename);
/* Header doesn't match, so read to next header */
len = ((th->fileLen + 511) & ~511); /* Padded length */
@ -1126,7 +1131,7 @@ _tarPositionTo(ArchiveHandle *AH, const char *filename)
_tarReadRaw(AH, &header[0], 512, NULL, ctx->tarFH);
if (!_tarGetHeader(AH, th))
die_horribly(AH, "%s: unable to find header for %s\n", progname, filename);
die_horribly(AH, modulename, "could not find header for file %s in tar archive\n", filename);
}
@ -1152,12 +1157,12 @@ _tarGetHeader(ArchiveHandle *AH, TAR_MEMBER *th)
while (!gotBlock)
{
/*
* if ( ftell(ctx->tarFH) != ctx->tarFHpos) die_horribly(AH, "%s:
* mismatch in actual vs. predicted file pos - %d vs. %d\n",
* progname, ftell(ctx->tarFH), ctx->tarFHpos);
*/
#if 0
if (ftell(ctx->tarFH) != ctx->tarFHpos)
die_horribly(AH, modulename,
"mismatch in actual vs. predicted file position (%d vs. %d)\n",
ftell(ctx->tarFH), ctx->tarFHpos);
#endif
/* Save the pos for reporting purposes */
hPos = ctx->tarFHpos;
@ -1168,7 +1173,7 @@ _tarGetHeader(ArchiveHandle *AH, TAR_MEMBER *th)
return 0;
if (len != 512)
die_horribly(AH, "%s: incomplete tar header found (%d bytes)\n", progname, len);
die_horribly(AH, modulename, "incomplete tar header found (%d bytes)\n", len);
/* Calc checksum */
chk = _tarChecksum(&h[0]);
@ -1200,9 +1205,10 @@ _tarGetHeader(ArchiveHandle *AH, TAR_MEMBER *th)
ahlog(AH, 3, "TOC Entry %s at %d (len=%d, chk=%d)\n", &name[0], hPos, len, sum);
if (chk != sum)
die_horribly(AH, "%s: corrupt tar header found in %s "
"(expected %d (%o), computed %d (%o)) file position %d (%x)\n",
progname, &name[0], sum, sum, chk, chk, ftell(ctx->tarFH), ftell(ctx->tarFH));
die_horribly(AH, modulename,
"corrupt tar header found in %s "
"(expected %d (%o), computed %d (%o)) file position %ld (%lx)\n",
&name[0], sum, sum, chk, chk, ftell(ctx->tarFH), ftell(ctx->tarFH));
th->targetFile = strdup(name);
th->fileLen = len;
@ -1277,6 +1283,6 @@ _tarWriteHeader(TAR_MEMBER *th)
}
if (fwrite(h, 1, 512, th->tarFH) != 512)
die_horribly(th->AH, "%s: unable to write tar header\n", progname);
die_horribly(th->AH, modulename, "unable to write tar header\n");
}

File diff suppressed because it is too large Load Diff

View File

@ -6,7 +6,7 @@
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $Id: pg_dump.h,v 1.63 2001/04/25 07:03:20 pjw Exp $
* $Id: pg_dump.h,v 1.64 2001/06/27 21:21:37 petere Exp $
*
* Modifications - 6/12/96 - dave@bensoft.com - version 1.13.dhb.2
*
@ -254,7 +254,7 @@ extern OprInfo *getOperators(int *numOperators);
extern TableInfo *getTables(int *numTables, FuncInfo *finfo, int numFuncs);
extern InhInfo *getInherits(int *numInherits);
extern void getTableAttrs(TableInfo *tbinfo, int numTables);
extern IndInfo *getIndices(int *numIndices);
extern IndInfo *getIndexes(int *numIndexes);
extern void dumpDBComment(Archive *outfile);
extern void dumpTypes(Archive *fout, FuncInfo *finfo, int numFuncs,
TypeInfo *tinfo, int numTypes);
@ -267,12 +267,12 @@ extern void dumpAggs(Archive *fout, AggInfo *agginfo, int numAggregates,
extern void dumpOprs(Archive *fout, OprInfo *agginfo, int numOperators,
TypeInfo *tinfo, int numTypes);
extern void dumpTables(Archive *fout, TableInfo *tbinfo, int numTables,
IndInfo *indinfo, int numIndices,
IndInfo *indinfo, int numIndexes,
InhInfo *inhinfo, int numInherits,
TypeInfo *tinfo, int numTypes, const char *tablename,
const bool acls, const bool oids,
const bool schemaOnly, const bool dataOnly);
extern void dumpIndices(Archive *fout, IndInfo *indinfo, int numIndices,
extern void dumpIndexes(Archive *fout, IndInfo *indinfo, int numIndexes,
TableInfo *tbinfo, int numTables, const char *tablename);
extern const char *fmtId(const char *identifier, bool force_quotes);

View File

@ -11,7 +11,7 @@
* user-defined types
* user-defined functions
* tables
* indices
* indexes
* aggregates
* operators
* ACL - grant/revoke
@ -34,7 +34,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_restore.c,v 1.20 2001/05/17 21:12:49 petere Exp $
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_restore.c,v 1.21 2001/06/27 21:21:37 petere Exp $
*
* Modifications - 28-Jun-2000 - pjw@rhyme.com.au
*
@ -55,10 +55,8 @@
*/
#include "pg_backup.h"
#include "pg_backup_archiver.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#ifndef HAVE_STRDUP
@ -73,6 +71,10 @@
#include <getopt.h>
#endif
#ifdef ENABLE_NLS
#include <locale.h>
#endif
/* Forward decls */
static void usage(const char *progname);
static char *_cleanupName(char *name);
@ -116,16 +118,24 @@ int
main(int argc, char **argv)
{
RestoreOptions *opts;
char *progname;
int c;
Archive *AH;
char *fileSpec = NULL;
extern int optind;
extern char *optarg;
#ifdef ENABLE_NLS
setlocale(LC_ALL, "");
bindtextdomain("pg_dump", LOCALEDIR);
textdomain("pg_dump");
#endif
opts = NewRestoreOptions();
progname = argv[0];
if (!strrchr(argv[0], '/'))
progname = argv[0];
else
progname = strrchr(argv[0], '/') + 1;
if (argc > 1)
{
@ -257,7 +267,7 @@ main(int argc, char **argv)
opts->aclsSkip = 1;
break;
default:
fprintf(stderr, "Try '%s --help' for more information.\n", progname);
fprintf(stderr, gettext("Try '%s --help' for more information.\n"), progname);
exit(1);
}
}
@ -289,8 +299,8 @@ main(int argc, char **argv)
break;
default:
fprintf(stderr, "%s: Unknown archive format '%s', please specify 't' or 'c'\n",
progname, opts->formatName);
write_msg("unrecognized archive format '%s'; please specify 't' or 'c'\n",
opts->formatName);
exit(1);
}
}
@ -335,75 +345,78 @@ main(int argc, char **argv)
static void
usage(const char *progname)
{
printf("%s restores a PostgreSQL database from an archive created by pg_dump.\n\n"
"Usage:\n %s [options] [file]\n\n"
"Options:\n",
printf(gettext(
"%s restores a PostgreSQL database from an archive created by pg_dump.\n\n"
"Usage:\n %s [options] [file]\n\n"
"Options:\n"),
progname, progname);
#ifdef HAVE_GETOPT_LONG
puts(
" -a, --data-only restore only the data, no schema\n"
" -c, --clean clean (drop) schema prior to create\n"
" -C, --create output commands to create the database\n"
" -d, --dbname=NAME specify database name\n"
" -f, --file=FILENAME script output file name\n"
" -F, --format {c|f} specify backup file format\n"
" -h, --host HOSTNAME server host name\n"
" -i, --index[=NAME] restore indices or named index\n"
" -l, --list dump summarized TOC for this file\n"
" -L, --use-list=FILENAME use specified table of contents for ordering\n"
" output from this file\n"
" -N, --orig-order restore in original dump order\n"
" -o, --oid-order restore in oid order\n"
" -O, --no-owner do not reconnect to database to match\n"
" object owner\n"
" -p, --port PORT server port number\n"
" -P, --function[=NAME] restore functions or named function\n"
" -r, --rearrange rearrange output to put indexes etc. at end\n"
" -R, --no-reconnect disallow ALL reconnections to the database\n"
" -s, --schema-only restore only the schema, no data\n"
" -S, --superuser=NAME specify the superuser user name to use for\n"
" disabling triggers\n"
" -t, --table[=TABLE] restore this table only\n"
" -T, --trigger[=NAME] restore triggers or named trigger\n"
" -U, --username=NAME connect as specified database user\n"
" -v, --verbose verbose\n"
" -W, --password force password prompt (should happen automatically)\n"
" -x, --no-acl skip dumping of ACLs (grant/revoke)\n");
puts(gettext(
" -a, --data-only restore only the data, no schema\n"
" -c, --clean clean (drop) schema prior to create\n"
" -C, --create output commands to create the database\n"
" -d, --dbname=NAME specify database name\n"
" -f, --file=FILENAME script output file name\n"
" -F, --format {c|f} specify backup file format\n"
" -h, --host HOSTNAME server host name\n"
" -i, --index[=NAME] restore indexes or named index\n"
" -l, --list dump summarized TOC for this file\n"
" -L, --use-list=FILENAME use specified table of contents for ordering\n"
" output from this file\n"
" -N, --orig-order restore in original dump order\n"
" -o, --oid-order restore in oid order\n"
" -O, --no-owner do not reconnect to database to match\n"
" object owner\n"
" -p, --port PORT server port number\n"
" -P, --function[=NAME] restore functions or named function\n"
" -r, --rearrange rearrange output to put indexes etc. at end\n"
" -R, --no-reconnect disallow ALL reconnections to the database\n"
" -s, --schema-only restore only the schema, no data\n"
" -S, --superuser=NAME specify the superuser user name to use for\n"
" disabling triggers\n"
" -t, --table[=TABLE] restore this table only\n"
" -T, --trigger[=NAME] restore triggers or named trigger\n"
" -U, --username=NAME connect as specified database user\n"
" -v, --verbose verbose\n"
" -W, --password force password prompt (should happen automatically)\n"
" -x, --no-acl skip dumping of ACLs (grant/revoke)\n"
));
#else /* not HAVE_GETOPT_LONG */
#else /* not HAVE_GETOPT_LONG */
puts(
" -a restore only the data, no schema\n"
" -c clean (drop) schema prior to create\n"
" -C output commands to create the database\n"
" -d NAME specify database name\n"
" -f FILENAME script output file name\n"
" -F {c|f} specify backup file format\n"
" -h HOSTNAME server host name\n"
" -i NAME restore indices or named index\n"
" -l dump summarized TOC for this file\n"
" -L FILENAME use specified table of contents for ordering\n"
" output from this file\n"
" -N restore in original dump order\n"
" -o restore in oid order\n"
" -O do not output reconnect to database to match\n"
" object owner\n"
" -p PORT server port number\n"
" -P NAME restore functions or named function\n"
" -r rearrange output to put indexes etc at end\n"
" -R disallow ALL reconnections to the database\n"
" -s restore only the schema, no data\n"
" -S NAME specify the superuser user name to use for\n"
" disabling triggers\n"
" -t NAME restore this table only\n"
" -T NAME restore triggers or named trigger\n"
" -U NAME connect as specified database user\n"
" -v verbose\n"
" -W force password prompt (should happen automatically)\n"
" -x skip dumping of ACLs (grant/revoke)\n");
puts(gettext(
" -a restore only the data, no schema\n"
" -c clean (drop) schema prior to create\n"
" -C output commands to create the database\n"
" -d NAME specify database name\n"
" -f FILENAME script output file name\n"
" -F {c|f} specify backup file format\n"
" -h HOSTNAME server host name\n"
" -i NAME restore indexes or named index\n"
" -l dump summarized TOC for this file\n"
" -L FILENAME use specified table of contents for ordering\n"
" output from this file\n"
" -N restore in original dump order\n"
" -o restore in oid order\n"
" -O do not output reconnect to database to match\n"
" object owner\n"
" -p PORT server port number\n"
" -P NAME restore functions or named function\n"
" -r rearrange output to put indexes etc at end\n"
" -R disallow ALL reconnections to the database\n"
" -s restore only the schema, no data\n"
" -S NAME specify the superuser user name to use for\n"
" disabling triggers\n"
" -t NAME restore this table only\n"
" -T NAME restore triggers or named trigger\n"
" -U NAME connect as specified database user\n"
" -v verbose\n"
" -W force password prompt (should happen automatically)\n"
" -x skip dumping of ACLs (grant/revoke)\n"
));
#endif
puts("If [file] is not supplied, then standard input is used.\n");
puts("Report bugs to <pgsql-bugs@postgresql.org>.");
puts(gettext("If no input file name is supplied, then standard input is used.\n"));
puts(gettext("Report bugs to <pgsql-bugs@postgresql.org>."));
}