@@ -44,8 +44,8 @@ typedef struct
44
44
45
45
46
46
static int64 sendDir (char * path , int basepathlen , bool sizeonly );
47
- static void sendFile (char * readfilename , char * tarfilename ,
48
- struct stat * statbuf );
47
+ static bool sendFile (char * readfilename , char * tarfilename ,
48
+ struct stat * statbuf , bool missing_ok );
49
49
static void sendFileWithContent (const char * filename , const char * content );
50
50
static void _tarWriteHeader (const char * filename , const char * linktarget ,
51
51
struct stat * statbuf );
@@ -199,7 +199,7 @@ perform_base_backup(basebackup_options *opt, DIR *tblspcdir)
199
199
XLOG_CONTROL_FILE )));
200
200
}
201
201
202
- sendFile (XLOG_CONTROL_FILE , XLOG_CONTROL_FILE , & statbuf );
202
+ sendFile (XLOG_CONTROL_FILE , XLOG_CONTROL_FILE , & statbuf , false );
203
203
}
204
204
205
205
/*
@@ -712,11 +712,18 @@ sendDir(char *path, int basepathlen, bool sizeonly)
712
712
}
713
713
else if (S_ISREG (statbuf .st_mode ))
714
714
{
715
- /* Add size, rounded up to 512byte block */
716
- size += (( statbuf . st_size + 511 ) & ~ 511 );
715
+ bool sent = false;
716
+
717
717
if (!sizeonly )
718
- sendFile (pathbuf , pathbuf + basepathlen + 1 , & statbuf );
719
- size += 512 ; /* Size of the header of the file */
718
+ sent = sendFile (pathbuf , pathbuf + basepathlen + 1 , & statbuf ,
719
+ true);
720
+
721
+ if (sent || sizeonly )
722
+ {
723
+ /* Add size, rounded up to 512byte block */
724
+ size += ((statbuf .st_size + 511 ) & ~511 );
725
+ size += 512 ; /* Size of the header of the file */
726
+ }
720
727
}
721
728
else
722
729
ereport (WARNING ,
@@ -776,9 +783,17 @@ _tarChecksum(char *header)
776
783
return sum ;
777
784
}
778
785
779
- /* Given the member, write the TAR header & send the file */
780
- static void
781
- sendFile (char * readfilename , char * tarfilename , struct stat * statbuf )
786
+ /*
787
+ * Given the member, write the TAR header & send the file.
788
+ *
789
+ * If 'missing_ok' is true, will not throw an error if the file is not found.
790
+ *
791
+ * Returns true if the file was successfully sent, false if 'missing_ok',
792
+ * and the file did not exist.
793
+ */
794
+ static bool
795
+ sendFile (char * readfilename , char * tarfilename , struct stat * statbuf ,
796
+ bool missing_ok )
782
797
{
783
798
FILE * fp ;
784
799
char buf [TAR_SEND_SIZE ];
@@ -788,9 +803,13 @@ sendFile(char *readfilename, char *tarfilename, struct stat * statbuf)
788
803
789
804
fp = AllocateFile (readfilename , "rb" );
790
805
if (fp == NULL )
806
+ {
807
+ if (errno == ENOENT && missing_ok )
808
+ return false;
791
809
ereport (ERROR ,
792
810
(errcode_for_file_access (),
793
811
errmsg ("could not open file \"%s\": %m" , readfilename )));
812
+ }
794
813
795
814
/*
796
815
* Some compilers will throw a warning knowing this test can never be true
@@ -844,6 +863,8 @@ sendFile(char *readfilename, char *tarfilename, struct stat * statbuf)
844
863
}
845
864
846
865
FreeFile (fp );
866
+
867
+ return true;
847
868
}
848
869
849
870
0 commit comments