mirror of
https://github.com/postgrespro/pg_probackup.git
synced 2025-02-03 14:01:57 +02:00
Check that OLDDIR has an entry in links first
This commit is contained in:
parent
9ace401921
commit
957de55a85
10
dir.c
10
dir.c
@ -206,6 +206,16 @@ pgFileComparePathDesc(const void *f1, const void *f2)
|
||||
return -pgFileComparePath(f1, f2);
|
||||
}
|
||||
|
||||
/* Compare two pgFile with their linked directory path. */
|
||||
int
|
||||
pgFileCompareLinked(const void *f1, const void *f2)
|
||||
{
|
||||
pgFile *f1p = *(pgFile **)f1;
|
||||
pgFile *f2p = *(pgFile **)f2;
|
||||
|
||||
return strcmp(f1p->linked, f2p->linked);
|
||||
}
|
||||
|
||||
/* Compare two pgFile with their size */
|
||||
int
|
||||
pgFileCompareSize(const void *f1, const void *f2)
|
||||
|
@ -330,6 +330,7 @@ extern void pgFileFree(void *file);
|
||||
extern pg_crc32 pgFileGetCRC(pgFile *file);
|
||||
extern int pgFileComparePath(const void *f1, const void *f2);
|
||||
extern int pgFileComparePathDesc(const void *f1, const void *f2);
|
||||
extern int pgFileCompareLinked(const void *f1, const void *f2);
|
||||
extern int pgFileCompareSize(const void *f1, const void *f2);
|
||||
extern int pgFileCompareMtime(const void *f1, const void *f2);
|
||||
extern int pgFileCompareMtimeDesc(const void *f1, const void *f2);
|
||||
|
35
restore.c
35
restore.c
@ -30,8 +30,6 @@ typedef struct TablespaceListCell
|
||||
struct TablespaceListCell *next;
|
||||
char old_dir[MAXPGPATH];
|
||||
char new_dir[MAXPGPATH];
|
||||
bool checked; /* If this mapping was checked during
|
||||
restore */
|
||||
} TablespaceListCell;
|
||||
|
||||
typedef struct TablespaceList
|
||||
@ -508,10 +506,10 @@ restore_directories(const char *pg_data_dir, const char *backup_dir)
|
||||
dir_create_dir(to_path, DIR_PERMISSION);
|
||||
}
|
||||
|
||||
parray_walk(links, pgBackupFree);
|
||||
parray_walk(links, pgFileFree);
|
||||
parray_free(links);
|
||||
|
||||
parray_walk(dirs, pgBackupFree);
|
||||
parray_walk(dirs, pgFileFree);
|
||||
parray_free(dirs);
|
||||
}
|
||||
|
||||
@ -529,6 +527,7 @@ check_tablespace_mapping(pgBackup *backup)
|
||||
parray *links;
|
||||
size_t i;
|
||||
TablespaceListCell *cell;
|
||||
pgFile *tmp_file = pgut_new(pgFile);
|
||||
|
||||
links = parray_new();
|
||||
|
||||
@ -537,7 +536,18 @@ check_tablespace_mapping(pgBackup *backup)
|
||||
|
||||
elog(LOG, "check tablespace directories...");
|
||||
|
||||
/* 1 - all linked directories should be empty */
|
||||
/* 1 - OLDDIR should has an entry in links */
|
||||
for (cell = tablespace_dirs.head; cell; cell = cell->next)
|
||||
{
|
||||
tmp_file->linked = cell->old_dir;
|
||||
|
||||
if (parray_bsearch(links, tmp_file, pgFileCompareLinked) == NULL)
|
||||
elog(ERROR, "--tablespace-mapping option's old directory "
|
||||
"has not an entry in tablespace_map file: \"%s\"",
|
||||
cell->old_dir);
|
||||
}
|
||||
|
||||
/* 2 - all linked directories should be empty */
|
||||
for (i = 0; i < parray_num(links); i++)
|
||||
{
|
||||
pgFile *link = (pgFile *) parray_get(links, i);
|
||||
@ -548,7 +558,6 @@ check_tablespace_mapping(pgBackup *backup)
|
||||
if (strcmp(link->linked, cell->old_dir) == 0)
|
||||
{
|
||||
linked_path = cell->new_dir;
|
||||
cell->checked = true;
|
||||
break;
|
||||
}
|
||||
|
||||
@ -561,16 +570,8 @@ check_tablespace_mapping(pgBackup *backup)
|
||||
linked_path);
|
||||
}
|
||||
|
||||
/* 2 - OLDDIR should has an entry in links */
|
||||
for (cell = tablespace_dirs.head; cell; cell = cell->next)
|
||||
{
|
||||
if (!cell->checked)
|
||||
elog(ERROR, "--tablespace-mapping option's old directory "
|
||||
"has not an entry in tablespace_map file: \"%s\"",
|
||||
cell->old_dir);
|
||||
}
|
||||
|
||||
parray_walk(links, pgBackupFree);
|
||||
free(tmp_file);
|
||||
parray_walk(links, pgFileFree);
|
||||
parray_free(links);
|
||||
}
|
||||
|
||||
@ -1049,8 +1050,6 @@ opt_tablespace_map(pgut_option *opt, const char *arg)
|
||||
elog(ERROR, "new directory is not an absolute path in tablespace mapping: %s\n",
|
||||
cell->new_dir);
|
||||
|
||||
cell->checked = false;
|
||||
|
||||
if (tablespace_dirs.tail)
|
||||
tablespace_dirs.tail->next = cell;
|
||||
else
|
||||
|
Loading…
x
Reference in New Issue
Block a user