@@ -722,6 +722,7 @@ restore_data_file(const char *to_path, pgFile *file, bool allow_truncate,
722
722
size_t read_len ;
723
723
DataPage compressed_page ; /* used as read buffer */
724
724
DataPage page ;
725
+ int32 uncompressed_size = 0 ;
725
726
726
727
/* File didn`t changed. Nothig to copy */
727
728
if (file -> write_size == BYTES_INVALID )
@@ -777,17 +778,23 @@ restore_data_file(const char *to_path, pgFile *file, bool allow_truncate,
777
778
778
779
Assert (header .compressed_size <= BLCKSZ );
779
780
781
+ /* read a page from file */
780
782
read_len = fread (compressed_page .data , 1 ,
781
783
MAXALIGN (header .compressed_size ), in );
782
784
if (read_len != MAXALIGN (header .compressed_size ))
783
785
elog (ERROR , "cannot read block %u of \"%s\" read %lu of %d" ,
784
786
blknum , file -> path , read_len , header .compressed_size );
785
787
788
+ /*
789
+ * if page size is smaller than BLCKSZ, decompress the page.
790
+ * BUGFIX for versions < 2.0.23: if page size is equal to BLCKSZ.
791
+ * we have to check, whether it is compressed or not using
792
+ * page_may_be_compressed() function.
793
+ */
786
794
if (header .compressed_size != BLCKSZ
787
795
|| page_may_be_compressed (compressed_page .data , file -> compress_alg ,
788
796
backup_version ))
789
797
{
790
- int32 uncompressed_size = 0 ;
791
798
const char * errormsg = NULL ;
792
799
793
800
uncompressed_size = do_decompress (page .data , BLCKSZ ,
@@ -820,15 +827,19 @@ restore_data_file(const char *to_path, pgFile *file, bool allow_truncate,
820
827
blknum , file -> path , strerror (errno ));
821
828
}
822
829
823
- if (header .compressed_size < BLCKSZ )
830
+ /* if we uncompressed the page - write page.data,
831
+ * if page wasn't compressed -
832
+ * write what we've read - compressed_page.data
833
+ */
834
+ if (uncompressed_size == BLCKSZ )
824
835
{
825
836
if (fwrite (page .data , 1 , BLCKSZ , out ) != BLCKSZ )
826
837
elog (ERROR , "cannot write block %u of \"%s\": %s" ,
827
838
blknum , file -> path , strerror (errno ));
828
839
}
829
840
else
830
841
{
831
- /* if page wasn't compressed, we've read full block */
842
+ /* */
832
843
if (fwrite (compressed_page .data , 1 , BLCKSZ , out ) != BLCKSZ )
833
844
elog (ERROR , "cannot write block %u of \"%s\": %s" ,
834
845
blknum , file -> path , strerror (errno ));
0 commit comments