@@ -43,8 +43,8 @@ typedef struct
43
43
44
44
45
45
static int64 sendDir (char * path ,int basepathlen ,bool sizeonly );
46
- static void sendFile (char * readfilename ,char * tarfilename ,
47
- struct stat * statbuf );
46
+ static bool sendFile (char * readfilename ,char * tarfilename ,
47
+ struct stat * statbuf , bool missing_ok );
48
48
static void sendFileWithContent (const char * filename ,const char * content );
49
49
static void _tarWriteHeader (const char * filename ,const char * linktarget ,
50
50
struct stat * statbuf );
@@ -692,11 +692,18 @@ sendDir(char *path, int basepathlen, bool sizeonly)
692
692
}
693
693
else if (S_ISREG (statbuf .st_mode ))
694
694
{
695
- /* Add size, rounded up to 512byte block */
696
- size += (( statbuf . st_size + 511 ) & ~ 511 );
695
+ bool sent = false;
696
+
697
697
if (!sizeonly )
698
- sendFile (pathbuf ,pathbuf + basepathlen + 1 ,& statbuf );
699
- size += 512 ;/* Size of the header of the file */
698
+ sent = sendFile (pathbuf ,pathbuf + basepathlen + 1 ,& statbuf ,
699
+ true);
700
+
701
+ if (sent || sizeonly )
702
+ {
703
+ /* Add size, rounded up to 512byte block */
704
+ size += ((statbuf .st_size + 511 )& ~511 );
705
+ size += 512 ;/* Size of the header of the file */
706
+ }
700
707
}
701
708
else
702
709
ereport (WARNING ,
@@ -756,9 +763,17 @@ _tarChecksum(char *header)
756
763
return sum ;
757
764
}
758
765
759
- /* Given the member, write the TAR header & send the file */
760
- static void
761
- sendFile (char * readfilename ,char * tarfilename ,struct stat * statbuf )
766
+ /*
767
+ * Given the member, write the TAR header & send the file.
768
+ *
769
+ * If 'missing_ok' is true, will not throw an error if the file is not found.
770
+ *
771
+ * Returns true if the file was successfully sent, false if 'missing_ok',
772
+ * and the file did not exist.
773
+ */
774
+ static bool
775
+ sendFile (char * readfilename ,char * tarfilename ,struct stat * statbuf ,
776
+ bool missing_ok )
762
777
{
763
778
FILE * fp ;
764
779
char buf [TAR_SEND_SIZE ];
@@ -768,9 +783,13 @@ sendFile(char *readfilename, char *tarfilename, struct stat * statbuf)
768
783
769
784
fp = AllocateFile (readfilename ,"rb" );
770
785
if (fp == NULL )
786
+ {
787
+ if (errno == ENOENT && missing_ok )
788
+ return false;
771
789
ereport (ERROR ,
772
790
(errcode_for_file_access (),
773
791
errmsg ("could not open file \"%s\": %m" ,readfilename )));
792
+ }
774
793
775
794
/*
776
795
* Some compilers will throw a warning knowing this test can never be true
@@ -824,6 +843,8 @@ sendFile(char *readfilename, char *tarfilename, struct stat * statbuf)
824
843
}
825
844
826
845
FreeFile (fp );
846
+
847
+ return true;
827
848
}
828
849
829
850