Skip to content

Commit

Permalink
fix of the zlib error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
kunschikov committed Apr 5, 2017
1 parent afd7987 commit 15e9fda
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
16 changes: 14 additions & 2 deletions src/bin/pg_dump/compress_io.c
Expand Up @@ -593,7 +593,7 @@ cfread(void *ptr, int size, cfp *fp)
ret = gzread(fp->compressedfp, ptr, size);
if (ret != size && !gzeof(fp->compressedfp))
exit_horribly(modulename,
"could not read from input file: %s\n", strerror(errno));
"could not read from input file: %s\n", get_gz_error(fp->compressedfp));
}
else
#endif
Expand Down Expand Up @@ -629,7 +629,7 @@ cfgetc(cfp *fp)
{
if (!gzeof(fp->compressedfp))
exit_horribly(modulename,
"could not read from input file: %s\n", strerror(errno));
"could not read from input file: %s\n", get_gz_error(fp->compressedfp));
else
exit_horribly(modulename,
"could not read from input file: end of file\n");
Expand Down Expand Up @@ -710,4 +710,16 @@ hasSuffix(const char *filename, const char *suffix)
suffixlen) == 0;
}

const char *
get_gz_error(gzFile gzf)
{
int errnum;
const char *errmsg;

errmsg = gzerror(gzf, &errnum);
if (errnum == Z_ERRNO)
return strerror(errno);
else
return errmsg;
}
#endif
1 change: 1 addition & 0 deletions src/bin/pg_dump/compress_io.h
Expand Up @@ -52,6 +52,7 @@ extern void ReadDataFromArchive(ArchiveHandle *AH, int compression,
extern void WriteDataToArchive(ArchiveHandle *AH, CompressorState *cs,
const void *data, size_t dLen);
extern void EndCompressor(ArchiveHandle *AH, CompressorState *cs);
extern const char * get_gz_error(gzFile gzf);


typedef struct cfp cfp;
Expand Down
3 changes: 2 additions & 1 deletion src/bin/pg_dump/pg_backup_tar.c
Expand Up @@ -35,6 +35,7 @@
#include "pgtar.h"
#include "common/file_utils.h"
#include "fe_utils/string_utils.h"
#include "compress_io.h"

#include <sys/stat.h>
#include <ctype.h>
Expand Down Expand Up @@ -556,7 +557,7 @@ _tarReadRaw(ArchiveHandle *AH, void *buf, size_t len, TAR_MEMBER *th, FILE *fh)
res = GZREAD(&((char *) buf)[used], 1, len, th->zFH);
if (res != len && !GZEOF(th->zFH))
exit_horribly(modulename,
"could not read from input file: %s\n", strerror(errno));
"could not read from input file: %s\n", get_gz_error(th->zFH));
}
else
{
Expand Down

0 comments on commit 15e9fda

Please sign in to comment.