@@ -1263,29 +1263,16 @@ get_wal_file(const char *from_path, const char *to_path)
12631263gzFile gz_in = NULL ;
12641264#endif
12651265
1266- /* open file for read */
1267- in = fopen (from_path ,PG_BINARY_R );
1268- if (in == NULL )
1266+ /* First check source file for existance */
1267+ if (fio_access (from_path ,F_OK ,FIO_BACKUP_HOST )!= 0 )
12691268{
12701269#ifdef HAVE_LIBZ
12711270/*
12721271 * Maybe we need to decompress the file. Check it with .gz
12731272 * extension.
12741273 */
12751274snprintf (gz_from_path ,sizeof (gz_from_path ),"%s.gz" ,from_path );
1276- gz_in = gzopen (gz_from_path ,PG_BINARY_R );
1277- if (gz_in == NULL )
1278- {
1279- if (errno == ENOENT )
1280- {
1281- /* There is no compressed file too, raise an error below */
1282- }
1283- /* Cannot open compressed file for some reason */
1284- else
1285- elog (ERROR ,"Cannot open compressed WAL file \"%s\": %s" ,
1286- gz_from_path ,strerror (errno ));
1287- }
1288- else
1275+ if (fio_access (gz_from_path ,F_OK ,FIO_BACKUP_HOST )== 0 )
12891276{
12901277/* Found compressed file */
12911278is_decompress = true;
@@ -1294,9 +1281,28 @@ get_wal_file(const char *from_path, const char *to_path)
12941281#endif
12951282/* Didn't find compressed file */
12961283if (!is_decompress )
1284+ elog (ERROR ,"Source WAL file \"%s\" doesn't exist" ,
1285+ from_path );
1286+ }
1287+
1288+ /* open file for read */
1289+ if (!is_decompress )
1290+ {
1291+ in = fio_fopen (from_path ,PG_BINARY_R ,FIO_BACKUP_HOST );
1292+ if (in == NULL )
12971293elog (ERROR ,"Cannot open source WAL file \"%s\": %s" ,
1298- from_path ,strerror (errno ));
1294+ from_path ,strerror (errno ));
1295+ }
1296+ #ifdef HAVE_LIBZ
1297+ else
1298+ {
1299+ gz_in = fio_gzopen (gz_from_path ,PG_BINARY_R ,Z_DEFAULT_COMPRESSION ,
1300+ FIO_BACKUP_HOST );
1301+ if (gz_in == NULL )
1302+ elog (ERROR ,"Cannot open compressed WAL file \"%s\": %s" ,
1303+ gz_from_path ,strerror (errno ));
12991304}
1305+ #endif
13001306
13011307/* open backup file for write */
13021308snprintf (to_path_temp ,sizeof (to_path_temp ),"%s.partial" ,to_path );
@@ -1314,8 +1320,8 @@ get_wal_file(const char *from_path, const char *to_path)
13141320#ifdef HAVE_LIBZ
13151321if (is_decompress )
13161322{
1317- read_len = gzread (gz_in ,buf ,sizeof (buf ));
1318- if (read_len != sizeof (buf )&& !gzeof (gz_in ))
1323+ read_len = fio_gzread (gz_in ,buf ,sizeof (buf ));
1324+ if (read_len != sizeof (buf )&& !fio_gzeof (gz_in ))
13191325{
13201326errno_temp = errno ;
13211327fio_unlink (to_path_temp ,FIO_DB_HOST );
@@ -1326,7 +1332,7 @@ get_wal_file(const char *from_path, const char *to_path)
13261332else
13271333#endif
13281334{
1329- read_len = fread ( buf , 1 ,sizeof (buf ), in );
1335+ read_len = fio_fread ( in , buf ,sizeof (buf ));
13301336if (ferror (in ))
13311337{
13321338errno_temp = errno ;
@@ -1351,13 +1357,13 @@ get_wal_file(const char *from_path, const char *to_path)
13511357#ifdef HAVE_LIBZ
13521358if (is_decompress )
13531359{
1354- if (gzeof (gz_in )|| read_len == 0 )
1360+ if (fio_gzeof (gz_in )|| read_len == 0 )
13551361break ;
13561362}
13571363else
13581364#endif
13591365{
1360- if (feof (in )|| read_len == 0 )
1366+ if (/* feof(in) || */ read_len == 0 )
13611367break ;
13621368}
13631369}
@@ -1373,7 +1379,7 @@ get_wal_file(const char *from_path, const char *to_path)
13731379#ifdef HAVE_LIBZ
13741380if (is_decompress )
13751381{
1376- if (gzclose (gz_in )!= 0 )
1382+ if (fio_gzclose (gz_in )!= 0 )
13771383{
13781384errno_temp = errno ;
13791385fio_unlink (to_path_temp ,FIO_DB_HOST );
@@ -1384,7 +1390,7 @@ get_wal_file(const char *from_path, const char *to_path)
13841390else
13851391#endif
13861392{
1387- if (fclose (in ))
1393+ if (fio_fclose (in ))
13881394{
13891395errno_temp = errno ;
13901396fio_unlink (to_path_temp ,FIO_DB_HOST );