Skip to content

Commit ecc5e56

Browse files
committed
Fix readTimeLineHistory_probackup(). It should check existance of history file
1 parent 35471b5 commit ecc5e56

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

restore.c

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -727,28 +727,36 @@ readTimeLineHistory_probackup(TimeLineID targetTLI)
727727
parray *result;
728728
char path[MAXPGPATH];
729729
char fline[MAXPGPATH];
730-
FILE *fd;
730+
FILE *fd = NULL;
731731
TimeLineHistoryEntry *entry;
732732
TimeLineHistoryEntry *last_timeline = NULL;
733733

734734
/* Look for timeline history file in archlog_path */
735735
snprintf(path, lengthof(path), "%s/%08X.history", arclog_path,
736736
targetTLI);
737737

738-
fd = fopen(path, "rt");
739-
if (fd == NULL)
738+
/* Timeline 1 does not have a history file */
739+
if (targetTLI != 1)
740740
{
741-
if (errno != ENOENT)
742-
elog(ERROR, "could not open file \"%s\": %s", path,
743-
strerror(errno));
741+
fd = fopen(path, "rt");
742+
if (fd == NULL)
743+
{
744+
if (errno != ENOENT)
745+
elog(ERROR, "could not open file \"%s\": %s", path,
746+
strerror(errno));
747+
748+
/* There is no history file for target timeline */
749+
elog(ERROR, "recovery target timeline %u does not exist",
750+
targetTLI);
751+
}
744752
}
745753

746754
result = parray_new();
747755

748756
/*
749757
* Parse the file...
750758
*/
751-
while (fgets(fline, sizeof(fline), fd) != NULL)
759+
while (fd && fgets(fline, sizeof(fline), fd) != NULL)
752760
{
753761
char *ptr;
754762
TimeLineID tli;
@@ -797,8 +805,7 @@ readTimeLineHistory_probackup(TimeLineID targetTLI)
797805
fclose(fd);
798806

799807
if (last_timeline && targetTLI <= last_timeline->tli)
800-
elog(ERROR,
801-
"Timeline IDs must be less than child timeline's ID.");
808+
elog(ERROR, "Timeline IDs must be less than child timeline's ID.");
802809

803810
/* append target timeline */
804811
entry = pgut_new(TimeLineHistoryEntry);

show.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,10 @@ get_parent_tli(TimeLineID child_tli)
116116
char fline[MAXPGPATH];
117117
FILE *fd;
118118

119+
/* Timeline 1 does not have a history file and parent timeline */
120+
if (child_tli == 1)
121+
return 0;
122+
119123
/* Search history file in archives */
120124
snprintf(path, lengthof(path), "%s/%08X.history", arclog_path,
121125
child_tli);
@@ -126,6 +130,7 @@ get_parent_tli(TimeLineID child_tli)
126130
elog(ERROR, "could not open file \"%s\": %s", path,
127131
strerror(errno));
128132

133+
/* Did not find history file, do not raise the error */
129134
return 0;
130135
}
131136

0 commit comments

Comments
 (0)