@@ -912,7 +912,8 @@ restore_data_file(const char *to_path, pgFile *file, bool allow_truncate,
912912 * it is either small control file or already compressed cfs file.
913913 */
914914bool
915- copy_file (const char * from_root ,const char * to_root ,pgFile * file ,fio_location location )
915+ copy_file (const char * from_root ,fio_location from_location ,
916+ const char * to_root ,fio_location to_location ,pgFile * file )
916917{
917918char to_path [MAXPGPATH ];
918919FILE * in ;
@@ -930,7 +931,7 @@ copy_file(const char *from_root, const char *to_root, pgFile *file, fio_location
930931file -> write_size = 0 ;
931932
932933/* open backup mode file for read */
933- in = fopen (file -> path ,PG_BINARY_R );
934+ in = fio_fopen (file -> path ,PG_BINARY_R , from_location );
934935if (in == NULL )
935936{
936937FIN_FILE_CRC32 (true,crc );
@@ -950,19 +951,19 @@ copy_file(const char *from_root, const char *to_root, pgFile *file, fio_location
950951
951952/* open backup file for write */
952953join_path_components (to_path ,to_root ,file -> path + strlen (from_root )+ 1 );
953- out = fio_fopen (to_path ,PG_BINARY_W ,location );
954+ out = fio_fopen (to_path ,PG_BINARY_W ,to_location );
954955if (out == NULL )
955956{
956957int errno_tmp = errno ;
957- fclose (in );
958+ fio_fclose (in );
958959elog (ERROR ,"cannot open destination file \"%s\": %s" ,
959960to_path ,strerror (errno_tmp ));
960961}
961962
962963/* stat source file to change mode of destination file */
963- if (fstat ( fileno ( in ) ,& st )== -1 )
964+ if (fio_ffstat ( in ,& st )== -1 )
964965{
965- fclose (in );
966+ fio_fclose (in );
966967fio_fclose (out );
967968elog (ERROR ,"cannot stat \"%s\": %s" ,file -> path ,
968969strerror (errno ));
@@ -973,14 +974,14 @@ copy_file(const char *from_root, const char *to_root, pgFile *file, fio_location
973974{
974975read_len = 0 ;
975976
976- if ((read_len = fread ( buf , 1 ,sizeof (buf ), in ))!= sizeof (buf ))
977+ if ((read_len = fio_fread ( in , buf ,sizeof (buf )))!= sizeof (buf ))
977978break ;
978979
979980if (fio_fwrite (out ,buf ,read_len )!= read_len )
980981{
981982errno_tmp = errno ;
982983/* oops */
983- fclose (in );
984+ fio_fclose (in );
984985fio_fclose (out );
985986elog (ERROR ,"cannot write to \"%s\": %s" ,to_path ,
986987strerror (errno_tmp ));
@@ -992,9 +993,9 @@ copy_file(const char *from_root, const char *to_root, pgFile *file, fio_location
992993}
993994
994995errno_tmp = errno ;
995- if (! feof ( in ) )
996+ if (read_len < 0 )
996997{
997- fclose (in );
998+ fio_fclose (in );
998999fio_fclose (out );
9991000elog (ERROR ,"cannot read backup mode file \"%s\": %s" ,
10001001file -> path ,strerror (errno_tmp ));
@@ -1007,7 +1008,7 @@ copy_file(const char *from_root, const char *to_root, pgFile *file, fio_location
10071008{
10081009errno_tmp = errno ;
10091010/* oops */
1010- fclose (in );
1011+ fio_fclose (in );
10111012fio_fclose (out );
10121013elog (ERROR ,"cannot write to \"%s\": %s" ,to_path ,
10131014strerror (errno_tmp ));
@@ -1024,10 +1025,10 @@ copy_file(const char *from_root, const char *to_root, pgFile *file, fio_location
10241025file -> crc = crc ;
10251026
10261027/* update file permission */
1027- if (fio_chmod (to_path ,st .st_mode ,location )== -1 )
1028+ if (fio_chmod (to_path ,st .st_mode ,to_location )== -1 )
10281029{
10291030errno_tmp = errno ;
1030- fclose (in );
1031+ fio_fclose (in );
10311032fio_fclose (out );
10321033elog (ERROR ,"cannot change mode of \"%s\": %s" ,to_path ,
10331034strerror (errno_tmp ));
@@ -1036,7 +1037,7 @@ copy_file(const char *from_root, const char *to_root, pgFile *file, fio_location
10361037if (fio_fflush (out )!= 0 ||
10371038fio_fclose (out ))
10381039elog (ERROR ,"cannot write \"%s\": %s" ,to_path ,strerror (errno ));
1039- fclose (in );
1040+ fio_fclose (in );
10401041
10411042return true;
10421043}