@@ -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
}
@@ -291,7 +286,8 @@ _StartData(ArchiveHandle *AH, TocEntry *te)
291
286
lclTocEntry * tctx = (lclTocEntry * ) te -> formatData ;
292
287
293
288
tctx -> dataPos = _getFilePos (AH , ctx );
294
- tctx -> dataState = K_OFFSET_POS_SET ;
289
+ if (tctx -> dataPos >= 0 )
290
+ tctx -> dataState = K_OFFSET_POS_SET ;
295
291
296
292
_WriteByte (AH , BLK_DATA ); /* Block type */
297
293
WriteInt (AH , te -> dumpId ); /* For sanity check */
@@ -352,7 +348,8 @@ _StartBlobs(ArchiveHandle *AH, TocEntry *te)
352
348
lclTocEntry * tctx = (lclTocEntry * ) te -> formatData ;
353
349
354
350
tctx -> dataPos = _getFilePos (AH , ctx );
355
- tctx -> dataState = K_OFFSET_POS_SET ;
351
+ if (tctx -> dataPos >= 0 )
352
+ tctx -> dataState = K_OFFSET_POS_SET ;
356
353
357
354
_WriteByte (AH , BLK_BLOBS ); /* Block type */
358
355
WriteInt (AH , te -> dumpId ); /* For sanity check */
@@ -553,7 +550,6 @@ _skipBlobs(ArchiveHandle *AH)
553
550
static void
554
551
_skipData (ArchiveHandle * AH )
555
552
{
556
- lclContext * ctx = (lclContext * ) AH -> formatData ;
557
553
size_t blkLen ;
558
554
char * buf = NULL ;
559
555
int buflen = 0 ;
@@ -577,8 +573,6 @@ _skipData(ArchiveHandle *AH)
577
573
fatal ("could not read from input file: %m" );
578
574
}
579
575
580
- ctx -> filePos += blkLen ;
581
-
582
576
blkLen = ReadInt (AH );
583
577
}
584
578
@@ -596,12 +590,10 @@ _skipData(ArchiveHandle *AH)
596
590
static int
597
591
_WriteByte (ArchiveHandle * AH , const int i )
598
592
{
599
- lclContext * ctx = (lclContext * ) AH -> formatData ;
600
593
int res ;
601
594
602
595
if ((res = fputc (i , AH -> FH )) == EOF )
603
596
WRITE_ERROR_EXIT ;
604
- ctx -> filePos += 1 ;
605
597
606
598
return 1 ;
607
599
}
@@ -617,13 +609,11 @@ _WriteByte(ArchiveHandle *AH, const int i)
617
609
static int
618
610
_ReadByte (ArchiveHandle * AH )
619
611
{
620
- lclContext * ctx = (lclContext * ) AH -> formatData ;
621
612
int res ;
622
613
623
614
res = getc (AH -> FH );
624
615
if (res == EOF )
625
616
READ_ERROR_EXIT (AH -> FH );
626
- ctx -> filePos += 1 ;
627
617
return res ;
628
618
}
629
619
@@ -637,11 +627,8 @@ _ReadByte(ArchiveHandle *AH)
637
627
static void
638
628
_WriteBuf (ArchiveHandle * AH , const void * buf , size_t len )
639
629
{
640
- lclContext * ctx = (lclContext * ) AH -> formatData ;
641
-
642
630
if (fwrite (buf , 1 , len , AH -> FH ) != len )
643
631
WRITE_ERROR_EXIT ;
644
- ctx -> filePos += len ;
645
632
}
646
633
647
634
/*
@@ -654,11 +641,8 @@ _WriteBuf(ArchiveHandle *AH, const void *buf, size_t len)
654
641
static void
655
642
_ReadBuf (ArchiveHandle * AH , void * buf , size_t len )
656
643
{
657
- lclContext * ctx = (lclContext * ) AH -> formatData ;
658
-
659
644
if (fread (buf , 1 , len , AH -> FH ) != len )
660
645
READ_ERROR_EXIT (AH -> FH );
661
- ctx -> filePos += len ;
662
646
}
663
647
664
648
/*
@@ -690,7 +674,6 @@ _CloseArchive(ArchiveHandle *AH)
690
674
if (tpos < 0 && ctx -> hasSeek )
691
675
fatal ("could not determine seek position in archive file: %m" );
692
676
WriteToc (AH );
693
- ctx -> dataStart = _getFilePos (AH , ctx );
694
677
WriteDataChunks (AH , NULL );
695
678
696
679
/*
@@ -864,30 +847,24 @@ _WorkerJobRestoreCustom(ArchiveHandle *AH, TocEntry *te)
864
847
865
848
/*
866
849
* Get the current position in the archive file.
850
+ *
851
+ * With a non-seekable archive file, we may not be able to obtain the
852
+ * file position. If so, just return -1. It's not too important in
853
+ * that case because we won't be able to rewrite the TOC to fill in
854
+ * data block offsets anyway.
867
855
*/
868
856
static pgoff_t
869
857
_getFilePos (ArchiveHandle * AH , lclContext * ctx )
870
858
{
871
859
pgoff_t pos ;
872
860
873
- if (ctx -> hasSeek )
861
+ pos = ftello (AH -> FH );
862
+ if (pos < 0 )
874
863
{
875
- /*
876
- * Prior to 1.7 (pg7.3) we relied on the internally maintained
877
- * pointer. Now we rely on ftello() always, unless the file has been
878
- * found to not support it. For debugging purposes, print a warning
879
- * if the internal pointer disagrees, so that we're more likely to
880
- * notice if something's broken about the internal position tracking.
881
- */
882
- pos = ftello (AH -> FH );
883
- if (pos < 0 )
864
+ /* Not expected if we found we can seek. */
865
+ if (ctx -> hasSeek )
884
866
fatal ("could not determine seek position in archive file: %m" );
885
-
886
- if (pos != ctx -> filePos )
887
- pg_log_warning ("ftell mismatch with expected position -- ftell used" );
888
867
}
889
- else
890
- pos = ctx -> filePos ;
891
868
return pos ;
892
869
}
893
870
@@ -899,7 +876,6 @@ _getFilePos(ArchiveHandle *AH, lclContext *ctx)
899
876
static void
900
877
_readBlockHeader (ArchiveHandle * AH , int * type , int * id )
901
878
{
902
- lclContext * ctx = (lclContext * ) AH -> formatData ;
903
879
int byt ;
904
880
905
881
/*
@@ -920,7 +896,6 @@ _readBlockHeader(ArchiveHandle *AH, int *type, int *id)
920
896
* id = 0 ; /* don't return an uninitialized value */
921
897
return ;
922
898
}
923
- ctx -> filePos += 1 ;
924
899
}
925
900
926
901
* id = ReadInt (AH );
0 commit comments