@@ -71,14 +71,12 @@ typedef struct
71
71
{
72
72
CompressorState * cs ;
73
73
int hasSeek ;
74
- pgoff_t filePos ;
75
- pgoff_t dataStart ;
76
74
} lclContext ;
77
75
78
76
typedef struct
79
77
{
80
78
int dataState ;
81
- pgoff_t dataPos ;
79
+ pgoff_t dataPos ; /* valid only if dataState=K_OFFSET_POS_SET */
82
80
} lclTocEntry ;
83
81
84
82
@@ -145,8 +143,6 @@ InitArchiveFmt_Custom(ArchiveHandle *AH)
145
143
AH -> lo_buf_size = LOBBUFSIZE ;
146
144
AH -> lo_buf = (void * ) pg_malloc (LOBBUFSIZE );
147
145
148
- ctx -> filePos = 0 ;
149
-
150
146
/*
151
147
* Now open the file
152
148
*/
@@ -186,7 +182,6 @@ InitArchiveFmt_Custom(ArchiveHandle *AH)
186
182
187
183
ReadHead (AH );
188
184
ReadToc (AH );
189
- ctx -> dataStart = _getFilePos (AH , ctx );
190
185
}
191
186
192
187
}
@@ -292,7 +287,8 @@ _StartData(ArchiveHandle *AH, TocEntry *te)
292
287
lclTocEntry * tctx = (lclTocEntry * ) te -> formatData ;
293
288
294
289
tctx -> dataPos = _getFilePos (AH , ctx );
295
- tctx -> dataState = K_OFFSET_POS_SET ;
290
+ if (tctx -> dataPos >= 0 )
291
+ tctx -> dataState = K_OFFSET_POS_SET ;
296
292
297
293
_WriteByte (AH , BLK_DATA ); /* Block type */
298
294
WriteInt (AH , te -> dumpId ); /* For sanity check */
@@ -355,7 +351,8 @@ _StartBlobs(ArchiveHandle *AH, TocEntry *te)
355
351
lclTocEntry * tctx = (lclTocEntry * ) te -> formatData ;
356
352
357
353
tctx -> dataPos = _getFilePos (AH , ctx );
358
- tctx -> dataState = K_OFFSET_POS_SET ;
354
+ if (tctx -> dataPos >= 0 )
355
+ tctx -> dataState = K_OFFSET_POS_SET ;
359
356
360
357
_WriteByte (AH , BLK_BLOBS ); /* Block type */
361
358
WriteInt (AH , te -> dumpId ); /* For sanity check */
@@ -556,7 +553,6 @@ _skipBlobs(ArchiveHandle *AH)
556
553
static void
557
554
_skipData (ArchiveHandle * AH )
558
555
{
559
- lclContext * ctx = (lclContext * ) AH -> formatData ;
560
556
size_t blkLen ;
561
557
char * buf = NULL ;
562
558
int buflen = 0 ;
@@ -580,8 +576,6 @@ _skipData(ArchiveHandle *AH)
580
576
fatal ("could not read from input file: %m" );
581
577
}
582
578
583
- ctx -> filePos += blkLen ;
584
-
585
579
blkLen = ReadInt (AH );
586
580
}
587
581
@@ -599,12 +593,10 @@ _skipData(ArchiveHandle *AH)
599
593
static int
600
594
_WriteByte (ArchiveHandle * AH , const int i )
601
595
{
602
- lclContext * ctx = (lclContext * ) AH -> formatData ;
603
596
int res ;
604
597
605
598
if ((res = fputc (i , AH -> FH )) == EOF )
606
599
WRITE_ERROR_EXIT ;
607
- ctx -> filePos += 1 ;
608
600
609
601
return 1 ;
610
602
}
@@ -620,13 +612,11 @@ _WriteByte(ArchiveHandle *AH, const int i)
620
612
static int
621
613
_ReadByte (ArchiveHandle * AH )
622
614
{
623
- lclContext * ctx = (lclContext * ) AH -> formatData ;
624
615
int res ;
625
616
626
617
res = getc (AH -> FH );
627
618
if (res == EOF )
628
619
READ_ERROR_EXIT (AH -> FH );
629
- ctx -> filePos += 1 ;
630
620
return res ;
631
621
}
632
622
@@ -640,13 +630,8 @@ _ReadByte(ArchiveHandle *AH)
640
630
static void
641
631
_WriteBuf (ArchiveHandle * AH , const void * buf , size_t len )
642
632
{
643
- lclContext * ctx = (lclContext * ) AH -> formatData ;
644
-
645
633
if (fwrite (buf , 1 , len , AH -> FH ) != len )
646
634
WRITE_ERROR_EXIT ;
647
- ctx -> filePos += len ;
648
-
649
- return ;
650
635
}
651
636
652
637
/*
@@ -659,13 +644,8 @@ _WriteBuf(ArchiveHandle *AH, const void *buf, size_t len)
659
644
static void
660
645
_ReadBuf (ArchiveHandle * AH , void * buf , size_t len )
661
646
{
662
- lclContext * ctx = (lclContext * ) AH -> formatData ;
663
-
664
647
if (fread (buf , 1 , len , AH -> FH ) != len )
665
648
READ_ERROR_EXIT (AH -> FH );
666
- ctx -> filePos += len ;
667
-
668
- return ;
669
649
}
670
650
671
651
/*
@@ -697,7 +677,6 @@ _CloseArchive(ArchiveHandle *AH)
697
677
if (tpos < 0 && ctx -> hasSeek )
698
678
fatal ("could not determine seek position in archive file: %m" );
699
679
WriteToc (AH );
700
- ctx -> dataStart = _getFilePos (AH , ctx );
701
680
WriteDataChunks (AH , NULL );
702
681
703
682
/*
@@ -871,30 +850,24 @@ _WorkerJobRestoreCustom(ArchiveHandle *AH, TocEntry *te)
871
850
872
851
/*
873
852
* 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.
874
858
*/
875
859
static pgoff_t
876
860
_getFilePos (ArchiveHandle * AH , lclContext * ctx )
877
861
{
878
862
pgoff_t pos ;
879
863
880
- if (ctx -> hasSeek )
864
+ pos = ftello (AH -> FH );
865
+ if (pos < 0 )
881
866
{
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 )
891
869
fatal ("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" );
895
870
}
896
- else
897
- pos = ctx -> filePos ;
898
871
return pos ;
899
872
}
900
873
@@ -906,7 +879,6 @@ _getFilePos(ArchiveHandle *AH, lclContext *ctx)
906
879
static void
907
880
_readBlockHeader (ArchiveHandle * AH , int * type , int * id )
908
881
{
909
- lclContext * ctx = (lclContext * ) AH -> formatData ;
910
882
int byt ;
911
883
912
884
/*
@@ -927,7 +899,6 @@ _readBlockHeader(ArchiveHandle *AH, int *type, int *id)
927
899
* id = 0 ; /* don't return an uninitialized value */
928
900
return ;
929
901
}
930
- ctx -> filePos += 1 ;
931
902
}
932
903
933
904
* id = ReadInt (AH );
0 commit comments