Add strerror to pg_dump error messages where missing.
authorPeter Eisentraut
Mon, 22 May 2006 11:21:54 +0000 (11:21 +0000)
committerPeter Eisentraut
Mon, 22 May 2006 11:21:54 +0000 (11:21 +0000)
src/bin/pg_dump/common.c
src/bin/pg_dump/pg_backup_archiver.c
src/bin/pg_dump/pg_backup_custom.c
src/bin/pg_dump/pg_backup_files.c
src/bin/pg_dump/pg_backup_tar.c
src/bin/pg_dump/pg_dumpall.c

index bbbef5c51ff6606bb01d42b7e3451d62b1a0f8aa..102ed6a844bea307c654368f74d53885fa0c9dde 100644 (file)
@@ -11,7 +11,7 @@
  *
  *
  * IDENTIFICATION
- *   $PostgreSQL: pgsql/src/bin/pg_dump/common.c,v 1.89 2006/03/05 15:58:50 momjian Exp $
+ *   $PostgreSQL: pgsql/src/bin/pg_dump/common.c,v 1.90 2006/05/22 11:21:54 petere Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -768,7 +768,7 @@ parseOidArray(const char *str, Oid *array, int arraysize)
            {
                if (argNum >= arraysize)
                {
-                   write_msg(NULL, "could not parse numeric array: too many numbers\n");
+                   write_msg(NULL, "could not parse numeric array \"%s\": too many numbers\n", str);
                    exit_nicely();
                }
                temp[j] = '\0';
@@ -783,7 +783,7 @@ parseOidArray(const char *str, Oid *array, int arraysize)
            if (!(isdigit((unsigned char) s) || s == '-') ||
                j >= sizeof(temp) - 1)
            {
-               write_msg(NULL, "could not parse numeric array: invalid character in number\n");
+               write_msg(NULL, "could not parse numeric array \"%s\": invalid character in number\n", str);
                exit_nicely();
            }
            temp[j++] = s;
index 0f56a647f2e6af44eb7186e6d5a97db9fa7e9080..55cbf64bd0c268d4c644af39bcc170b185de3bcf 100644 (file)
@@ -15,7 +15,7 @@
  *
  *
  * IDENTIFICATION
- *     $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.127 2006/04/19 16:02:17 tgl Exp $
+ *     $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.128 2006/05/22 11:21:54 petere Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -122,7 +122,8 @@ CloseArchive(Archive *AHX)
        res = fclose(AH->OF);
 
    if (res != 0)
-       die_horribly(AH, modulename, "could not close output archive file\n");
+       die_horribly(AH, modulename, "could not close output file: %s\n",
+                    strerror(errno));
 }
 
 /* Public */
@@ -306,7 +307,7 @@ RestoreArchive(Archive *AHX, RestoreOptions *ropt)
                {
 #ifndef HAVE_LIBZ
                    if (AH->compression != 0)
-                       die_horribly(AH, modulename, "cannot restore from compressed archive (not configured for compression support)\n");
+                       die_horribly(AH, modulename, "cannot restore from compressed archive (compression not supported in this installation)\n");
 #endif
 
                    _printTocEntry(AH, te, ropt, true, false);
@@ -774,7 +775,8 @@ SortTocFromFile(Archive *AHX, RestoreOptions *ropt)
    /* Setup the file */
    fh = fopen(ropt->tocFile, PG_BINARY_R);
    if (!fh)
-       die_horribly(AH, modulename, "could not open TOC file\n");
+       die_horribly(AH, modulename, "could not open TOC file: %s\n",
+                    strerror(errno));
 
    while (fgets(buf, sizeof(buf), fh) != NULL)
    {
@@ -1066,7 +1068,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, modulename, "could not write to compressed archive\n");
+           die_horribly(AH, modulename, "could not write to output file: %s\n", strerror(errno));
        return res;
    }
    else if (AH->CustomOutPtr)
@@ -1089,8 +1091,8 @@ 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, modulename, "could not write to output file (%lu != %lu)\n",
-                            (unsigned long) res, (unsigned long) nmemb);
+               die_horribly(AH, modulename, "could not write to output file: %s\n",
+                            strerror(errno));
            return res;
        }
    }
@@ -1321,7 +1323,7 @@ ReadOffset(ArchiveHandle *AH, off_t *o)
            break;
 
        default:
-           die_horribly(AH, modulename, "Unexpected data offset flag %d\n", offsetFlg);
+           die_horribly(AH, modulename, "unexpected data offset flag %d\n", offsetFlg);
    }
 
    /*
@@ -1556,7 +1558,7 @@ _discoverArchiveFormat(ArchiveHandle *AH)
    /* Close the file */
    if (wantClose)
        if (fclose(fh) != 0)
-           die_horribly(AH, modulename, "could not close the input file after reading header: %s\n",
+           die_horribly(AH, modulename, "could not close input file: %s\n",
                         strerror(errno));
 
    return AH->format;
index 3edbb8f5c0a6c5bb4eb790be02168c12c9903546..41b7bc2313587ab22f5063cb92ab923b4344f7e2 100644 (file)
@@ -19,7 +19,7 @@
  *
  *
  * IDENTIFICATION
- *     $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_custom.c,v 1.33 2005/10/15 02:49:38 momjian Exp $
+ *     $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_custom.c,v 1.34 2006/05/22 11:21:54 petere Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -175,7 +175,7 @@ InitArchiveFmt_Custom(ArchiveHandle *AH)
            AH->FH = stdout;
 
        if (!AH->FH)
-           die_horribly(AH, modulename, "could not open archive file \"%s\": %s\n", AH->fSpec, strerror(errno));
+           die_horribly(AH, modulename, "could not open output file \"%s\": %s\n", AH->fSpec, strerror(errno));
 
        ctx->hasSeek = checkSeek(AH->FH);
    }
@@ -186,7 +186,7 @@ InitArchiveFmt_Custom(ArchiveHandle *AH)
        else
            AH->FH = stdin;
        if (!AH->FH)
-           die_horribly(AH, modulename, "could not open archive file \"%s\": %s\n", AH->fSpec, strerror(errno));
+           die_horribly(AH, modulename, "could not open input file \"%s\": %s\n", AH->fSpec, strerror(errno));
 
        ctx->hasSeek = checkSeek(AH->FH);
 
@@ -438,7 +438,7 @@ _PrintTocData(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt)
        {
            if ((TocIDRequired(AH, id, ropt) & REQ_DATA) != 0)
                die_horribly(AH, modulename,
-                            "Dumping a specific TOC data block out of order is not supported"
+                            "dumping a specific TOC data block out of order is not supported"
                      " without ID on this input stream (fseek required)\n");
 
            switch (blkType)
@@ -540,9 +540,14 @@ _PrintData(ArchiveHandle *AH)
 
        cnt = fread(in, 1, blkLen, AH->FH);
        if (cnt != blkLen)
-           die_horribly(AH, modulename,
-                     "could not read data block -- expected %lu, got %lu\n",
-                        (unsigned long) blkLen, (unsigned long) cnt);
+       {
+           if (feof(AH->FH))
+               die_horribly(AH, modulename,
+                            "could not read from input file: end of file\n");
+           else
+               die_horribly(AH, modulename,
+                            "could not read from input file: %s\n", strerror(errno));
+       }
 
        ctx->filePos += blkLen;
 
@@ -663,9 +668,14 @@ _skipData(ArchiveHandle *AH)
        }
        cnt = fread(in, 1, blkLen, AH->FH);
        if (cnt != blkLen)
-           die_horribly(AH, modulename,
-                     "could not read data block -- expected %lu, got %lu\n",
-                        (unsigned long) blkLen, (unsigned long) cnt);
+       {
+           if (feof(AH->FH))
+               die_horribly(AH, modulename,
+                            "could not read from input file: end of file\n");
+           else
+               die_horribly(AH, modulename,
+                            "could not read from input file: %s\n", strerror(errno));
+       }
 
        ctx->filePos += blkLen;
 
@@ -736,8 +746,7 @@ _WriteBuf(ArchiveHandle *AH, const void *buf, size_t len)
 
    if (res != len)
        die_horribly(AH, modulename,
-                    "write error in _WriteBuf (%lu != %lu)\n",
-                    (unsigned long) res, (unsigned long) len);
+                    "could not write to output file: %s\n", strerror(errno));
 
    ctx->filePos += res;
    return res;
@@ -929,7 +938,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, modulename, "could not write compressed chunk\n");
+                   die_horribly(AH, modulename, "could not write to output file: %s\n", strerror(errno));
                ctx->filePos += zlibOutSize - zp->avail_out;
            }
            zp->next_out = (void *) out;
@@ -943,7 +952,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, modulename, "could not write uncompressed chunk\n");
+               die_horribly(AH, modulename, "could not write to output file: %s\n", strerror(errno));
            ctx->filePos += zp->avail_in;
            zp->avail_in = 0;
        }
index b36a1c8600f2602f27f55e736932255c2161d04f..b882598f77dc17528fb41592abcdd9a18d472de6 100644 (file)
@@ -20,7 +20,7 @@
  *
  *
  * IDENTIFICATION
- *     $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_files.c,v 1.27 2005/10/15 02:49:38 momjian Exp $
+ *     $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_files.c,v 1.28 2006/05/22 11:21:54 petere Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -243,7 +243,7 @@ _StartData(ArchiveHandle *AH, TocEntry *te)
 #endif
 
    if (tctx->FH == NULL)
-       die_horribly(AH, modulename, "could not open data file for output\n");
+       die_horribly(AH, modulename, "could not open output file: %s\n", strerror(errno));
 }
 
 static size_t
@@ -287,7 +287,7 @@ _PrintFileData(ArchiveHandle *AH, char *filename, RestoreOptions *ropt)
 #endif
 
    if (AH->FH == NULL)
-       die_horribly(AH, modulename, "could not open data file for input\n");
+       die_horribly(AH, modulename, "could not open input file: %s\n", strerror(errno));
 
    while ((cnt = GZREAD(buf, 1, 4095, AH->FH)) > 0)
    {
@@ -411,7 +411,7 @@ _WriteBuf(ArchiveHandle *AH, const void *buf, size_t len)
 
    res = fwrite(buf, 1, len, AH->FH);
    if (res != len)
-       die_horribly(AH, modulename, "write error in _WriteBuf (%lu != %lu)\n", (unsigned long) res, (unsigned long) len);
+       die_horribly(AH, modulename, "could not write to output file: %s\n", strerror(errno));
 
    ctx->filePos += res;
    return res;
@@ -508,7 +508,7 @@ _StartBlob(ArchiveHandle *AH, TocEntry *te, Oid oid)
 #endif
 
    if (tctx->FH == NULL)
-       die_horribly(AH, modulename, "could not open large object file\n");
+       die_horribly(AH, modulename, "could not open large object file for input: %s\n", strerror(errno));
 }
 
 /*
index b777fa140e507362cec32d8c28d9d1172363b870..bb490e2aefbd8a619272018a76a31e7df5f72569 100644 (file)
@@ -16,7 +16,7 @@
  *
  *
  * IDENTIFICATION
- *     $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_tar.c,v 1.50 2006/02/12 06:11:50 momjian Exp $
+ *     $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_tar.c,v 1.51 2006/05/22 11:21:54 petere Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -546,8 +546,7 @@ tarWrite(const void *buf, size_t len, TAR_MEMBER *th)
 
    if (res != len)
        die_horribly(th->AH, modulename,
-               "could not write to tar member (wrote %lu, attempted %lu)\n",
-                    (unsigned long) res, (unsigned long) len);
+                    "could not write to output file: %s\n", strerror(errno));
 
    th->pos += res;
    return res;
@@ -1035,13 +1034,12 @@ _tarAddFile(ArchiveHandle *AH, TAR_MEMBER *th)
        res = fwrite(&buf[0], 1, cnt, th->tarFH);
        if (res != cnt)
            die_horribly(AH, modulename,
-                        "write error appending to tar archive (wrote %lu, attempted %lu)\n",
-                        (unsigned long) res, (unsigned long) cnt);
+                        "could not write to output file: %s\n", strerror(errno));
        len += res;
    }
 
    if (fclose(tmp) != 0)       /* This *should* delete it... */
-       die_horribly(AH, modulename, "could not close tar member: %s\n", strerror(errno));
+       die_horribly(AH, modulename, "could not close temporary file: %s\n", strerror(errno));
 
    if (len != th->fileLen)
    {
@@ -1327,6 +1325,6 @@ _tarWriteHeader(TAR_MEMBER *th)
    }
 
    if (fwrite(h, 1, 512, th->tarFH) != 512)
-       die_horribly(th->AH, modulename, "could not write tar header\n");
+       die_horribly(th->AH, modulename, "could not write to output file: %s\n", strerror(errno));
 
 }
index 71edfde398dbff1b697e1a9d39c8f51e58d804de..e8c22e510df39eda6e3f9775cfbd76db5097516a 100644 (file)
@@ -6,7 +6,7 @@
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  *
- * $PostgreSQL: pgsql/src/bin/pg_dump/pg_dumpall.c,v 1.74 2006/04/07 21:26:29 tgl Exp $
+ * $PostgreSQL: pgsql/src/bin/pg_dump/pg_dumpall.c,v 1.75 2006/05/22 11:21:54 petere Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -38,8 +38,8 @@ int           optreset;
 #include "pqexpbuffer.h"
 
 
-/* version string we expect back from postgres */
-#define PG_VERSIONSTR "pg_dump (PostgreSQL) " PG_VERSION "\n"
+/* version string we expect back from pg_dump */
+#define PGDUMP_VERSIONSTR "pg_dump (PostgreSQL) " PG_VERSION "\n"
 
 
 static const char *progname;
@@ -142,7 +142,7 @@ main(int argc, char *argv[])
        }
    }
 
-   if ((ret = find_other_exec(argv[0], "pg_dump", PG_VERSIONSTR,
+   if ((ret = find_other_exec(argv[0], "pg_dump", PGDUMP_VERSIONSTR,
                               pg_dump_bin)) < 0)
    {
        char        full_path[MAXPGPATH];