1
0
mirror of https://github.com/postgrespro/pg_probackup.git synced 2025-01-20 11:34:51 +02:00

Fix readTimeLineHistory_probackup(). It should check existance of history file

This commit is contained in:
Arthur Zakirov 2017-04-27 17:10:26 +03:00
parent 35471b52ed
commit ecc5e56201
2 changed files with 21 additions and 9 deletions

View File

@ -727,7 +727,7 @@ readTimeLineHistory_probackup(TimeLineID targetTLI)
parray *result;
char path[MAXPGPATH];
char fline[MAXPGPATH];
FILE *fd;
FILE *fd = NULL;
TimeLineHistoryEntry *entry;
TimeLineHistoryEntry *last_timeline = NULL;
@ -735,12 +735,20 @@ readTimeLineHistory_probackup(TimeLineID targetTLI)
snprintf(path, lengthof(path), "%s/%08X.history", arclog_path,
targetTLI);
fd = fopen(path, "rt");
if (fd == NULL)
/* Timeline 1 does not have a history file */
if (targetTLI != 1)
{
if (errno != ENOENT)
elog(ERROR, "could not open file \"%s\": %s", path,
strerror(errno));
fd = fopen(path, "rt");
if (fd == NULL)
{
if (errno != ENOENT)
elog(ERROR, "could not open file \"%s\": %s", path,
strerror(errno));
/* There is no history file for target timeline */
elog(ERROR, "recovery target timeline %u does not exist",
targetTLI);
}
}
result = parray_new();
@ -748,7 +756,7 @@ readTimeLineHistory_probackup(TimeLineID targetTLI)
/*
* Parse the file...
*/
while (fgets(fline, sizeof(fline), fd) != NULL)
while (fd && fgets(fline, sizeof(fline), fd) != NULL)
{
char *ptr;
TimeLineID tli;
@ -797,8 +805,7 @@ readTimeLineHistory_probackup(TimeLineID targetTLI)
fclose(fd);
if (last_timeline && targetTLI <= last_timeline->tli)
elog(ERROR,
"Timeline IDs must be less than child timeline's ID.");
elog(ERROR, "Timeline IDs must be less than child timeline's ID.");
/* append target timeline */
entry = pgut_new(TimeLineHistoryEntry);

5
show.c
View File

@ -116,6 +116,10 @@ get_parent_tli(TimeLineID child_tli)
char fline[MAXPGPATH];
FILE *fd;
/* Timeline 1 does not have a history file and parent timeline */
if (child_tli == 1)
return 0;
/* Search history file in archives */
snprintf(path, lengthof(path), "%s/%08X.history", arclog_path,
child_tli);
@ -126,6 +130,7 @@ get_parent_tli(TimeLineID child_tli)
elog(ERROR, "could not open file \"%s\": %s", path,
strerror(errno));
/* Did not find history file, do not raise the error */
return 0;
}