@@ -416,7 +416,7 @@ restore_directories(const char *pg_data_dir, const char *backup_dir)
416416link_name [len ]= '\0' ;
417417}
418418else
419- strcpy ( link_name , link_ptr ) ;
419+ goto create_directory ;
420420
421421tmp_ptr = dir -> path ;
422422dir -> path = link_name ;
@@ -442,7 +442,13 @@ restore_directories(const char *pg_data_dir, const char *backup_dir)
442442 * create it second time.
443443 */
444444if (strcmp (dir_created ,linked_path )== 0 )
445- continue ;
445+ {
446+ /* Create rest of directories */
447+ if (link_sep && (link_sep + 1 ))
448+ gotocreate_directory ;
449+ else
450+ continue ;
451+ }
446452else
447453elog (ERROR ,"tablespace directory \"%s\" of page backup does not "
448454"match with previous created tablespace directory \"%s\" of symlink \"%s\"" ,
@@ -467,12 +473,6 @@ restore_directories(const char *pg_data_dir, const char *backup_dir)
467473
468474/* Firstly, create linked directory */
469475dir_create_dir (linked_path ,DIR_PERMISSION );
470- /* Create rest of directories */
471- if (link_sep && (link_sep + 1 ))
472- {
473- join_path_components (to_path ,linked_path ,link_sep + 1 );
474- dir_create_dir (to_path ,DIR_PERMISSION );
475- }
476476
477477join_path_components (to_path ,pg_data_dir ,PG_TBLSPC_DIR );
478478/* Create pg_tblspc directory just in case */
@@ -487,10 +487,15 @@ restore_directories(const char *pg_data_dir, const char *backup_dir)
487487/* Save linked directory */
488488set_tablespace_created (link_name ,linked_path );
489489
490+ /* Create rest of directories */
491+ if (link_sep && (link_sep + 1 ))
492+ gotocreate_directory ;
493+
490494continue ;
491495}
492496}
493497
498+ create_directory :
494499elog (LOG ,"create directory \"%s\"" ,relative_ptr );
495500
496501/* This is not symlink, create directory */