Skip to content

Commit 8ac4c25

Browse files
committed
Clean up some dead code in pg_dump with tar format and gzip compression
Compression with gzip has never been supported in the tar format of pg_dump since this code has been introduced in c3e1880, as the use of buffered I/O in gzdopen() changes the file positioning that tar requires. The original idea behind the use of compression with the tar mode is to be able to include compressed data files (named %u.dat.gz) and blob files (blob_%u.dat.gz) in the tarball generated by the dump, with toc.dat, that tracks down if compression is used in the dump, always uncompressed. Note that this commit removes the dump part of the code as well as the restore part, removing any dependency to zlib in pg_backup_tar.c. There could be an argument behind keeping around the restore part, but this would require one to change the internals of a tarball previously dumped so as data and blob files are compressed with toc.dat itself changed to track down if compression is enabled. However, the argument about gzdopen() still holds in the read case with pg_restore. Removing this code simplifies future additions related to compression in pg_dump. Author: Georgios Kokolatos, Rachel Heaton Discussion: https://postgr.es/m/faUNEOpts9vunEaLnmxmG-DldLSg_ql137OC3JYDmgrOMHm1RvvWY2IdBkv_CRxm5spCCb_OmKNk2T03TMm0fBEWveFF9wA1WizPuAgB7Ss=@protonmail.com
1 parent f8e0d90 commit 8ac4c25

File tree

1 file changed

+11
-78
lines changed

1 file changed

+11
-78
lines changed

src/bin/pg_dump/pg_backup_tar.c

Lines changed: 11 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,6 @@ static void _EndBlobs(ArchiveHandle *AH, TocEntry *te);
6565

6666
typedef struct
6767
{
68-
#ifdef HAVE_LIBZ
69-
gzFile zFH;
70-
#else
71-
FILE *zFH;
72-
#endif
7368
FILE *nFH;
7469
FILE *tarFH;
7570
FILE *tmpFH;
@@ -248,14 +243,7 @@ _ArchiveEntry(ArchiveHandle *AH, TocEntry *te)
248243
ctx = (lclTocEntry *) pg_malloc0(sizeof(lclTocEntry));
249244
if (te->dataDumper != NULL)
250245
{
251-
#ifdef HAVE_LIBZ
252-
if (AH->compression == 0)
253-
sprintf(fn, "%d.dat", te->dumpId);
254-
else
255-
sprintf(fn, "%d.dat.gz", te->dumpId);
256-
#else
257-
sprintf(fn, "%d.dat", te->dumpId);
258-
#endif
246+
snprintf(fn, sizeof(fn), "%d.dat", te->dumpId);
259247
ctx->filename = pg_strdup(fn);
260248
}
261249
else
@@ -320,10 +308,6 @@ tarOpen(ArchiveHandle *AH, const char *filename, char mode)
320308
lclContext *ctx = (lclContext *) AH->formatData;
321309
TAR_MEMBER *tm;
322310

323-
#ifdef HAVE_LIBZ
324-
char fmode[14];
325-
#endif
326-
327311
if (mode == 'r')
328312
{
329313
tm = _tarPositionTo(AH, filename);
@@ -344,16 +328,10 @@ tarOpen(ArchiveHandle *AH, const char *filename, char mode)
344328
}
345329
}
346330

347-
#ifdef HAVE_LIBZ
348-
349331
if (AH->compression == 0)
350332
tm->nFH = ctx->tarFH;
351333
else
352334
fatal("compression is not supported by tar archive format");
353-
/* tm->zFH = gzdopen(dup(fileno(ctx->tarFH)), "rb"); */
354-
#else
355-
tm->nFH = ctx->tarFH;
356-
#endif
357335
}
358336
else
359337
{
@@ -405,21 +383,10 @@ tarOpen(ArchiveHandle *AH, const char *filename, char mode)
405383

406384
umask(old_umask);
407385

408-
#ifdef HAVE_LIBZ
409-
410-
if (AH->compression != 0)
411-
{
412-
sprintf(fmode, "wb%d", AH->compression);
413-
tm->zFH = gzdopen(dup(fileno(tm->tmpFH)), fmode);
414-
if (tm->zFH == NULL)
415-
fatal("could not open temporary file");
416-
}
417-
else
386+
if (AH->compression == 0)
418387
tm->nFH = tm->tmpFH;
419-
#else
420-
421-
tm->nFH = tm->tmpFH;
422-
#endif
388+
else
389+
fatal("compression is not supported by tar archive format");
423390

424391
tm->AH = AH;
425392
tm->targetFile = pg_strdup(filename);
@@ -434,15 +401,8 @@ tarOpen(ArchiveHandle *AH, const char *filename, char mode)
434401
static void
435402
tarClose(ArchiveHandle *AH, TAR_MEMBER *th)
436403
{
437-
/*
438-
* Close the GZ file since we dup'd. This will flush the buffers.
439-
*/
440404
if (AH->compression != 0)
441-
{
442-
errno = 0; /* in case gzclose() doesn't set it */
443-
if (GZCLOSE(th->zFH) != 0)
444-
fatal("could not close tar member: %m");
445-
}
405+
fatal("compression is not supported by tar archive format");
446406

447407
if (th->mode == 'w')
448408
_tarAddFile(AH, th); /* This will close the temp file */
@@ -456,7 +416,6 @@ tarClose(ArchiveHandle *AH, TAR_MEMBER *th)
456416
free(th->targetFile);
457417

458418
th->nFH = NULL;
459-
th->zFH = NULL;
460419
}
461420

462421
#ifdef __NOT_USED__
@@ -542,29 +501,9 @@ _tarReadRaw(ArchiveHandle *AH, void *buf, size_t len, TAR_MEMBER *th, FILE *fh)
542501
}
543502
else if (th)
544503
{
545-
if (th->zFH)
546-
{
547-
res = GZREAD(&((char *) buf)[used], 1, len, th->zFH);
548-
if (res != len && !GZEOF(th->zFH))
549-
{
550-
#ifdef HAVE_LIBZ
551-
int errnum;
552-
const char *errmsg = gzerror(th->zFH, &errnum);
553-
554-
fatal("could not read from input file: %s",
555-
errnum == Z_ERRNO ? strerror(errno) : errmsg);
556-
#else
557-
fatal("could not read from input file: %s",
558-
strerror(errno));
559-
#endif
560-
}
561-
}
562-
else
563-
{
564-
res = fread(&((char *) buf)[used], 1, len, th->nFH);
565-
if (res != len && !feof(th->nFH))
566-
READ_ERROR_EXIT(th->nFH);
567-
}
504+
res = fread(&((char *) buf)[used], 1, len, th->nFH);
505+
if (res != len && !feof(th->nFH))
506+
READ_ERROR_EXIT(th->nFH);
568507
}
569508
}
570509

@@ -596,10 +535,7 @@ tarWrite(const void *buf, size_t len, TAR_MEMBER *th)
596535
{
597536
size_t res;
598537

599-
if (th->zFH != NULL)
600-
res = GZWRITE(buf, 1, len, th->zFH);
601-
else
602-
res = fwrite(buf, 1, len, th->nFH);
538+
res = fwrite(buf, 1, len, th->nFH);
603539

604540
th->pos += res;
605541
return res;
@@ -949,17 +885,14 @@ _StartBlob(ArchiveHandle *AH, TocEntry *te, Oid oid)
949885
lclContext *ctx = (lclContext *) AH->formatData;
950886
lclTocEntry *tctx = (lclTocEntry *) te->formatData;
951887
char fname[255];
952-
char *sfx;
953888

954889
if (oid == 0)
955890
fatal("invalid OID for large object (%u)", oid);
956891

957892
if (AH->compression != 0)
958-
sfx = ".gz";
959-
else
960-
sfx = "";
893+
fatal("compression is not supported by tar archive format");
961894

962-
sprintf(fname, "blob_%u.dat%s", oid, sfx);
895+
sprintf(fname, "blob_%u.dat", oid);
963896

964897
tarPrintf(ctx->blobToc, "%u %s\n", oid, fname);
965898

0 commit comments

Comments
 (0)