@@ -57,6 +57,8 @@ static bool sendFile(char *readfilename, char *tarfilename,
57
57
static void sendFileWithContent (const char * filename , const char * content );
58
58
static void _tarWriteHeader (const char * filename , const char * linktarget ,
59
59
struct stat * statbuf );
60
+ static int64 _tarWriteDir (const char * pathbuf , int basepathlen , struct stat * statbuf ,
61
+ bool sizeonly );
60
62
static void send_int8_string (StringInfoData * buf , int64 intval );
61
63
static void SendBackupHeader (List * tablespaces );
62
64
static void base_backup_cleanup (int code , Datum arg );
@@ -969,9 +971,7 @@ sendDir(char *path, int basepathlen, bool sizeonly, List *tablespaces,
969
971
if ((statrelpath != NULL && strcmp (pathbuf , statrelpath ) == 0 ) ||
970
972
strncmp (de -> d_name , PG_STAT_TMP_DIR , strlen (PG_STAT_TMP_DIR )) == 0 )
971
973
{
972
- if (!sizeonly )
973
- _tarWriteHeader (pathbuf + basepathlen + 1 , NULL , & statbuf );
974
- size += 512 ;
974
+ size += _tarWriteDir (pathbuf , basepathlen , & statbuf , sizeonly );
975
975
continue ;
976
976
}
977
977
@@ -981,9 +981,7 @@ sendDir(char *path, int basepathlen, bool sizeonly, List *tablespaces,
981
981
*/
982
982
if (strcmp (de -> d_name , "pg_replslot" ) == 0 )
983
983
{
984
- if (!sizeonly )
985
- _tarWriteHeader (pathbuf + basepathlen + 1 , NULL , & statbuf );
986
- size += 512 ; /* Size of the header just added */
984
+ size += _tarWriteDir (pathbuf , basepathlen , & statbuf , sizeonly );
987
985
continue ;
988
986
}
989
987
@@ -994,18 +992,8 @@ sendDir(char *path, int basepathlen, bool sizeonly, List *tablespaces,
994
992
*/
995
993
if (strcmp (pathbuf , "./pg_xlog" ) == 0 )
996
994
{
997
- if (!sizeonly )
998
- {
999
- /* If pg_xlog is a symlink, write it as a directory anyway */
1000
- #ifndef WIN32
1001
- if (S_ISLNK (statbuf .st_mode ))
1002
- #else
1003
- if (pgwin32_is_junction (pathbuf ))
1004
- #endif
1005
- statbuf .st_mode = S_IFDIR | S_IRWXU ;
1006
- _tarWriteHeader (pathbuf + basepathlen + 1 , NULL , & statbuf );
1007
- }
1008
- size += 512 ; /* Size of the header just added */
995
+ /* If pg_xlog is a symlink, write it as a directory anyway */
996
+ size += _tarWriteDir (pathbuf , basepathlen , & statbuf , sizeonly );
1009
997
1010
998
/*
1011
999
* Also send archive_status directory (by hackishly reusing
@@ -1247,6 +1235,30 @@ _tarWriteHeader(const char *filename, const char *linktarget,
1247
1235
pq_putmessage ('d' , h , 512 );
1248
1236
}
1249
1237
1238
+ /*
1239
+ * Write tar header for a directory. If the entry in statbuf is a link then
1240
+ * write it as a directory anyway.
1241
+ */
1242
+ static int64
1243
+ _tarWriteDir (const char * pathbuf , int basepathlen , struct stat * statbuf ,
1244
+ bool sizeonly )
1245
+ {
1246
+ if (sizeonly )
1247
+ /* Directory headers are always 512 bytes */
1248
+ return 512 ;
1249
+
1250
+ /* If symlink, write it as a directory anyway */
1251
+ #ifndef WIN32
1252
+ if (S_ISLNK (statbuf -> st_mode ))
1253
+ #else
1254
+ if (pgwin32_is_junction (pathbuf ))
1255
+ #endif
1256
+ statbuf -> st_mode = S_IFDIR | S_IRWXU ;
1257
+
1258
+ _tarWriteHeader (pathbuf + basepathlen + 1 , NULL , statbuf );
1259
+ return 512 ;
1260
+ }
1261
+
1250
1262
/*
1251
1263
* Increment the network transfer counter by the given number of bytes,
1252
1264
* and sleep if necessary to comply with the requested network transfer
0 commit comments