@@ -294,9 +294,11 @@ pgmoneta_receive_archive_files(int srv, SSL* ssl, int socket, struct stream_buff
294294 {
295295 char file_path [MAX_PATH ];
296296 char directory [MAX_PATH ];
297+ char manifest_prefix [MAX_PATH ];
297298 const char * archive_ext = basebackup_archive_extension ();
298299 memset (file_path , 0 , sizeof (file_path ));
299300 memset (directory , 0 , sizeof (directory ));
301+ memset (manifest_prefix , 0 , sizeof (manifest_prefix ));
300302 if (tup -> data [1 ] == NULL )
301303 {
302304 // main data directory
@@ -320,6 +322,7 @@ pgmoneta_receive_archive_files(int srv, SSL* ssl, int socket, struct stream_buff
320322 if (pgmoneta_compare_string (tup -> data [1 ], tblspc -> path ))
321323 {
322324 tblspc -> oid = atoi (tup -> data [0 ]);
325+ pgmoneta_snprintf (manifest_prefix , sizeof (manifest_prefix ), "pg_tblspc/%d" , tblspc -> oid );
323326 break ;
324327 }
325328 tblspc = tblspc -> next ;
@@ -394,7 +397,7 @@ pgmoneta_receive_archive_files(int srv, SSL* ssl, int socket, struct stream_buff
394397 fclose (file );
395398
396399 // extract the file
397- if (pgmoneta_extract_backup_tar_file (file_path , directory , file_checksums , file_sizes ))
400+ if (pgmoneta_extract_backup_tar_file (file_path , directory , file_checksums , file_sizes , manifest_prefix ))
398401 {
399402 goto error ;
400403 }
@@ -479,6 +482,7 @@ pgmoneta_receive_archive_stream(int srv, SSL* ssl, int socket, struct stream_buf
479482 char file_path [MAX_PATH ];
480483 char directory [MAX_PATH ];
481484 char link_path [MAX_PATH ];
485+ char manifest_prefix [MAX_PATH ];
482486 char tmp_manifest_file_path [MAX_PATH ];
483487 char manifest_file_path [MAX_PATH ];
484488 struct art * file_sizes = NULL ;
@@ -487,6 +491,7 @@ pgmoneta_receive_archive_stream(int srv, SSL* ssl, int socket, struct stream_buf
487491 memset (file_path , 0 , sizeof (file_path ));
488492 memset (directory , 0 , sizeof (directory ));
489493 memset (link_path , 0 , sizeof (link_path ));
494+ memset (manifest_prefix , 0 , sizeof (manifest_prefix ));
490495 memset (manifest_file_path , 0 , sizeof (manifest_file_path ));
491496 memset (tmp_manifest_file_path , 0 , sizeof (tmp_manifest_file_path ));
492497 memset (null_buffer , 0 , 2 * 512 );
@@ -568,7 +573,7 @@ pgmoneta_receive_archive_stream(int srv, SSL* ssl, int socket, struct stream_buf
568573 fflush (file );
569574 fclose (file );
570575 file = NULL ;
571- if (pgmoneta_extract_backup_tar_file (file_path , directory , file_checksums , file_sizes ))
576+ if (pgmoneta_extract_backup_tar_file (file_path , directory , file_checksums , file_sizes , manifest_prefix ))
572577 {
573578 goto error ;
574579 }
@@ -580,6 +585,7 @@ pgmoneta_receive_archive_stream(int srv, SSL* ssl, int socket, struct stream_buf
580585
581586 memset (file_path , 0 , sizeof (file_path ));
582587 memset (directory , 0 , sizeof (directory ));
588+ memset (manifest_prefix , 0 , sizeof (manifest_prefix ));
583589 const char * archive_ext = basebackup_archive_extension ();
584590 // The tablespace order in the second result set is presumably the same as the order in which the server sends tablespaces
585591 tblspc = tablespaces ;
@@ -614,6 +620,7 @@ pgmoneta_receive_archive_stream(int srv, SSL* ssl, int socket, struct stream_buf
614620 if (pgmoneta_compare_string (tblspc -> path , archive_path ))
615621 {
616622 tblspc -> oid = atoi (tup -> data [0 ]);
623+ pgmoneta_snprintf (manifest_prefix , sizeof (manifest_prefix ), "pg_tblspc/%d" , tblspc -> oid );
617624 break ;
618625 }
619626 tblspc = tblspc -> next ;
@@ -655,7 +662,7 @@ pgmoneta_receive_archive_stream(int srv, SSL* ssl, int socket, struct stream_buf
655662 fflush (file );
656663 fclose (file );
657664 file = NULL ;
658- if (pgmoneta_extract_backup_tar_file (file_path , directory , file_checksums , file_sizes ))
665+ if (pgmoneta_extract_backup_tar_file (file_path , directory , file_checksums , file_sizes , manifest_prefix ))
659666 {
660667 goto error ;
661668 }
@@ -795,7 +802,7 @@ pgmoneta_receive_archive_stream(int srv, SSL* ssl, int socket, struct stream_buf
795802}
796803
797804int
798- pgmoneta_extract_backup_tar_file (char * file_path , char * destination , struct art * file_checksums , struct art * file_sizes )
805+ pgmoneta_extract_backup_tar_file (char * file_path , char * destination , struct art * file_checksums , struct art * file_sizes , char * manifest_prefix )
799806{
800807 char * archive_name = NULL ;
801808 struct archive * a ;
@@ -905,6 +912,11 @@ pgmoneta_extract_backup_tar_file(char* file_path, char* destination, struct art*
905912 pgmoneta_snprintf (dst_path , sizeof (dst_path ), "%s/%s" , destination , entry_path );
906913 }
907914
915+ if (type == AE_IFLNK && pgmoneta_ends_with (dst_path , "/" ))
916+ {
917+ dst_path [strlen (dst_path ) - 1 ] = '\0' ;
918+ }
919+
908920 if (type == AE_IFDIR )
909921 {
910922 if (pgmoneta_mkdir (dst_path ))
@@ -987,6 +999,11 @@ pgmoneta_extract_backup_tar_file(char* file_path, char* destination, struct art*
987999 }
9881000 while (asize > 0 );
9891001
1002+ if (manifest_prefix != NULL && strlen (manifest_prefix ) > 0 )
1003+ {
1004+ entry_path_cpy = pgmoneta_append (entry_path_cpy , manifest_prefix );
1005+ entry_path_cpy = pgmoneta_append (entry_path_cpy , "/" );
1006+ }
9901007 entry_path_cpy = pgmoneta_append (entry_path_cpy , entry_path );
9911008 pgmoneta_art_insert (file_sizes , entry_path_cpy , (uintptr_t )strm -> written , ValueUInt64 );
9921009 pgmoneta_art_insert (file_checksums , entry_path_cpy , (uintptr_t )hasher -> hash , ValueString );
0 commit comments