pg_basebackup: Error handling fixes.

Thomas Ogrisegg and Fujii Masao
This commit is contained in:
Robert Haas 2012-03-28 12:19:22 -04:00
parent 9f0a017076
commit 4d278b785e
1 changed files with 20 additions and 11 deletions

View File

@ -410,6 +410,7 @@ ReceiveTarFile(PGconn *conn, PGresult *res, int rownum)
{ {
fprintf(stderr, _("%s: could not write to compressed file \"%s\": %s\n"), fprintf(stderr, _("%s: could not write to compressed file \"%s\": %s\n"),
progname, filename, get_gz_error(ztarfile)); progname, filename, get_gz_error(ztarfile));
disconnect_and_exit(1);
} }
} }
else else
@ -423,21 +424,28 @@ ReceiveTarFile(PGconn *conn, PGresult *res, int rownum)
} }
} }
if (strcmp(basedir, "-") == 0)
{
#ifdef HAVE_LIBZ
if (ztarfile)
gzclose(ztarfile);
#endif
}
else
{
#ifdef HAVE_LIBZ #ifdef HAVE_LIBZ
if (ztarfile != NULL) if (ztarfile != NULL)
gzclose(ztarfile); {
if (gzclose(ztarfile) != 0)
{
fprintf(stderr, _("%s: could not close compressed file \"%s\": %s\n"),
progname, filename, get_gz_error(ztarfile));
disconnect_and_exit(1);
}
}
else
#endif #endif
if (tarfile != NULL) {
fclose(tarfile); if (strcmp(basedir, "-") != 0)
{
if (fclose(tarfile) != 0)
{
fprintf(stderr, _("%s: could not close file \"%s\": %s\n"),
progname, filename, strerror(errno));
disconnect_and_exit(1);
}
}
} }
break; break;
@ -456,6 +464,7 @@ ReceiveTarFile(PGconn *conn, PGresult *res, int rownum)
{ {
fprintf(stderr, _("%s: could not write to compressed file \"%s\": %s\n"), fprintf(stderr, _("%s: could not write to compressed file \"%s\": %s\n"),
progname, filename, get_gz_error(ztarfile)); progname, filename, get_gz_error(ztarfile));
disconnect_and_exit(1);
} }
} }
else else