Skip to content

Commit 957de55

Browse files
author
Artur Zakirov
committed
Check that OLDDIR has an entry in links first
1 parent 9ace401 commit 957de55

File tree

3 files changed

+28
-18
lines changed

3 files changed

+28
-18
lines changed

dir.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,16 @@ pgFileComparePathDesc(const void *f1, const void *f2)
206206
return -pgFileComparePath(f1, f2);
207207
}
208208

209+
/* Compare two pgFile with their linked directory path. */
210+
int
211+
pgFileCompareLinked(const void *f1, const void *f2)
212+
{
213+
pgFile *f1p = *(pgFile **)f1;
214+
pgFile *f2p = *(pgFile **)f2;
215+
216+
return strcmp(f1p->linked, f2p->linked);
217+
}
218+
209219
/* Compare two pgFile with their size */
210220
int
211221
pgFileCompareSize(const void *f1, const void *f2)

pg_probackup.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,7 @@ extern void pgFileFree(void *file);
330330
extern pg_crc32 pgFileGetCRC(pgFile *file);
331331
extern int pgFileComparePath(const void *f1, const void *f2);
332332
extern int pgFileComparePathDesc(const void *f1, const void *f2);
333+
extern int pgFileCompareLinked(const void *f1, const void *f2);
333334
extern int pgFileCompareSize(const void *f1, const void *f2);
334335
extern int pgFileCompareMtime(const void *f1, const void *f2);
335336
extern int pgFileCompareMtimeDesc(const void *f1, const void *f2);

restore.c

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -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

3735
typedef 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

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy