@@ -912,7 +912,8 @@ restore_data_file(const char *to_path, pgFile *file, bool allow_truncate,
912
912
* it is either small control file or already compressed cfs file.
913
913
*/
914
914
bool
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 )
916
917
{
917
918
char to_path [MAXPGPATH ];
918
919
FILE * in ;
@@ -930,7 +931,7 @@ copy_file(const char *from_root, const char *to_root, pgFile *file, fio_location
930
931
file -> write_size = 0 ;
931
932
932
933
/* 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 );
934
935
if (in == NULL )
935
936
{
936
937
FIN_FILE_CRC32 (true, crc );
@@ -950,19 +951,19 @@ copy_file(const char *from_root, const char *to_root, pgFile *file, fio_location
950
951
951
952
/* open backup file for write */
952
953
join_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 );
954
955
if (out == NULL )
955
956
{
956
957
int errno_tmp = errno ;
957
- fclose (in );
958
+ fio_fclose (in );
958
959
elog (ERROR , "cannot open destination file \"%s\": %s" ,
959
960
to_path , strerror (errno_tmp ));
960
961
}
961
962
962
963
/* stat source file to change mode of destination file */
963
- if (fstat ( fileno ( in ) , & st ) == -1 )
964
+ if (fio_ffstat ( in , & st ) == -1 )
964
965
{
965
- fclose (in );
966
+ fio_fclose (in );
966
967
fio_fclose (out );
967
968
elog (ERROR , "cannot stat \"%s\": %s" , file -> path ,
968
969
strerror (errno ));
@@ -973,14 +974,14 @@ copy_file(const char *from_root, const char *to_root, pgFile *file, fio_location
973
974
{
974
975
read_len = 0 ;
975
976
976
- if ((read_len = fread ( buf , 1 , sizeof (buf ), in )) != sizeof (buf ))
977
+ if ((read_len = fio_fread ( in , buf , sizeof (buf ))) != sizeof (buf ))
977
978
break ;
978
979
979
980
if (fio_fwrite (out , buf , read_len ) != read_len )
980
981
{
981
982
errno_tmp = errno ;
982
983
/* oops */
983
- fclose (in );
984
+ fio_fclose (in );
984
985
fio_fclose (out );
985
986
elog (ERROR , "cannot write to \"%s\": %s" , to_path ,
986
987
strerror (errno_tmp ));
@@ -992,9 +993,9 @@ copy_file(const char *from_root, const char *to_root, pgFile *file, fio_location
992
993
}
993
994
994
995
errno_tmp = errno ;
995
- if (! feof ( in ) )
996
+ if (read_len < 0 )
996
997
{
997
- fclose (in );
998
+ fio_fclose (in );
998
999
fio_fclose (out );
999
1000
elog (ERROR , "cannot read backup mode file \"%s\": %s" ,
1000
1001
file -> path , strerror (errno_tmp ));
@@ -1007,7 +1008,7 @@ copy_file(const char *from_root, const char *to_root, pgFile *file, fio_location
1007
1008
{
1008
1009
errno_tmp = errno ;
1009
1010
/* oops */
1010
- fclose (in );
1011
+ fio_fclose (in );
1011
1012
fio_fclose (out );
1012
1013
elog (ERROR , "cannot write to \"%s\": %s" , to_path ,
1013
1014
strerror (errno_tmp ));
@@ -1024,10 +1025,10 @@ copy_file(const char *from_root, const char *to_root, pgFile *file, fio_location
1024
1025
file -> crc = crc ;
1025
1026
1026
1027
/* 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 )
1028
1029
{
1029
1030
errno_tmp = errno ;
1030
- fclose (in );
1031
+ fio_fclose (in );
1031
1032
fio_fclose (out );
1032
1033
elog (ERROR , "cannot change mode of \"%s\": %s" , to_path ,
1033
1034
strerror (errno_tmp ));
@@ -1036,7 +1037,7 @@ copy_file(const char *from_root, const char *to_root, pgFile *file, fio_location
1036
1037
if (fio_fflush (out ) != 0 ||
1037
1038
fio_fclose (out ))
1038
1039
elog (ERROR , "cannot write \"%s\": %s" , to_path , strerror (errno ));
1039
- fclose (in );
1040
+ fio_fclose (in );
1040
1041
1041
1042
return true;
1042
1043
}
0 commit comments