@@ -70,14 +70,12 @@ typedef struct
70
70
{
71
71
CompressorState * cs ;
72
72
int hasSeek ;
73
- pgoff_t filePos ;
74
- pgoff_t dataStart ;
75
73
} lclContext ;
76
74
77
75
typedef struct
78
76
{
79
77
int dataState ;
80
- pgoff_t dataPos ;
78
+ pgoff_t dataPos ; /* valid only if dataState=K_OFFSET_POS_SET */
81
79
} lclTocEntry ;
82
80
83
81
@@ -144,8 +142,6 @@ InitArchiveFmt_Custom(ArchiveHandle *AH)
144
142
AH -> lo_buf_size = LOBBUFSIZE ;
145
143
AH -> lo_buf = (void * ) pg_malloc (LOBBUFSIZE );
146
144
147
- ctx -> filePos = 0 ;
148
-
149
145
/*
150
146
* Now open the file
151
147
*/
@@ -185,7 +181,6 @@ InitArchiveFmt_Custom(ArchiveHandle *AH)
185
181
186
182
ReadHead (AH );
187
183
ReadToc (AH );
188
- ctx -> dataStart = _getFilePos (AH , ctx );
189
184
}
190
185
191
186
}
@@ -290,7 +285,8 @@ _StartData(ArchiveHandle *AH, TocEntry *te)
290
285
lclTocEntry * tctx = (lclTocEntry * ) te -> formatData ;
291
286
292
287
tctx -> dataPos = _getFilePos (AH , ctx );
293
- tctx -> dataState = K_OFFSET_POS_SET ;
288
+ if (tctx -> dataPos >= 0 )
289
+ tctx -> dataState = K_OFFSET_POS_SET ;
294
290
295
291
_WriteByte (AH , BLK_DATA ); /* Block type */
296
292
WriteInt (AH , te -> dumpId ); /* For sanity check */
@@ -350,7 +346,8 @@ _StartBlobs(ArchiveHandle *AH, TocEntry *te)
350
346
lclTocEntry * tctx = (lclTocEntry * ) te -> formatData ;
351
347
352
348
tctx -> dataPos = _getFilePos (AH , ctx );
353
- tctx -> dataState = K_OFFSET_POS_SET ;
349
+ if (tctx -> dataPos >= 0 )
350
+ tctx -> dataState = K_OFFSET_POS_SET ;
354
351
355
352
_WriteByte (AH , BLK_BLOBS ); /* Block type */
356
353
WriteInt (AH , te -> dumpId ); /* For sanity check */
@@ -551,7 +548,6 @@ _skipBlobs(ArchiveHandle *AH)
551
548
static void
552
549
_skipData (ArchiveHandle * AH )
553
550
{
554
- lclContext * ctx = (lclContext * ) AH -> formatData ;
555
551
size_t blkLen ;
556
552
char * buf = NULL ;
557
553
int buflen = 0 ;
@@ -575,8 +571,6 @@ _skipData(ArchiveHandle *AH)
575
571
fatal ("could not read from input file: %m" );
576
572
}
577
573
578
- ctx -> filePos += blkLen ;
579
-
580
574
blkLen = ReadInt (AH );
581
575
}
582
576
@@ -594,12 +588,10 @@ _skipData(ArchiveHandle *AH)
594
588
static int
595
589
_WriteByte (ArchiveHandle * AH , const int i )
596
590
{
597
- lclContext * ctx = (lclContext * ) AH -> formatData ;
598
591
int res ;
599
592
600
593
if ((res = fputc (i , AH -> FH )) == EOF )
601
594
WRITE_ERROR_EXIT ;
602
- ctx -> filePos += 1 ;
603
595
604
596
return 1 ;
605
597
}
@@ -615,13 +607,11 @@ _WriteByte(ArchiveHandle *AH, const int i)
615
607
static int
616
608
_ReadByte (ArchiveHandle * AH )
617
609
{
618
- lclContext * ctx = (lclContext * ) AH -> formatData ;
619
610
int res ;
620
611
621
612
res = getc (AH -> FH );
622
613
if (res == EOF )
623
614
READ_ERROR_EXIT (AH -> FH );
624
- ctx -> filePos += 1 ;
625
615
return res ;
626
616
}
627
617
@@ -635,11 +625,8 @@ _ReadByte(ArchiveHandle *AH)
635
625
static void
636
626
_WriteBuf (ArchiveHandle * AH , const void * buf , size_t len )
637
627
{
638
- lclContext * ctx = (lclContext * ) AH -> formatData ;
639
-
640
628
if (fwrite (buf , 1 , len , AH -> FH ) != len )
641
629
WRITE_ERROR_EXIT ;
642
- ctx -> filePos += len ;
643
630
}
644
631
645
632
/*
@@ -652,11 +639,8 @@ _WriteBuf(ArchiveHandle *AH, const void *buf, size_t len)
652
639
static void
653
640
_ReadBuf (ArchiveHandle * AH , void * buf , size_t len )
654
641
{
655
- lclContext * ctx = (lclContext * ) AH -> formatData ;
656
-
657
642
if (fread (buf , 1 , len , AH -> FH ) != len )
658
643
READ_ERROR_EXIT (AH -> FH );
659
- ctx -> filePos += len ;
660
644
}
661
645
662
646
/*
@@ -688,7 +672,6 @@ _CloseArchive(ArchiveHandle *AH)
688
672
if (tpos < 0 && ctx -> hasSeek )
689
673
fatal ("could not determine seek position in archive file: %m" );
690
674
WriteToc (AH );
691
- ctx -> dataStart = _getFilePos (AH , ctx );
692
675
WriteDataChunks (AH , NULL );
693
676
694
677
/*
@@ -862,30 +845,24 @@ _WorkerJobRestoreCustom(ArchiveHandle *AH, TocEntry *te)
862
845
863
846
/*
864
847
* Get the current position in the archive file.
848
+ *
849
+ * With a non-seekable archive file, we may not be able to obtain the
850
+ * file position. If so, just return -1. It's not too important in
851
+ * that case because we won't be able to rewrite the TOC to fill in
852
+ * data block offsets anyway.
865
853
*/
866
854
static pgoff_t
867
855
_getFilePos (ArchiveHandle * AH , lclContext * ctx )
868
856
{
869
857
pgoff_t pos ;
870
858
871
- if (ctx -> hasSeek )
859
+ pos = ftello (AH -> FH );
860
+ if (pos < 0 )
872
861
{
873
- /*
874
- * Prior to 1.7 (pg7.3) we relied on the internally maintained
875
- * pointer. Now we rely on ftello() always, unless the file has been
876
- * found to not support it. For debugging purposes, print a warning
877
- * if the internal pointer disagrees, so that we're more likely to
878
- * notice if something's broken about the internal position tracking.
879
- */
880
- pos = ftello (AH -> FH );
881
- if (pos < 0 )
862
+ /* Not expected if we found we can seek. */
863
+ if (ctx -> hasSeek )
882
864
fatal ("could not determine seek position in archive file: %m" );
883
-
884
- if (pos != ctx -> filePos )
885
- pg_log_warning ("ftell mismatch with expected position -- ftell used" );
886
865
}
887
- else
888
- pos = ctx -> filePos ;
889
866
return pos ;
890
867
}
891
868
@@ -897,7 +874,6 @@ _getFilePos(ArchiveHandle *AH, lclContext *ctx)
897
874
static void
898
875
_readBlockHeader (ArchiveHandle * AH , int * type , int * id )
899
876
{
900
- lclContext * ctx = (lclContext * ) AH -> formatData ;
901
877
int byt ;
902
878
903
879
/*
@@ -918,7 +894,6 @@ _readBlockHeader(ArchiveHandle *AH, int *type, int *id)
918
894
* id = 0 ; /* don't return an uninitialized value */
919
895
return ;
920
896
}
921
- ctx -> filePos += 1 ;
922
897
}
923
898
924
899
* id = ReadInt (AH );
0 commit comments