Please find attached a patch for the pg_dump directory which addresses:
authorJan Wieck <[email protected]>
Thu, 6 Jul 2000 18:39:39 +0000 (18:39 +0000)
committerJan Wieck <[email protected]>
Thu, 6 Jul 2000 18:39:39 +0000 (18:39 +0000)
- 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

src/bin/pg_dump/pg_backup_archiver.c
src/bin/pg_dump/pg_backup_archiver.h
src/bin/pg_dump/pg_backup_custom.c
src/bin/pg_dump/pg_backup_files.c
src/bin/pg_dump/pg_dump.c
src/bin/pg_dump/pg_restore.c

index 1673a8dd4f953e53464a3d5e5e1f8b81ba965f2f..e25cf5675634bee1796100eb9b48b8c7a62745ce 100644 (file)
@@ -118,7 +118,7 @@ void RestoreArchive(Archive* AHX, RestoreOptions *ropt)
            _printTocEntry(AH, te, ropt);
 
        if (AH->PrintTocDataPtr != NULL && (reqs & 2) != 0) {
-#ifndef HAVE_ZLIB
+#ifndef HAVE_LIBZ
            if (AH->compression != 0)
                die_horribly("%s: Unable to restore data from a compressed archive\n", progname);
 #endif
@@ -415,11 +415,14 @@ int archprintf(Archive* AH, const char *fmt, ...)
 {
     char       *p = NULL;
     va_list    ap;
-    int                bSize = strlen(fmt) + 1024;
+    int                bSize = strlen(fmt) + 256;
     int                cnt = -1;
 
     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);
        bSize *= 2;
        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      sav;
-#ifdef HAVE_ZLIB
+#ifdef HAVE_LIBZ
     char               fmode[10];
 #endif
     int                        fn = 0;
@@ -464,7 +467,7 @@ OutputContext SetOutput(ArchiveHandle* AH, char *filename, int compression)
     }
 
     /* If compression explicitly requested, use gzopen */
-#ifdef HAVE_ZLIB
+#ifdef HAVE_LIBZ
     if (compression != 0)
     {
        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->gzOut = 0;
-#ifdef HAVE_ZLIB
+#ifdef HAVE_LIBZ
     }
 #endif
 
@@ -509,11 +512,13 @@ int ahprintf(ArchiveHandle* AH, const char *fmt, ...)
 {
     char       *p = NULL;
     va_list    ap;
-    int                bSize = strlen(fmt) + 1024; /* Should be enough */
+    int                bSize = strlen(fmt) + 256; /* Should be enough */
     int                cnt = -1;
 
     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);
        bSize *= 2;
        p = (char*)malloc(bSize);
@@ -681,6 +686,7 @@ int _discoverArchiveFormat(ArchiveHandle* AH)
     int                cnt;
     int                wantClose = 0;
 
+
     if (AH->fSpec) {
        wantClose = 1;
        fh = fopen(AH->fSpec, PG_BINARY_R);
@@ -693,16 +699,11 @@ int _discoverArchiveFormat(ArchiveHandle* AH)
 
     cnt = fread(sig, 1, 5, fh);
 
-    if (cnt != 5) {
-        fprintf(stderr, "Archiver: input file is too short, or is unreadable\n");
-       exit(1);
-    }
+    if (cnt != 5)
+        die_horribly("%s: input file is too short, or is unreadable\n", progname);
 
     if (strncmp(sig, "PGDMP", 5) != 0)
-    {
-       fprintf(stderr, "Archiver: input file does not appear to be a valid archive\n");
-       exit(1);
-    }
+       die_horribly("%s: input file does not appear to be a valid archive\n", progname);
 
     AH->vmaj = fgetc(fh);
     AH->vmin = fgetc(fh);
@@ -739,7 +740,7 @@ static ArchiveHandle* _allocAH(const char* FileSpec, ArchiveFormat fmt,
                                int compression, ArchiveMode mode) {
     ArchiveHandle*     AH;
 
-    AH = (ArchiveHandle*)malloc(sizeof(ArchiveHandle));
+    AH = (ArchiveHandle*)calloc(1, sizeof(ArchiveHandle));
     if (!AH) 
        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->currUser = "";
 
-    AH->toc = (TocEntry*)malloc(sizeof(TocEntry));
+    AH->toc = (TocEntry*)calloc(1, sizeof(TocEntry));
     if (!AH->toc)
        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->format);
 
-#ifndef HAVE_ZLIB
+#ifndef HAVE_LIBZ
     if (AH->compression != 0)
        fprintf(stderr, "%s: WARNING - requested compression not available in this installation - "
                    "archive will be uncompressed \n", progname);
@@ -1016,43 +1017,43 @@ void ReadHead(ArchiveHandle* AH)
     char       tmpMag[7];
     int                fmt;
 
-    if (AH->readHeader)
-       return;
+    if (!AH->readHeader) {
 
-    (*AH->ReadBufPtr)(AH, tmpMag, 5);
+       (*AH->ReadBufPtr)(AH, tmpMag, 5);
 
-    if (strncmp(tmpMag,"PGDMP", 5) != 0)
-       die_horribly("Archiver: Did not fing magic PGDMP in file header\n");
+       if (strncmp(tmpMag,"PGDMP", 5) != 0)
+           die_horribly("Archiver: Did not fing magic PGDMP in file header\n");
 
-    AH->vmaj = (*AH->ReadBytePtr)(AH);
-    AH->vmin = (*AH->ReadBytePtr)(AH);
+       AH->vmaj = (*AH->ReadBytePtr)(AH);
+       AH->vmin = (*AH->ReadBytePtr)(AH);
 
-    if (AH->vmaj > 1 || ( (AH->vmaj == 1) && (AH->vmin > 0) ) ) /* Version > 1.0 */
-    {
-       AH->vrev = (*AH->ReadBytePtr)(AH);
-    } else {
-       AH->vrev = 0;
-    }
+       if (AH->vmaj > 1 || ( (AH->vmaj == 1) && (AH->vmin > 0) ) ) /* Version > 1.0 */
+       {
+           AH->vrev = (*AH->ReadBytePtr)(AH);
+       } else {
+           AH->vrev = 0;
+       }
 
-    AH->version = ( (AH->vmaj * 256 + AH->vmin) * 256 + AH->vrev ) * 256 + 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);
+       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);
+       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");
+       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);
+       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->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)
     {
@@ -1061,8 +1062,9 @@ void ReadHead(ArchiveHandle* AH)
        AH->compression = Z_DEFAULT_COMPRESSION;
     }
 
-#ifndef HAVE_ZLIB
-    fprintf(stderr, "%s: WARNING - archive is compressed - any data will not be available\n", progname);
+#ifndef HAVE_LIBZ
+    if (AH->compression != 0)
+       fprintf(stderr, "%s: WARNING - archive is compressed - any data will not be available\n", progname);
 #endif
 
 }
index 6b0fd47f877ff2f01336982068bfb1a5587fa2d3..2153f3e70770d251542d0023cbae8e09403f9840 100644 (file)
@@ -30,7 +30,7 @@
 \r
 #include <stdio.h>\r
 \r
-#ifdef HAVE_ZLIB\r
+#ifdef HAVE_LIBZ\r
 #include <zlib.h>\r
 #define GZCLOSE(fh) gzclose(fh)\r
 #define GZWRITE(p, s, n, fh) gzwrite(fh, p, n * s)\r
@@ -54,7 +54,7 @@ typedef z_stream *z_streamp;
 \r
 #define K_VERS_MAJOR 1\r
 #define K_VERS_MINOR 2 \r
-#define K_VERS_REV 0 \r
+#define K_VERS_REV 1 \r
 \r
 /* Some important version numbers (checked in code) */\r
 #define K_VERS_1_0 (( (1 * 256 + 0) * 256 + 0) * 256 + 0)\r
index 95483f0e9fd1a219be73b3fddea79c24e495e10f..3edbb751f9a0a80ada721fdc9e9012610083fd64 100644 (file)
@@ -200,7 +200,7 @@ static void _StartData(ArchiveHandle* AH, TocEntry* te)
 \r
     WriteInt(AH, te->id); /* For sanity check */\r
 \r
-#ifdef HAVE_ZLIB\r
+#ifdef HAVE_LIBZ\r
 \r
     if (AH->compression < 0 || AH->compression > 9) {\r
        AH->compression = Z_DEFAULT_COMPRESSION;\r
@@ -230,7 +230,7 @@ static int  _DoDeflate(ArchiveHandle* AH, lclContext* ctx, int flush)
 {\r
     z_streamp   zp = ctx->zp;\r
 \r
-#ifdef HAVE_ZLIB\r
+#ifdef HAVE_LIBZ\r
     char*      out = ctx->zlibOut;\r
     int                res = Z_OK;\r
 \r
@@ -268,14 +268,14 @@ static int        _DoDeflate(ArchiveHandle* AH, lclContext* ctx, int flush)
            ctx->filePos += zp->avail_in;\r
            zp->avail_in = 0;\r
        } else {\r
-#ifdef HAVE_ZLIB\r
+#ifdef HAVE_LIBZ\r
            if (flush == Z_FINISH)\r
                res = Z_STREAM_END;\r
 #endif\r
        }\r
 \r
 \r
-#ifdef HAVE_ZLIB\r
+#ifdef HAVE_LIBZ\r
     }\r
 \r
     return res;\r
@@ -305,7 +305,7 @@ static void _EndData(ArchiveHandle* AH, TocEntry* te)
     lclContext*                ctx = (lclContext*)AH->formatData;\r
     lclTocEntry*       tctx = (lclTocEntry*) te->formatData;\r
 \r
-#ifdef HAVE_ZLIB\r
+#ifdef HAVE_LIBZ\r
     z_streamp          zp = ctx->zp;\r
     int                        res;\r
 \r
@@ -385,7 +385,7 @@ static void _PrintData(ArchiveHandle* AH)
     char*      in = ctx->zlibIn;\r
     int                cnt;\r
 \r
-#ifdef HAVE_ZLIB\r
+#ifdef HAVE_LIBZ\r
 \r
     int                res;\r
     char*      out = ctx->zlibOut;\r
@@ -424,7 +424,7 @@ static void _PrintData(ArchiveHandle* AH)
        zp->next_in = in;\r
        zp->avail_in = blkLen;\r
 \r
-#ifdef HAVE_ZLIB\r
+#ifdef HAVE_LIBZ\r
 \r
        if (AH->compression != 0) {\r
 \r
@@ -443,14 +443,14 @@ static void       _PrintData(ArchiveHandle* AH)
            ahwrite(in, 1, zp->avail_in, AH);\r
            zp->avail_in = 0;\r
 \r
-#ifdef HAVE_ZLIB\r
+#ifdef HAVE_LIBZ\r
        }\r
 #endif\r
 \r
        blkLen = ReadInt(AH);\r
     }\r
 \r
-#ifdef HAVE_ZLIB\r
+#ifdef HAVE_LIBZ\r
     if (AH->compression != 0) \r
     {\r
        zp->next_in = NULL;\r
index bbf30de9aaa953c6648da6a885d59f17ad7e899b..ef2ea57f2ce61971eb1b2e1e7eb84b50fb66ba20 100644 (file)
@@ -54,7 +54,7 @@ typedef struct {
 } lclContext;\r
 \r
 typedef struct {\r
-#ifdef HAVE_ZLIB\r
+#ifdef HAVE_LIBZ\r
     gzFile     *FH;\r
 #else\r
     FILE       *FH;\r
@@ -133,7 +133,7 @@ static void _ArchiveEntry(ArchiveHandle* AH, TocEntry* te)
 \r
     ctx = (lclTocEntry*)malloc(sizeof(lclTocEntry));\r
     if (te->dataDumper) {\r
-#ifdef HAVE_ZLIB\r
+#ifdef HAVE_LIBZ\r
        if (AH->compression == 0) {\r
            sprintf(fn, "%d.dat", te->id);\r
        } else {\r
@@ -192,7 +192,7 @@ static void _StartData(ArchiveHandle* AH, TocEntry* te)
 \r
     sprintf(fmode, "wb%d", AH->compression);\r
 \r
-#ifdef HAVE_ZLIB\r
+#ifdef HAVE_LIBZ\r
     tctx->FH = gzopen(tctx->filename, fmode);\r
 #else\r
     tctx->FH = fopen(tctx->filename, PG_BINARY_W);\r
@@ -229,7 +229,7 @@ static void _PrintTocData(ArchiveHandle* AH, TocEntry* te, RestoreOptions *ropt)
     if (!tctx->filename) \r
        return;\r
 \r
-#ifdef HAVE_ZLIB\r
+#ifdef HAVE_LIBZ\r
     AH->FH = gzopen(tctx->filename,"rb");\r
 #else\r
     AH->FH = fopen(tctx->filename,PG_BINARY_R);\r
index a5fbdf80193a98accbfe55ab816a91fec472a276..d444cb743f4451cfc36f87aab74d95d391b08b20 100644 (file)
@@ -22,7 +22,7 @@
  *
  *
  * 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 - [email protected] - version 1.13.dhb
  *
@@ -3202,10 +3202,9 @@ dumpTables(Archive *fout, TableInfo *tblinfo, int numTables,
                {
 
                        /* Skip VIEW relations */
-
-                       /*
-                        * if (isViewRule(tblinfo[i].relname)) continue;
-                        */
+                       
+                       /* if (isViewRule(tblinfo[i].relname)) continue; */
+                       
 
                        parentRels = tblinfo[i].parentRels;
                        numParents = tblinfo[i].numParents;
index 7097a8e06988b4cfdd2172440316ecd6e2db4890..7b1a17c3f70d63cfa45157eaec7f5f9420a90f79 100644 (file)
@@ -108,7 +108,7 @@ int main(int argc, char **argv)
        char            *progname;\r
        int             c;\r
        Archive*        AH;\r
-       char            *fileSpec;\r
+       char            *fileSpec = NULL;\r
 \r
        opts = NewRestoreOptions();\r
 \r