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

Commit060393f

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 parente5c87d5 commit060393f

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
@@ -357,7 +357,9 @@ _WriteData(ArchiveHandle *AH, const void *data, size_t dLen)
357357
lclContext*ctx= (lclContext*)AH->formatData;
358358

359359
if (dLen>0&&cfwrite(data,dLen,ctx->dataFH)!=dLen)
360-
WRITE_ERROR_EXIT;
360+
exit_horribly(modulename,"could not write to output file: %s\n",
361+
get_cfp_error(ctx->dataFH));
362+
361363

362364
return;
363365
}
@@ -495,7 +497,8 @@ _WriteByte(ArchiveHandle *AH, const int i)
495497
lclContext*ctx= (lclContext*)AH->formatData;
496498

497499
if (cfwrite(&c,1,ctx->dataFH)!=1)
498-
WRITE_ERROR_EXIT;
500+
exit_horribly(modulename,"could not write to output file: %s\n",
501+
get_cfp_error(ctx->dataFH));
499502

500503
return1;
501504
}
@@ -524,7 +527,8 @@ _WriteBuf(ArchiveHandle *AH, const void *buf, size_t len)
524527
lclContext*ctx= (lclContext*)AH->formatData;
525528

526529
if (cfwrite(buf,len,ctx->dataFH)!=len)
527-
WRITE_ERROR_EXIT;
530+
exit_horribly(modulename,"could not write to output file: %s\n",
531+
get_cfp_error(ctx->dataFH));
528532

529533
return;
530534
}

‎src/bin/pg_dump/pg_backup_tar.c

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

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp