@@ -30,8 +30,6 @@ typedef struct TablespaceListCell
3030 struct TablespaceListCell * next ;
3131 char old_dir [MAXPGPATH ];
3232 char new_dir [MAXPGPATH ];
33- bool checked ; /* If this mapping was checked during
34- restore */
3533} TablespaceListCell ;
3634
3735typedef struct TablespaceList
@@ -508,10 +506,10 @@ restore_directories(const char *pg_data_dir, const char *backup_dir)
508506 dir_create_dir (to_path , DIR_PERMISSION );
509507 }
510508
511- parray_walk (links , pgBackupFree );
509+ parray_walk (links , pgFileFree );
512510 parray_free (links );
513511
514- parray_walk (dirs , pgBackupFree );
512+ parray_walk (dirs , pgFileFree );
515513 parray_free (dirs );
516514}
517515
@@ -529,6 +527,7 @@ check_tablespace_mapping(pgBackup *backup)
529527 parray * links ;
530528 size_t i ;
531529 TablespaceListCell * cell ;
530+ pgFile * tmp_file = pgut_new (pgFile );
532531
533532 links = parray_new ();
534533
@@ -537,7 +536,18 @@ check_tablespace_mapping(pgBackup *backup)
537536
538537 elog (LOG , "check tablespace directories..." );
539538
540- /* 1 - all linked directories should be empty */
539+ /* 1 - OLDDIR should has an entry in links */
540+ for (cell = tablespace_dirs .head ; cell ; cell = cell -> next )
541+ {
542+ tmp_file -> linked = cell -> old_dir ;
543+
544+ if (parray_bsearch (links , tmp_file , pgFileCompareLinked ) == NULL )
545+ elog (ERROR , "--tablespace-mapping option's old directory "
546+ "has not an entry in tablespace_map file: \"%s\"" ,
547+ cell -> old_dir );
548+ }
549+
550+ /* 2 - all linked directories should be empty */
541551 for (i = 0 ; i < parray_num (links ); i ++ )
542552 {
543553 pgFile * link = (pgFile * ) parray_get (links , i );
@@ -548,7 +558,6 @@ check_tablespace_mapping(pgBackup *backup)
548558 if (strcmp (link -> linked , cell -> old_dir ) == 0 )
549559 {
550560 linked_path = cell -> new_dir ;
551- cell -> checked = true;
552561 break ;
553562 }
554563
@@ -561,16 +570,8 @@ check_tablespace_mapping(pgBackup *backup)
561570 linked_path );
562571 }
563572
564- /* 2 - OLDDIR should has an entry in links */
565- for (cell = tablespace_dirs .head ; cell ; cell = cell -> next )
566- {
567- if (!cell -> checked )
568- elog (ERROR , "--tablespace-mapping option's old directory "
569- "has not an entry in tablespace_map file: \"%s\"" ,
570- cell -> old_dir );
571- }
572-
573- parray_walk (links , pgBackupFree );
573+ free (tmp_file );
574+ parray_walk (links , pgFileFree );
574575 parray_free (links );
575576}
576577
@@ -1049,8 +1050,6 @@ opt_tablespace_map(pgut_option *opt, const char *arg)
10491050 elog (ERROR , "new directory is not an absolute path in tablespace mapping: %s\n" ,
10501051 cell -> new_dir );
10511052
1052- cell -> checked = false;
1053-
10541053 if (tablespace_dirs .tail )
10551054 tablespace_dirs .tail -> next = cell ;
10561055 else
0 commit comments