@@ -1792,15 +1792,16 @@ get_checksum_map(const char *fullpath, uint32 checksum_version,
17921792 char read_buffer [BLCKSZ ];
17931793 char in_buf [STDIO_BUFSIZE ];
17941794
1795- /* truncate up to blocks */
1796- if (truncate (fullpath , n_blocks * BLCKSZ ) != 0 )
1797- elog (ERROR , "Cannot truncate file to blknum %u \"%s\": %s" ,
1798- n_blocks , fullpath , strerror (errno ));
1799-
18001795 /* open file */
18011796 in = fopen (fullpath , PG_BINARY_R );
18021797 if (!in )
18031798 elog (ERROR , "Cannot open source file \"%s\": %s" , fullpath , strerror (errno ));
1799+
1800+ /* truncate up to blocks */
1801+ if (ftruncate (fileno (in ), n_blocks * BLCKSZ ) != 0 )
1802+ elog (ERROR , "Cannot truncate file to blknum %u \"%s\": %s" ,
1803+ n_blocks , fullpath , strerror (errno ));
1804+
18041805 setvbuf (in , in_buf , _IOFBF , STDIO_BUFSIZE );
18051806
18061807 /* initialize array of checksums */
@@ -1860,17 +1861,18 @@ get_lsn_map(const char *fullpath, uint32 checksum_version,
18601861 char in_buf [STDIO_BUFSIZE ];
18611862 datapagemap_t * lsn_map = NULL ;
18621863
1863- /* truncate up to blocks */
1864- if (truncate (fullpath , n_blocks * BLCKSZ ) != 0 )
1865- elog (ERROR , "Cannot truncate file to blknum %u \"%s\": %s" ,
1866- n_blocks , fullpath , strerror (errno ));
1867-
18681864 Assert (shift_lsn > 0 );
18691865
18701866 /* open file */
18711867 in = fopen (fullpath , PG_BINARY_R );
18721868 if (!in )
18731869 elog (ERROR , "Cannot open source file \"%s\": %s" , fullpath , strerror (errno ));
1870+
1871+ /* truncate up to blocks */
1872+ if (ftruncate (fileno (in ), n_blocks * BLCKSZ ) != 0 )
1873+ elog (ERROR , "Cannot truncate file to blknum %u \"%s\": %s" ,
1874+ n_blocks , fullpath , strerror (errno ));
1875+
18741876 setvbuf (in , in_buf , _IOFBF , STDIO_BUFSIZE );
18751877
18761878 lsn_map = pgut_malloc (sizeof (datapagemap_t ));
0 commit comments