Please find attached a patch for the pg_dump directory which addresses:

- The problems Jan reported

- incompatibility with configure (now uses HAVE_LIBZ instead of HAVE_ZLIB)

- a problem in auto-detecting archive file format on piped archives

Philip Warner
This commit is contained in:
Jan Wieck 2000-07-06 18:39:39 +00:00
parent 2a225ebf18
commit 43f6ab8654
6 changed files with 75 additions and 74 deletions

View File

@ -118,7 +118,7 @@ void RestoreArchive(Archive* AHX, RestoreOptions *ropt)
_printTocEntry(AH, te, ropt); _printTocEntry(AH, te, ropt);
if (AH->PrintTocDataPtr != NULL && (reqs & 2) != 0) { if (AH->PrintTocDataPtr != NULL && (reqs & 2) != 0) {
#ifndef HAVE_ZLIB #ifndef HAVE_LIBZ
if (AH->compression != 0) if (AH->compression != 0)
die_horribly("%s: Unable to restore data from a compressed archive\n", progname); die_horribly("%s: Unable to restore data from a compressed archive\n", progname);
#endif #endif
@ -415,11 +415,14 @@ int archprintf(Archive* AH, const char *fmt, ...)
{ {
char *p = NULL; char *p = NULL;
va_list ap; va_list ap;
int bSize = strlen(fmt) + 1024; int bSize = strlen(fmt) + 256;
int cnt = -1; int cnt = -1;
va_start(ap, fmt); va_start(ap, fmt);
while (cnt < 0) {
/* This is paranoid: deal with the possibility that vsnprintf is willing to ignore trailing null */
/* or returns > 0 even if string does not fit. It may be the case that it returns cnt = bufsize */
while (cnt < 0 || cnt >= (bSize-1) ) {
if (p != NULL) free(p); if (p != NULL) free(p);
bSize *= 2; bSize *= 2;
if ((p = malloc(bSize)) == NULL) if ((p = malloc(bSize)) == NULL)
@ -443,7 +446,7 @@ int archprintf(Archive* AH, const char *fmt, ...)
OutputContext SetOutput(ArchiveHandle* AH, char *filename, int compression) OutputContext SetOutput(ArchiveHandle* AH, char *filename, int compression)
{ {
OutputContext sav; OutputContext sav;
#ifdef HAVE_ZLIB #ifdef HAVE_LIBZ
char fmode[10]; char fmode[10];
#endif #endif
int fn = 0; int fn = 0;
@ -464,7 +467,7 @@ OutputContext SetOutput(ArchiveHandle* AH, char *filename, int compression)
} }
/* If compression explicitly requested, use gzopen */ /* If compression explicitly requested, use gzopen */
#ifdef HAVE_ZLIB #ifdef HAVE_LIBZ
if (compression != 0) if (compression != 0)
{ {
sprintf(fmode, "wb%d", compression); sprintf(fmode, "wb%d", compression);
@ -482,7 +485,7 @@ OutputContext SetOutput(ArchiveHandle* AH, char *filename, int compression)
AH->OF = fopen(filename, PG_BINARY_W); AH->OF = fopen(filename, PG_BINARY_W);
} }
AH->gzOut = 0; AH->gzOut = 0;
#ifdef HAVE_ZLIB #ifdef HAVE_LIBZ
} }
#endif #endif
@ -509,11 +512,13 @@ int ahprintf(ArchiveHandle* AH, const char *fmt, ...)
{ {
char *p = NULL; char *p = NULL;
va_list ap; va_list ap;
int bSize = strlen(fmt) + 1024; /* Should be enough */ int bSize = strlen(fmt) + 256; /* Should be enough */
int cnt = -1; int cnt = -1;
va_start(ap, fmt); va_start(ap, fmt);
while (cnt < 0) { /* This is paranoid: deal with the possibility that vsnprintf is willing to ignore trailing null */
/* or returns > 0 even if string does not fit. It may be the case that it returns cnt = bufsize */
while (cnt < 0 || cnt >= (bSize - 1) ) {
if (p != NULL) free(p); if (p != NULL) free(p);
bSize *= 2; bSize *= 2;
p = (char*)malloc(bSize); p = (char*)malloc(bSize);
@ -681,6 +686,7 @@ int _discoverArchiveFormat(ArchiveHandle* AH)
int cnt; int cnt;
int wantClose = 0; int wantClose = 0;
if (AH->fSpec) { if (AH->fSpec) {
wantClose = 1; wantClose = 1;
fh = fopen(AH->fSpec, PG_BINARY_R); fh = fopen(AH->fSpec, PG_BINARY_R);
@ -693,16 +699,11 @@ int _discoverArchiveFormat(ArchiveHandle* AH)
cnt = fread(sig, 1, 5, fh); cnt = fread(sig, 1, 5, fh);
if (cnt != 5) { if (cnt != 5)
fprintf(stderr, "Archiver: input file is too short, or is unreadable\n"); die_horribly("%s: input file is too short, or is unreadable\n", progname);
exit(1);
}
if (strncmp(sig, "PGDMP", 5) != 0) if (strncmp(sig, "PGDMP", 5) != 0)
{ die_horribly("%s: input file does not appear to be a valid archive\n", progname);
fprintf(stderr, "Archiver: input file does not appear to be a valid archive\n");
exit(1);
}
AH->vmaj = fgetc(fh); AH->vmaj = fgetc(fh);
AH->vmin = fgetc(fh); AH->vmin = fgetc(fh);
@ -739,7 +740,7 @@ static ArchiveHandle* _allocAH(const char* FileSpec, ArchiveFormat fmt,
int compression, ArchiveMode mode) { int compression, ArchiveMode mode) {
ArchiveHandle* AH; ArchiveHandle* AH;
AH = (ArchiveHandle*)malloc(sizeof(ArchiveHandle)); AH = (ArchiveHandle*)calloc(1, sizeof(ArchiveHandle));
if (!AH) if (!AH)
die_horribly("Archiver: Could not allocate archive handle\n"); die_horribly("Archiver: Could not allocate archive handle\n");
@ -759,7 +760,7 @@ static ArchiveHandle* _allocAH(const char* FileSpec, ArchiveFormat fmt,
AH->currToc = NULL; AH->currToc = NULL;
AH->currUser = ""; AH->currUser = "";
AH->toc = (TocEntry*)malloc(sizeof(TocEntry)); AH->toc = (TocEntry*)calloc(1, sizeof(TocEntry));
if (!AH->toc) if (!AH->toc)
die_horribly("Archiver: Could not allocate TOC header\n"); die_horribly("Archiver: Could not allocate TOC header\n");
@ -996,7 +997,7 @@ void WriteHead(ArchiveHandle* AH)
(*AH->WriteBytePtr)(AH, AH->intSize); (*AH->WriteBytePtr)(AH, AH->intSize);
(*AH->WriteBytePtr)(AH, AH->format); (*AH->WriteBytePtr)(AH, AH->format);
#ifndef HAVE_ZLIB #ifndef HAVE_LIBZ
if (AH->compression != 0) if (AH->compression != 0)
fprintf(stderr, "%s: WARNING - requested compression not available in this installation - " fprintf(stderr, "%s: WARNING - requested compression not available in this installation - "
"archive will be uncompressed \n", progname); "archive will be uncompressed \n", progname);
@ -1016,44 +1017,44 @@ void ReadHead(ArchiveHandle* AH)
char tmpMag[7]; char tmpMag[7];
int fmt; int fmt;
if (AH->readHeader) if (!AH->readHeader) {
return;
(*AH->ReadBufPtr)(AH, tmpMag, 5); (*AH->ReadBufPtr)(AH, tmpMag, 5);
if (strncmp(tmpMag,"PGDMP", 5) != 0) if (strncmp(tmpMag,"PGDMP", 5) != 0)
die_horribly("Archiver: Did not fing magic PGDMP in file header\n"); die_horribly("Archiver: Did not fing magic PGDMP in file header\n");
AH->vmaj = (*AH->ReadBytePtr)(AH); AH->vmaj = (*AH->ReadBytePtr)(AH);
AH->vmin = (*AH->ReadBytePtr)(AH); AH->vmin = (*AH->ReadBytePtr)(AH);
if (AH->vmaj > 1 || ( (AH->vmaj == 1) && (AH->vmin > 0) ) ) /* Version > 1.0 */ if (AH->vmaj > 1 || ( (AH->vmaj == 1) && (AH->vmin > 0) ) ) /* Version > 1.0 */
{ {
AH->vrev = (*AH->ReadBytePtr)(AH); AH->vrev = (*AH->ReadBytePtr)(AH);
} else { } else {
AH->vrev = 0; AH->vrev = 0;
}
AH->version = ( (AH->vmaj * 256 + AH->vmin) * 256 + AH->vrev ) * 256 + 0;
if (AH->version < K_VERS_1_0 || AH->version > K_VERS_MAX)
die_horribly("Archiver: unsupported version (%d.%d) in file header\n", AH->vmaj, AH->vmin);
AH->intSize = (*AH->ReadBytePtr)(AH);
if (AH->intSize > 32)
die_horribly("Archiver: sanity check on integer size (%d) failes\n", AH->intSize);
if (AH->intSize > sizeof(int))
fprintf(stderr, "\nWARNING: Backup file was made on a machine with larger integers, "
"some operations may fail\n");
fmt = (*AH->ReadBytePtr)(AH);
if (AH->format != fmt)
die_horribly("Archiver: expected format (%d) differs from format found in file (%d)\n",
AH->format, fmt);
} }
AH->version = ( (AH->vmaj * 256 + AH->vmin) * 256 + AH->vrev ) * 256 + 0;
if (AH->version < K_VERS_1_0 || AH->version > K_VERS_MAX)
die_horribly("Archiver: unsupported version (%d.%d) in file header\n", AH->vmaj, AH->vmin);
AH->intSize = (*AH->ReadBytePtr)(AH);
if (AH->intSize > 32)
die_horribly("Archiver: sanity check on integer size (%d) failes\n", AH->intSize);
if (AH->intSize > sizeof(int))
fprintf(stderr, "\nWARNING: Backup file was made on a machine with larger integers, "
"some operations may fail\n");
fmt = (*AH->ReadBytePtr)(AH);
if (AH->format != fmt)
die_horribly("Archiver: expected format (%d) differs from format found in file (%d)\n",
AH->format, fmt);
if (AH->version >= K_VERS_1_2) if (AH->version >= K_VERS_1_2)
{ {
AH->compression = (*AH->ReadBytePtr)(AH); AH->compression = (*AH->ReadBytePtr)(AH);
@ -1061,8 +1062,9 @@ void ReadHead(ArchiveHandle* AH)
AH->compression = Z_DEFAULT_COMPRESSION; AH->compression = Z_DEFAULT_COMPRESSION;
} }
#ifndef HAVE_ZLIB #ifndef HAVE_LIBZ
fprintf(stderr, "%s: WARNING - archive is compressed - any data will not be available\n", progname); if (AH->compression != 0)
fprintf(stderr, "%s: WARNING - archive is compressed - any data will not be available\n", progname);
#endif #endif
} }

View File

@ -30,7 +30,7 @@
#include <stdio.h> #include <stdio.h>
#ifdef HAVE_ZLIB #ifdef HAVE_LIBZ
#include <zlib.h> #include <zlib.h>
#define GZCLOSE(fh) gzclose(fh) #define GZCLOSE(fh) gzclose(fh)
#define GZWRITE(p, s, n, fh) gzwrite(fh, p, n * s) #define GZWRITE(p, s, n, fh) gzwrite(fh, p, n * s)
@ -54,7 +54,7 @@ typedef z_stream *z_streamp;
#define K_VERS_MAJOR 1 #define K_VERS_MAJOR 1
#define K_VERS_MINOR 2 #define K_VERS_MINOR 2
#define K_VERS_REV 0 #define K_VERS_REV 1
/* Some important version numbers (checked in code) */ /* Some important version numbers (checked in code) */
#define K_VERS_1_0 (( (1 * 256 + 0) * 256 + 0) * 256 + 0) #define K_VERS_1_0 (( (1 * 256 + 0) * 256 + 0) * 256 + 0)

View File

@ -200,7 +200,7 @@ static void _StartData(ArchiveHandle* AH, TocEntry* te)
WriteInt(AH, te->id); /* For sanity check */ WriteInt(AH, te->id); /* For sanity check */
#ifdef HAVE_ZLIB #ifdef HAVE_LIBZ
if (AH->compression < 0 || AH->compression > 9) { if (AH->compression < 0 || AH->compression > 9) {
AH->compression = Z_DEFAULT_COMPRESSION; AH->compression = Z_DEFAULT_COMPRESSION;
@ -230,7 +230,7 @@ static int _DoDeflate(ArchiveHandle* AH, lclContext* ctx, int flush)
{ {
z_streamp zp = ctx->zp; z_streamp zp = ctx->zp;
#ifdef HAVE_ZLIB #ifdef HAVE_LIBZ
char* out = ctx->zlibOut; char* out = ctx->zlibOut;
int res = Z_OK; int res = Z_OK;
@ -268,14 +268,14 @@ static int _DoDeflate(ArchiveHandle* AH, lclContext* ctx, int flush)
ctx->filePos += zp->avail_in; ctx->filePos += zp->avail_in;
zp->avail_in = 0; zp->avail_in = 0;
} else { } else {
#ifdef HAVE_ZLIB #ifdef HAVE_LIBZ
if (flush == Z_FINISH) if (flush == Z_FINISH)
res = Z_STREAM_END; res = Z_STREAM_END;
#endif #endif
} }
#ifdef HAVE_ZLIB #ifdef HAVE_LIBZ
} }
return res; return res;
@ -305,7 +305,7 @@ static void _EndData(ArchiveHandle* AH, TocEntry* te)
lclContext* ctx = (lclContext*)AH->formatData; lclContext* ctx = (lclContext*)AH->formatData;
lclTocEntry* tctx = (lclTocEntry*) te->formatData; lclTocEntry* tctx = (lclTocEntry*) te->formatData;
#ifdef HAVE_ZLIB #ifdef HAVE_LIBZ
z_streamp zp = ctx->zp; z_streamp zp = ctx->zp;
int res; int res;
@ -385,7 +385,7 @@ static void _PrintData(ArchiveHandle* AH)
char* in = ctx->zlibIn; char* in = ctx->zlibIn;
int cnt; int cnt;
#ifdef HAVE_ZLIB #ifdef HAVE_LIBZ
int res; int res;
char* out = ctx->zlibOut; char* out = ctx->zlibOut;
@ -424,7 +424,7 @@ static void _PrintData(ArchiveHandle* AH)
zp->next_in = in; zp->next_in = in;
zp->avail_in = blkLen; zp->avail_in = blkLen;
#ifdef HAVE_ZLIB #ifdef HAVE_LIBZ
if (AH->compression != 0) { if (AH->compression != 0) {
@ -443,14 +443,14 @@ static void _PrintData(ArchiveHandle* AH)
ahwrite(in, 1, zp->avail_in, AH); ahwrite(in, 1, zp->avail_in, AH);
zp->avail_in = 0; zp->avail_in = 0;
#ifdef HAVE_ZLIB #ifdef HAVE_LIBZ
} }
#endif #endif
blkLen = ReadInt(AH); blkLen = ReadInt(AH);
} }
#ifdef HAVE_ZLIB #ifdef HAVE_LIBZ
if (AH->compression != 0) if (AH->compression != 0)
{ {
zp->next_in = NULL; zp->next_in = NULL;

View File

@ -54,7 +54,7 @@ typedef struct {
} lclContext; } lclContext;
typedef struct { typedef struct {
#ifdef HAVE_ZLIB #ifdef HAVE_LIBZ
gzFile *FH; gzFile *FH;
#else #else
FILE *FH; FILE *FH;
@ -133,7 +133,7 @@ static void _ArchiveEntry(ArchiveHandle* AH, TocEntry* te)
ctx = (lclTocEntry*)malloc(sizeof(lclTocEntry)); ctx = (lclTocEntry*)malloc(sizeof(lclTocEntry));
if (te->dataDumper) { if (te->dataDumper) {
#ifdef HAVE_ZLIB #ifdef HAVE_LIBZ
if (AH->compression == 0) { if (AH->compression == 0) {
sprintf(fn, "%d.dat", te->id); sprintf(fn, "%d.dat", te->id);
} else { } else {
@ -192,7 +192,7 @@ static void _StartData(ArchiveHandle* AH, TocEntry* te)
sprintf(fmode, "wb%d", AH->compression); sprintf(fmode, "wb%d", AH->compression);
#ifdef HAVE_ZLIB #ifdef HAVE_LIBZ
tctx->FH = gzopen(tctx->filename, fmode); tctx->FH = gzopen(tctx->filename, fmode);
#else #else
tctx->FH = fopen(tctx->filename, PG_BINARY_W); tctx->FH = fopen(tctx->filename, PG_BINARY_W);
@ -229,7 +229,7 @@ static void _PrintTocData(ArchiveHandle* AH, TocEntry* te, RestoreOptions *ropt)
if (!tctx->filename) if (!tctx->filename)
return; return;
#ifdef HAVE_ZLIB #ifdef HAVE_LIBZ
AH->FH = gzopen(tctx->filename,"rb"); AH->FH = gzopen(tctx->filename,"rb");
#else #else
AH->FH = fopen(tctx->filename,PG_BINARY_R); AH->FH = fopen(tctx->filename,PG_BINARY_R);

View File

@ -22,7 +22,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.156 2000/07/04 16:57:49 momjian Exp $ * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.157 2000/07/06 18:39:39 wieck Exp $
* *
* Modifications - 6/10/96 - dave@bensoft.com - version 1.13.dhb * Modifications - 6/10/96 - dave@bensoft.com - version 1.13.dhb
* *
@ -3202,10 +3202,9 @@ dumpTables(Archive *fout, TableInfo *tblinfo, int numTables,
{ {
/* Skip VIEW relations */ /* Skip VIEW relations */
/* /* if (isViewRule(tblinfo[i].relname)) continue; */
* if (isViewRule(tblinfo[i].relname)) continue;
*/
parentRels = tblinfo[i].parentRels; parentRels = tblinfo[i].parentRels;
numParents = tblinfo[i].numParents; numParents = tblinfo[i].numParents;

View File

@ -108,7 +108,7 @@ int main(int argc, char **argv)
char *progname; char *progname;
int c; int c;
Archive* AH; Archive* AH;
char *fileSpec; char *fileSpec = NULL;
opts = NewRestoreOptions(); opts = NewRestoreOptions();