@@ -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 );
@@ -194,7 +194,7 @@ perform_base_backup(basebackup_options *opt, DIR *tblspcdir)
194
194
XLOG_CONTROL_FILE )));
195
195
}
196
196
197
- sendFile (XLOG_CONTROL_FILE ,XLOG_CONTROL_FILE ,& statbuf );
197
+ sendFile (XLOG_CONTROL_FILE ,XLOG_CONTROL_FILE ,& statbuf , false );
198
198
}
199
199
200
200
/*
@@ -715,11 +715,18 @@ sendDir(char *path, int basepathlen, bool sizeonly)
715
715
}
716
716
else if (S_ISREG (statbuf .st_mode ))
717
717
{
718
- /* Add size, rounded up to 512byte block */
719
- size += (( statbuf . st_size + 511 ) & ~ 511 );
718
+ bool sent = false;
719
+
720
720
if (!sizeonly )
721
- sendFile (pathbuf ,pathbuf + basepathlen + 1 ,& statbuf );
722
- size += 512 ;/* Size of the header of the file */
721
+ sent = sendFile (pathbuf ,pathbuf + basepathlen + 1 ,& statbuf ,
722
+ true);
723
+
724
+ if (sent || sizeonly )
725
+ {
726
+ /* Add size, rounded up to 512byte block */
727
+ size += ((statbuf .st_size + 511 )& ~511 );
728
+ size += 512 ;/* Size of the header of the file */
729
+ }
723
730
}
724
731
else
725
732
ereport (WARNING ,
@@ -779,9 +786,17 @@ _tarChecksum(char *header)
779
786
return sum ;
780
787
}
781
788
782
- /* Given the member, write the TAR header & send the file */
783
- static void
784
- sendFile (char * readfilename ,char * tarfilename ,struct stat * statbuf )
789
+ /*
790
+ * Given the member, write the TAR header & send the file.
791
+ *
792
+ * If 'missing_ok' is true, will not throw an error if the file is not found.
793
+ *
794
+ * Returns true if the file was successfully sent, false if 'missing_ok',
795
+ * and the file did not exist.
796
+ */
797
+ static bool
798
+ sendFile (char * readfilename ,char * tarfilename ,struct stat * statbuf ,
799
+ bool missing_ok )
785
800
{
786
801
FILE * fp ;
787
802
char buf [TAR_SEND_SIZE ];
@@ -791,9 +806,13 @@ sendFile(char *readfilename, char *tarfilename, struct stat * statbuf)
791
806
792
807
fp = AllocateFile (readfilename ,"rb" );
793
808
if (fp == NULL )
809
+ {
810
+ if (errno == ENOENT && missing_ok )
811
+ return false;
794
812
ereport (ERROR ,
795
813
(errcode_for_file_access (),
796
814
errmsg ("could not open file \"%s\": %m" ,readfilename )));
815
+ }
797
816
798
817
/*
799
818
* Some compilers will throw a warning knowing this test can never be true
@@ -847,6 +866,8 @@ sendFile(char *readfilename, char *tarfilename, struct stat * statbuf)
847
866
}
848
867
849
868
FreeFile (fp );
869
+
870
+ return true;
850
871
}
851
872
852
873