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

Commit411febd

Browse files
committed
Ensure write failure reports no-disk-space
A few places calling fwrite and gzwrite were not setting errno to ENOSPCwhen reporting errors, as is customary; this led to some failures beingreported as"could not write file: Success"which makes us look silly. Make a few of these places in pg_dump andpg_basebackup use our customary pattern.Backpatch-to: 9.5Author: Justin Pryzby <pryzby@telsasoft.com>Author: Tom Lane <tgl@sss.pgh.pa.us>Author: Álvaro Herrera <alvherre@alvh.no-ip.org>Discussion:https://postgr.es/m/20200611153753.GU14879@telsasoft.com
1 parent91e27a3 commit411febd

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

‎src/bin/pg_basebackup/pg_basebackup.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -902,8 +902,12 @@ writeTarData(
902902
#ifdefHAVE_LIBZ
903903
if (ztarfile!=NULL)
904904
{
905+
errno=0;
905906
if (gzwrite(ztarfile,buf,r)!=r)
906907
{
908+
/* if write didn't set errno, assume problem is no disk space */
909+
if (errno==0)
910+
errno=ENOSPC;
907911
fprintf(stderr,
908912
_("%s: could not write to compressed file \"%s\": %s\n"),
909913
progname,current_file,get_gz_error(ztarfile));
@@ -913,8 +917,12 @@ writeTarData(
913917
else
914918
#endif
915919
{
920+
errno=0;
916921
if (fwrite(buf,r,1,tarfile)!=1)
917922
{
923+
/* if write didn't set errno, assume problem is no disk space */
924+
if (errno==0)
925+
errno=ENOSPC;
918926
fprintf(stderr,_("%s: could not write to file \"%s\": %s\n"),
919927
progname,current_file,strerror(errno));
920928
disconnect_and_exit(1);
@@ -1526,8 +1534,12 @@ ReceiveAndUnpackTarFile(PGconn *conn, PGresult *res, int rownum)
15261534
continue;
15271535
}
15281536

1537+
errno=0;
15291538
if (fwrite(copybuf,r,1,file)!=1)
15301539
{
1540+
/* if write didn't set errno, assume problem is no disk space */
1541+
if (errno==0)
1542+
errno=ENOSPC;
15311543
fprintf(stderr,_("%s: could not write to file \"%s\": %s\n"),
15321544
progname,filename,strerror(errno));
15331545
disconnect_and_exit(1);

‎src/bin/pg_dump/pg_backup_directory.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,10 +351,15 @@ _WriteData(ArchiveHandle *AH, const void *data, size_t dLen)
351351
{
352352
lclContext*ctx= (lclContext*)AH->formatData;
353353

354+
errno=0;
354355
if (dLen>0&&cfwrite(data,dLen,ctx->dataFH)!=dLen)
356+
{
357+
/* if write didn't set errno, assume problem is no disk space */
358+
if (errno==0)
359+
errno=ENOSPC;
355360
exit_horribly(modulename,"could not write to output file: %s\n",
356361
get_cfp_error(ctx->dataFH));
357-
362+
}
358363

359364
return;
360365
}
@@ -491,9 +496,15 @@ _WriteByte(ArchiveHandle *AH, const int i)
491496
unsignedcharc= (unsignedchar)i;
492497
lclContext*ctx= (lclContext*)AH->formatData;
493498

499+
errno=0;
494500
if (cfwrite(&c,1,ctx->dataFH)!=1)
501+
{
502+
/* if write didn't set errno, assume problem is no disk space */
503+
if (errno==0)
504+
errno=ENOSPC;
495505
exit_horribly(modulename,"could not write to output file: %s\n",
496506
get_cfp_error(ctx->dataFH));
507+
}
497508

498509
return1;
499510
}
@@ -521,9 +532,15 @@ _WriteBuf(ArchiveHandle *AH, const void *buf, size_t len)
521532
{
522533
lclContext*ctx= (lclContext*)AH->formatData;
523534

535+
errno=0;
524536
if (cfwrite(buf,len,ctx->dataFH)!=len)
537+
{
538+
/* if write didn't set errno, assume problem is no disk space */
539+
if (errno==0)
540+
errno=ENOSPC;
525541
exit_horribly(modulename,"could not write to output file: %s\n",
526542
get_cfp_error(ctx->dataFH));
543+
}
527544

528545
return;
529546
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp