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

Commit 4d278b7

Browse files
committed
pg_basebackup: Error handling fixes.
Thomas Ogrisegg and Fujii Masao
1 parent 9f0a017 commit 4d278b7

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed

src/bin/pg_basebackup/pg_basebackup.c

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,7 @@ ReceiveTarFile(PGconn *conn, PGresult *res, int rownum)
410410
{
411411
fprintf(stderr, _("%s: could not write to compressed file \"%s\": %s\n"),
412412
progname, filename, get_gz_error(ztarfile));
413+
disconnect_and_exit(1);
413414
}
414415
}
415416
else
@@ -423,21 +424,28 @@ ReceiveTarFile(PGconn *conn, PGresult *res, int rownum)
423424
}
424425
}
425426

426-
if (strcmp(basedir, "-") == 0)
427-
{
428427
#ifdef HAVE_LIBZ
429-
if (ztarfile)
430-
gzclose(ztarfile);
431-
#endif
428+
if (ztarfile != NULL)
429+
{
430+
if (gzclose(ztarfile) != 0)
431+
{
432+
fprintf(stderr, _("%s: could not close compressed file \"%s\": %s\n"),
433+
progname, filename, get_gz_error(ztarfile));
434+
disconnect_and_exit(1);
435+
}
432436
}
433437
else
434-
{
435-
#ifdef HAVE_LIBZ
436-
if (ztarfile != NULL)
437-
gzclose(ztarfile);
438438
#endif
439-
if (tarfile != NULL)
440-
fclose(tarfile);
439+
{
440+
if (strcmp(basedir, "-") != 0)
441+
{
442+
if (fclose(tarfile) != 0)
443+
{
444+
fprintf(stderr, _("%s: could not close file \"%s\": %s\n"),
445+
progname, filename, strerror(errno));
446+
disconnect_and_exit(1);
447+
}
448+
}
441449
}
442450

443451
break;
@@ -456,6 +464,7 @@ ReceiveTarFile(PGconn *conn, PGresult *res, int rownum)
456464
{
457465
fprintf(stderr, _("%s: could not write to compressed file \"%s\": %s\n"),
458466
progname, filename, get_gz_error(ztarfile));
467+
disconnect_and_exit(1);
459468
}
460469
}
461470
else

0 commit comments

Comments
 (0)