Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4d57e83

Browse files
committed
Fix pg_dump's errno checking for zlib I/O
Some error reports were reporting strerror(errno), which for some errorconditions coming from zlib are wrong, resulting in confusing reportssuch as pg_restore: [compress_io] could not read from input file: Successwhich makes no sense. To correctly extract the error message we need touse gzerror(), so let's do that.This isn't as comprehensive or as neat as I would like, but at least itshould improve things in many common cases. The zlib abstraction incompress_io does not seem to be applied consistently enough; we couldperhaps improve that, but it seems master-only material, not a bug fixfor back-patching.This problem goes back all the way, but I decided to apply back to 9.4only, because older branches don't contain commit14ea893 which thischange depends on.Authors: Vladimir Kunschikov, Álvaro HerreraDiscussion:https://postgr.es/m/1498120508308.9826@infotecs.ru
1 parent8021515 commit4d57e83

File tree

4 files changed

+38
-5
lines changed

4 files changed

+38
-5
lines changed

‎src/bin/pg_dump/compress_io.c

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -592,8 +592,14 @@ cfread(void *ptr, int size, cfp *fp)
592592
{
593593
ret=gzread(fp->compressedfp,ptr,size);
594594
if (ret!=size&& !gzeof(fp->compressedfp))
595+
{
596+
interrnum;
597+
constchar*errmsg=gzerror(fp->compressedfp,&errnum);
598+
595599
exit_horribly(modulename,
596-
"could not read from input file: %s\n",strerror(errno));
600+
"could not read from input file: %s\n",
601+
errnum==Z_ERRNO ?strerror(errno) :errmsg);
602+
}
597603
}
598604
else
599605
#endif
@@ -695,6 +701,22 @@ cfeof(cfp *fp)
695701
returnfeof(fp->uncompressedfp);
696702
}
697703

704+
constchar*
705+
get_cfp_error(cfp*fp)
706+
{
707+
#ifdefHAVE_LIBZ
708+
if (fp->compressedfp)
709+
{
710+
interrnum;
711+
constchar*errmsg=gzerror(fp->compressedfp,&errnum);
712+
713+
if (errnum!=Z_ERRNO)
714+
returnerrmsg;
715+
}
716+
#endif
717+
returnstrerror(errno);
718+
}
719+
698720
#ifdefHAVE_LIBZ
699721
staticint
700722
hasSuffix(constchar*filename,constchar*suffix)

‎src/bin/pg_dump/compress_io.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,5 +65,6 @@ extern intcfgetc(cfp *fp);
6565
externchar*cfgets(cfp*fp,char*buf,intlen);
6666
externintcfclose(cfp*fp);
6767
externintcfeof(cfp*fp);
68+
externconstchar*get_cfp_error(cfp*fp);
6869

6970
#endif

‎src/bin/pg_dump/pg_backup_directory.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,9 @@ _WriteData(ArchiveHandle *AH, const void *data, size_t dLen)
352352
lclContext*ctx= (lclContext*)AH->formatData;
353353

354354
if (dLen>0&&cfwrite(data,dLen,ctx->dataFH)!=dLen)
355-
WRITE_ERROR_EXIT;
355+
exit_horribly(modulename,"could not write to output file: %s\n",
356+
get_cfp_error(ctx->dataFH));
357+
356358

357359
return;
358360
}
@@ -490,7 +492,8 @@ _WriteByte(ArchiveHandle *AH, const int i)
490492
lclContext*ctx= (lclContext*)AH->formatData;
491493

492494
if (cfwrite(&c,1,ctx->dataFH)!=1)
493-
WRITE_ERROR_EXIT;
495+
exit_horribly(modulename,"could not write to output file: %s\n",
496+
get_cfp_error(ctx->dataFH));
494497

495498
return1;
496499
}
@@ -519,7 +522,8 @@ _WriteBuf(ArchiveHandle *AH, const void *buf, size_t len)
519522
lclContext*ctx= (lclContext*)AH->formatData;
520523

521524
if (cfwrite(buf,len,ctx->dataFH)!=len)
522-
WRITE_ERROR_EXIT;
525+
exit_horribly(modulename,"could not write to output file: %s\n",
526+
get_cfp_error(ctx->dataFH));
523527

524528
return;
525529
}

‎src/bin/pg_dump/pg_backup_tar.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -555,8 +555,14 @@ _tarReadRaw(ArchiveHandle *AH, void *buf, size_t len, TAR_MEMBER *th, FILE *fh)
555555
{
556556
res=GZREAD(&((char*)buf)[used],1,len,th->zFH);
557557
if (res!=len&& !GZEOF(th->zFH))
558+
{
559+
interrnum;
560+
constchar*errmsg=gzerror(th->zFH,&errnum);
561+
558562
exit_horribly(modulename,
559-
"could not read from input file: %s\n",strerror(errno));
563+
"could not read from input file: %s\n",
564+
errnum==Z_ERRNO ?strerror(errno) :errmsg);
565+
}
560566
}
561567
else
562568
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp