Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit ae3259c

Browse files
committed
Ensure write failure reports no-disk-space
A few places calling fwrite and gzwrite were not setting errno to ENOSPC when reporting errors, as is customary; this led to some failures being reported as "could not write file: Success" which makes us look silly. Make a few of these places in pg_dump and pg_basebackup use our customary pattern. Backpatch-to: 9.5 Author: 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 parent 2c8ef93 commit ae3259c

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

src/bin/pg_basebackup/pg_basebackup.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -992,8 +992,12 @@ writeTarData(WriteTarState *state, char *buf, int r)
992992
#ifdef HAVE_LIBZ
993993
if (state->ztarfile != NULL)
994994
{
995+
errno = 0;
995996
if (gzwrite(state->ztarfile, buf, r) != r)
996997
{
998+
/* if write didn't set errno, assume problem is no disk space */
999+
if (errno == 0)
1000+
errno = ENOSPC;
9971001
pg_log_error("could not write to compressed file \"%s\": %s",
9981002
state->filename, get_gz_error(state->ztarfile));
9991003
exit(1);
@@ -1002,8 +1006,12 @@ writeTarData(WriteTarState *state, char *buf, int r)
10021006
else
10031007
#endif
10041008
{
1009+
errno = 0;
10051010
if (fwrite(buf, r, 1, state->tarfile) != 1)
10061011
{
1012+
/* if write didn't set errno, assume problem is no disk space */
1013+
if (errno == 0)
1014+
errno = ENOSPC;
10071015
pg_log_error("could not write to file \"%s\": %m",
10081016
state->filename);
10091017
exit(1);
@@ -1691,8 +1699,12 @@ ReceiveTarAndUnpackCopyChunk(size_t r, char *copybuf, void *callback_data)
16911699
return;
16921700
}
16931701

1702+
errno = 0;
16941703
if (fwrite(copybuf, r, 1, state->file) != 1)
16951704
{
1705+
/* if write didn't set errno, assume problem is no disk space */
1706+
if (errno == 0)
1707+
errno = ENOSPC;
16961708
pg_log_error("could not write to file \"%s\": %m", state->filename);
16971709
exit(1);
16981710
}
@@ -1743,8 +1755,12 @@ ReceiveBackupManifestChunk(size_t r, char *copybuf, void *callback_data)
17431755
{
17441756
WriteManifestState *state = callback_data;
17451757

1758+
errno = 0;
17461759
if (fwrite(copybuf, r, 1, state->file) != 1)
17471760
{
1761+
/* if write didn't set errno, assume problem is no disk space */
1762+
if (errno == 0)
1763+
errno = ENOSPC;
17481764
pg_log_error("could not write to file \"%s\": %m", state->filename);
17491765
exit(1);
17501766
}

src/bin/pg_dump/pg_backup_directory.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,9 +346,15 @@ _WriteData(ArchiveHandle *AH, const void *data, size_t dLen)
346346
{
347347
lclContext *ctx = (lclContext *) AH->formatData;
348348

349+
errno = 0;
349350
if (dLen > 0 && cfwrite(data, dLen, ctx->dataFH) != dLen)
351+
{
352+
/* if write didn't set errno, assume problem is no disk space */
353+
if (errno == 0)
354+
errno = ENOSPC;
350355
fatal("could not write to output file: %s",
351356
get_cfp_error(ctx->dataFH));
357+
}
352358
}
353359

354360
/*
@@ -481,9 +487,15 @@ _WriteByte(ArchiveHandle *AH, const int i)
481487
unsigned char c = (unsigned char) i;
482488
lclContext *ctx = (lclContext *) AH->formatData;
483489

490+
errno = 0;
484491
if (cfwrite(&c, 1, ctx->dataFH) != 1)
492+
{
493+
/* if write didn't set errno, assume problem is no disk space */
494+
if (errno == 0)
495+
errno = ENOSPC;
485496
fatal("could not write to output file: %s",
486497
get_cfp_error(ctx->dataFH));
498+
}
487499

488500
return 1;
489501
}
@@ -511,9 +523,15 @@ _WriteBuf(ArchiveHandle *AH, const void *buf, size_t len)
511523
{
512524
lclContext *ctx = (lclContext *) AH->formatData;
513525

526+
errno = 0;
514527
if (cfwrite(buf, len, ctx->dataFH) != len)
528+
{
529+
/* if write didn't set errno, assume problem is no disk space */
530+
if (errno == 0)
531+
errno = ENOSPC;
515532
fatal("could not write to output file: %s",
516533
get_cfp_error(ctx->dataFH));
534+
}
517535
}
518536

519537
/*

0 commit comments

Comments
 (0)