@@ -1792,15 +1792,16 @@ get_checksum_map(const char *fullpath, uint32 checksum_version,
17921792char read_buffer [BLCKSZ ];
17931793char 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 */
18011796in = fopen (fullpath ,PG_BINARY_R );
18021797if (!in )
18031798elog (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+
18041805setvbuf (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,
18601861char in_buf [STDIO_BUFSIZE ];
18611862datapagemap_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-
18681864Assert (shift_lsn > 0 );
18691865
18701866/* open file */
18711867in = fopen (fullpath ,PG_BINARY_R );
18721868if (!in )
18731869elog (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+
18741876setvbuf (in ,in_buf ,_IOFBF ,STDIO_BUFSIZE );
18751877
18761878lsn_map = pgut_malloc (sizeof (datapagemap_t ));