You've already forked pg_probackup
							
							
				mirror of
				https://github.com/postgrespro/pg_probackup.git
				synced 2025-10-31 00:17:52 +02:00 
			
		
		
		
	Fix readTimeLineHistory_probackup(). It should check existance of history file
This commit is contained in:
		
							
								
								
									
										25
									
								
								restore.c
									
									
									
									
									
								
							
							
						
						
									
										25
									
								
								restore.c
									
									
									
									
									
								
							| @@ -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
									
									
									
									
									
								
							
							
						
						
									
										5
									
								
								show.c
									
									
									
									
									
								
							| @@ -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; | ||||
| 	} | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user