@@ -272,7 +272,7 @@ parse_page(const DataPage *page, int server_version,
272
272
* If lsn is not NULL, pages only which are modified after the lsn will be
273
273
* copied.
274
274
*/
275
- void
275
+ bool
276
276
backup_data_file (const char * from_root , const char * to_root ,
277
277
pgFile * file , const XLogRecPtr * lsn , bool compress )
278
278
{
@@ -291,13 +291,22 @@ backup_data_file(const char *from_root, const char *to_root,
291
291
char outbuf [zlibOutSize ];
292
292
#endif
293
293
294
+ INIT_CRC32 (crc );
295
+
296
+ /* reset size summary */
297
+ file -> read_size = 0 ;
298
+ file -> write_size = 0 ;
299
+
294
300
/* open backup mode file for read */
295
301
in = fopen (file -> path , "r" );
296
302
if (in == NULL )
297
303
{
298
- /* meybe vanished, it's not error */
304
+ FIN_CRC32 (crc );
305
+ file -> crc = crc ;
306
+
307
+ /* maybe vanished, it's not error */
299
308
if (errno == ENOENT )
300
- return ;
309
+ return false ;
301
310
302
311
elog (ERROR_SYSTEM , _ ("can't open backup mode file \"%s\": %s" ),
303
312
file -> path , strerror (errno ));
@@ -317,12 +326,6 @@ backup_data_file(const char *from_root, const char *to_root,
317
326
to_path , strerror (errno_tmp ));
318
327
}
319
328
320
- INIT_CRC32 (crc );
321
-
322
- /* reset size summary */
323
- file -> read_size = 0 ;
324
- file -> write_size = 0 ;
325
-
326
329
#ifdef HAVE_LIBZ
327
330
if (compress )
328
331
{
@@ -365,9 +368,8 @@ backup_data_file(const char *from_root, const char *to_root,
365
368
fclose (in );
366
369
fclose (out );
367
370
file -> is_datafile = false;
368
- copy_file (from_root , to_root , file ,
369
- compress ? COMPRESSION : NO_COMPRESSION );
370
- return ;
371
+ return copy_file (from_root , to_root , file ,
372
+ compress ? COMPRESSION : NO_COMPRESSION );
371
373
}
372
374
373
375
file -> read_size += read_len ;
@@ -540,13 +542,18 @@ backup_data_file(const char *from_root, const char *to_root,
540
542
541
543
/* We do not backup if all pages skipped. */
542
544
if (file -> write_size == 0 && file -> read_size > 0 )
545
+ {
543
546
if (remove (to_path ) == -1 )
544
547
elog (ERROR_SYSTEM , _ ("can't remove file \"%s\": %s" ), to_path ,
545
548
strerror (errno ));
549
+ return false;
550
+ }
546
551
547
552
/* remove $BACKUP_PATH/tmp created during check */
548
553
if (check )
549
554
remove (to_path );
555
+
556
+ return true;
550
557
}
551
558
552
559
/*
@@ -746,7 +753,7 @@ restore_data_file(const char *from_root,
746
753
fclose (out );
747
754
}
748
755
749
- void
756
+ bool
750
757
copy_file (const char * from_root , const char * to_root , pgFile * file ,
751
758
CompressionMode mode )
752
759
{
@@ -765,13 +772,22 @@ copy_file(const char *from_root, const char *to_root, pgFile *file,
765
772
char inbuf [zlibInSize ];
766
773
#endif
767
774
775
+ INIT_CRC32 (crc );
776
+
777
+ /* reset size summary */
778
+ file -> read_size = 0 ;
779
+ file -> write_size = 0 ;
780
+
768
781
/* open backup mode file for read */
769
782
in = fopen (file -> path , "r" );
770
783
if (in == NULL )
771
784
{
772
- /* meybe deleted, it's not error */
785
+ FIN_CRC32 (crc );
786
+ file -> crc = crc ;
787
+
788
+ /* maybe deleted, it's not error */
773
789
if (errno == ENOENT )
774
- return ;
790
+ return false ;
775
791
776
792
elog (ERROR_SYSTEM , _ ("can't open source file \"%s\": %s" ), file -> path ,
777
793
strerror (errno ));
@@ -798,12 +814,6 @@ copy_file(const char *from_root, const char *to_root, pgFile *file,
798
814
strerror (errno ));
799
815
}
800
816
801
- INIT_CRC32 (crc );
802
-
803
- /* reset size summary */
804
- file -> read_size = 0 ;
805
- file -> write_size = 0 ;
806
-
807
817
#ifdef HAVE_LIBZ
808
818
z .zalloc = Z_NULL ;
809
819
z .zfree = Z_NULL ;
@@ -962,4 +972,6 @@ copy_file(const char *from_root, const char *to_root, pgFile *file,
962
972
963
973
if (check )
964
974
remove (to_path );
975
+
976
+ return true;
965
977
}
0 commit comments