aboutsummaryrefslogtreecommitdiff
path: root/src/bin/pg_dump/pg_backup_tar.c
diff options
context:
space:
mode:
authorPhilip Warner <pjw@rhyme.com.au>2001-02-13 01:31:54 +0000
committerPhilip Warner <pjw@rhyme.com.au>2001-02-13 01:31:54 +0000
commit4a19bd87411dba4315cdacdb98c62d8758142d47 (patch)
treef58009f30bbc4ae829cea28c66917d87df7c5957 /src/bin/pg_dump/pg_backup_tar.c
parentf7a839bc2ba3f15d48006fe931499d4d9cfb314f (diff)
downloadpostgresql-4a19bd87411dba4315cdacdb98c62d8758142d47.tar.gz
postgresql-4a19bd87411dba4315cdacdb98c62d8758142d47.zip
- Fix help output: replace 'f' with 't' and change desc
- Add extra arg to formatStringLiteral to specify how to handle LF & TAB. I opted for encoding them except in procedure bodies & comments - Fixed bug in tar file input when restoring blobs
Diffstat (limited to 'src/bin/pg_dump/pg_backup_tar.c')
-rw-r--r--src/bin/pg_dump/pg_backup_tar.c51
1 files changed, 39 insertions, 12 deletions
diff --git a/src/bin/pg_dump/pg_backup_tar.c b/src/bin/pg_dump/pg_backup_tar.c
index 40d90ac8652..87dada274d5 100644
--- a/src/bin/pg_dump/pg_backup_tar.c
+++ b/src/bin/pg_dump/pg_backup_tar.c
@@ -1061,26 +1061,53 @@ static int _tarGetHeader(ArchiveHandle *AH, TAR_MEMBER* th)
int sum, chk;
int len;
int hPos;
+ int i;
+ bool gotBlock = false;
- /*
- * if ( ftell(ctx->tarFH) != ctx->tarFHpos)
- * die_horribly(AH, "%s: mismatch in actual vs. predicted file pos - %d vs. %d\n",
- * progname, ftell(ctx->tarFH), ctx->tarFHpos);
- */
+ while (!gotBlock)
+ {
+ /*
+ * if ( ftell(ctx->tarFH) != ctx->tarFHpos)
+ * die_horribly(AH, "%s: mismatch in actual vs. predicted file pos - %d vs. %d\n",
+ * progname, ftell(ctx->tarFH), ctx->tarFHpos);
+ */
- hPos = ctx->tarFHpos;
+ /* Save the pos for reporting purposes */
+ hPos = ctx->tarFHpos;
- len = _tarReadRaw(AH, &h[0], 512, NULL, ctx->tarFH);
- if (len == 0) /* EOF */
- return 0;
+ /* Read a 512 byte block, return EOF, exit if short */
+ len = _tarReadRaw(AH, &h[0], 512, NULL, ctx->tarFH);
+ if (len == 0) /* EOF */
+ return 0;
+
+ if (len != 512)
+ die_horribly(AH, "%s: incomplete tar header found (%d bytes)\n", progname, len);
+
+ /* Calc checksum */
+ chk = _tarChecksum(&h[0]);
- if (len != 512)
- die_horribly(AH, "%s: incomplete tar header found (%d bytes)\n", progname, len);
+ /*
+ * If the checksum failed, see if it is a null block.
+ * If so, then just try with next block...
+ */
+
+ if (chk == sum) {
+ gotBlock = true;
+ } else {
+ for( i = 0 ; i < 512 ; i++)
+ {
+ if (h[0] != 0)
+ {
+ gotBlock = true;
+ break;
+ }
+ }
+ }
+ }
sscanf(&h[0], "%99s", &name[0]);
sscanf(&h[124], "%12o", &len);
sscanf(&h[148], "%8o", &sum);
- chk = _tarChecksum(&h[0]);
ahlog(AH, 3, "TOC Entry %s at %d (len=%d, chk=%d)\n", &name[0], hPos, len, sum);