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

Commit2e155d9

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 parente7c183c commit2e155d9

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
@@ -931,8 +931,12 @@ writeTarData(
931931
#ifdefHAVE_LIBZ
932932
if (ztarfile!=NULL)
933933
{
934+
errno=0;
934935
if (gzwrite(ztarfile,buf,r)!=r)
935936
{
937+
/* if write didn't set errno, assume problem is no disk space */
938+
if (errno==0)
939+
errno=ENOSPC;
936940
fprintf(stderr,
937941
_("%s: could not write to compressed file \"%s\": %s\n"),
938942
progname,current_file,get_gz_error(ztarfile));
@@ -942,8 +946,12 @@ writeTarData(
942946
else
943947
#endif
944948
{
949+
errno=0;
945950
if (fwrite(buf,r,1,tarfile)!=1)
946951
{
952+
/* if write didn't set errno, assume problem is no disk space */
953+
if (errno==0)
954+
errno=ENOSPC;
947955
fprintf(stderr,_("%s: could not write to file \"%s\": %s\n"),
948956
progname,current_file,strerror(errno));
949957
disconnect_and_exit(1);
@@ -1555,8 +1563,12 @@ ReceiveAndUnpackTarFile(PGconn *conn, PGresult *res, int rownum)
15551563
continue;
15561564
}
15571565

1566+
errno=0;
15581567
if (fwrite(copybuf,r,1,file)!=1)
15591568
{
1569+
/* if write didn't set errno, assume problem is no disk space */
1570+
if (errno==0)
1571+
errno=ENOSPC;
15601572
fprintf(stderr,_("%s: could not write to file \"%s\": %s\n"),
15611573
progname,filename,strerror(errno));
15621574
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