@@ -71,14 +71,12 @@ typedef struct
7171{
7272CompressorState * cs ;
7373int hasSeek ;
74- pgoff_t filePos ;
75- pgoff_t dataStart ;
7674}lclContext ;
7775
7876typedef struct
7977{
8078int dataState ;
81- pgoff_t dataPos ;
79+ pgoff_t dataPos ;/* valid only if dataState=K_OFFSET_POS_SET */
8280}lclTocEntry ;
8381
8482
@@ -145,8 +143,6 @@ InitArchiveFmt_Custom(ArchiveHandle *AH)
145143AH -> lo_buf_size = LOBBUFSIZE ;
146144AH -> lo_buf = (void * )pg_malloc (LOBBUFSIZE );
147145
148- ctx -> filePos = 0 ;
149-
150146/*
151147 * Now open the file
152148 */
@@ -186,7 +182,6 @@ InitArchiveFmt_Custom(ArchiveHandle *AH)
186182
187183ReadHead (AH );
188184ReadToc (AH );
189- ctx -> dataStart = _getFilePos (AH ,ctx );
190185}
191186
192187}
@@ -292,7 +287,8 @@ _StartData(ArchiveHandle *AH, TocEntry *te)
292287lclTocEntry * tctx = (lclTocEntry * )te -> formatData ;
293288
294289tctx -> dataPos = _getFilePos (AH ,ctx );
295- tctx -> dataState = K_OFFSET_POS_SET ;
290+ if (tctx -> dataPos >=0 )
291+ tctx -> dataState = K_OFFSET_POS_SET ;
296292
297293_WriteByte (AH ,BLK_DATA );/* Block type */
298294WriteInt (AH ,te -> dumpId );/* For sanity check */
@@ -355,7 +351,8 @@ _StartBlobs(ArchiveHandle *AH, TocEntry *te)
355351lclTocEntry * tctx = (lclTocEntry * )te -> formatData ;
356352
357353tctx -> dataPos = _getFilePos (AH ,ctx );
358- tctx -> dataState = K_OFFSET_POS_SET ;
354+ if (tctx -> dataPos >=0 )
355+ tctx -> dataState = K_OFFSET_POS_SET ;
359356
360357_WriteByte (AH ,BLK_BLOBS );/* Block type */
361358WriteInt (AH ,te -> dumpId );/* For sanity check */
@@ -556,7 +553,6 @@ _skipBlobs(ArchiveHandle *AH)
556553static void
557554_skipData (ArchiveHandle * AH )
558555{
559- lclContext * ctx = (lclContext * )AH -> formatData ;
560556size_t blkLen ;
561557char * buf = NULL ;
562558int buflen = 0 ;
@@ -580,8 +576,6 @@ _skipData(ArchiveHandle *AH)
580576fatal ("could not read from input file: %m" );
581577}
582578
583- ctx -> filePos += blkLen ;
584-
585579blkLen = ReadInt (AH );
586580}
587581
@@ -599,12 +593,10 @@ _skipData(ArchiveHandle *AH)
599593static int
600594_WriteByte (ArchiveHandle * AH ,const int i )
601595{
602- lclContext * ctx = (lclContext * )AH -> formatData ;
603596int res ;
604597
605598if ((res = fputc (i ,AH -> FH ))== EOF )
606599WRITE_ERROR_EXIT ;
607- ctx -> filePos += 1 ;
608600
609601return 1 ;
610602}
@@ -620,13 +612,11 @@ _WriteByte(ArchiveHandle *AH, const int i)
620612static int
621613_ReadByte (ArchiveHandle * AH )
622614{
623- lclContext * ctx = (lclContext * )AH -> formatData ;
624615int res ;
625616
626617res = getc (AH -> FH );
627618if (res == EOF )
628619READ_ERROR_EXIT (AH -> FH );
629- ctx -> filePos += 1 ;
630620return res ;
631621}
632622
@@ -640,13 +630,8 @@ _ReadByte(ArchiveHandle *AH)
640630static void
641631_WriteBuf (ArchiveHandle * AH ,const void * buf ,size_t len )
642632{
643- lclContext * ctx = (lclContext * )AH -> formatData ;
644-
645633if (fwrite (buf ,1 ,len ,AH -> FH )!= len )
646634WRITE_ERROR_EXIT ;
647- ctx -> filePos += len ;
648-
649- return ;
650635}
651636
652637/*
@@ -659,13 +644,8 @@ _WriteBuf(ArchiveHandle *AH, const void *buf, size_t len)
659644static void
660645_ReadBuf (ArchiveHandle * AH ,void * buf ,size_t len )
661646{
662- lclContext * ctx = (lclContext * )AH -> formatData ;
663-
664647if (fread (buf ,1 ,len ,AH -> FH )!= len )
665648READ_ERROR_EXIT (AH -> FH );
666- ctx -> filePos += len ;
667-
668- return ;
669649}
670650
671651/*
@@ -697,7 +677,6 @@ _CloseArchive(ArchiveHandle *AH)
697677if (tpos < 0 && ctx -> hasSeek )
698678fatal ("could not determine seek position in archive file: %m" );
699679WriteToc (AH );
700- ctx -> dataStart = _getFilePos (AH ,ctx );
701680WriteDataChunks (AH ,NULL );
702681
703682/*
@@ -871,30 +850,24 @@ _WorkerJobRestoreCustom(ArchiveHandle *AH, TocEntry *te)
871850
872851/*
873852 * Get the current position in the archive file.
853+ *
854+ * With a non-seekable archive file, we may not be able to obtain the
855+ * file position. If so, just return -1. It's not too important in
856+ * that case because we won't be able to rewrite the TOC to fill in
857+ * data block offsets anyway.
874858 */
875859static pgoff_t
876860_getFilePos (ArchiveHandle * AH ,lclContext * ctx )
877861{
878862pgoff_t pos ;
879863
880- if (ctx -> hasSeek )
864+ pos = ftello (AH -> FH );
865+ if (pos < 0 )
881866{
882- /*
883- * Prior to 1.7 (pg7.3) we relied on the internally maintained
884- * pointer. Now we rely on ftello() always, unless the file has been
885- * found to not support it. For debugging purposes, print a warning
886- * if the internal pointer disagrees, so that we're more likely to
887- * notice if something's broken about the internal position tracking.
888- */
889- pos = ftello (AH -> FH );
890- if (pos < 0 )
867+ /* Not expected if we found we can seek. */
868+ if (ctx -> hasSeek )
891869fatal ("could not determine seek position in archive file: %m" );
892-
893- if (pos != ctx -> filePos )
894- pg_log_warning ("ftell mismatch with expected position -- ftell used" );
895870}
896- else
897- pos = ctx -> filePos ;
898871return pos ;
899872}
900873
@@ -906,7 +879,6 @@ _getFilePos(ArchiveHandle *AH, lclContext *ctx)
906879static void
907880_readBlockHeader (ArchiveHandle * AH ,int * type ,int * id )
908881{
909- lclContext * ctx = (lclContext * )AH -> formatData ;
910882int byt ;
911883
912884/*
@@ -927,7 +899,6 @@ _readBlockHeader(ArchiveHandle *AH, int *type, int *id)
927899* id = 0 ;/* don't return an uninitialized value */
928900return ;
929901}
930- ctx -> filePos += 1 ;
931902}
932903
933904* id = ReadInt (AH );