From d4a8384cfaa720f6e7dfd2d287a8acc5e3fc7b06 Mon Sep 17 00:00:00 2001 From: Grigory Smolkin Date: Sat, 23 May 2020 03:45:24 +0300 Subject: [PATCH] [Issue #201] use parent link instead of backup list in restore_non_data_file() --- src/data.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/data.c b/src/data.c index 571c40a0..ced1c716 100644 --- a/src/data.c +++ b/src/data.c @@ -1191,7 +1191,7 @@ size_t restore_non_data_file(parray *parent_chain, pgBackup *dest_backup, pgFile *dest_file, FILE *out, const char *to_fullpath) { - int i; +// int i; char from_root[MAXPGPATH]; char from_fullpath[MAXPGPATH]; FILE *in = NULL; @@ -1213,14 +1213,12 @@ restore_non_data_file(parray *parent_chain, pgBackup *dest_backup, * full copy of destination file. * Full copy is latest possible destination file with size equal or * greater than zero. - * TODO: rewrite to use parent_link of dest backup. */ - for (i = 1; i < parray_num(parent_chain); i++) + tmp_backup = dest_backup->parent_backup_link; + while (tmp_backup) { pgFile **res_file = NULL; - tmp_backup = (pgBackup *) parray_get(parent_chain, i); - /* lookup file in intermediate backup */ res_file = parray_bsearch(tmp_backup->files, dest_file, pgFileCompareRelPathWithExternal); tmp_file = (res_file) ? *res_file : NULL; @@ -1243,6 +1241,8 @@ restore_non_data_file(parray *parent_chain, pgBackup *dest_backup, /* Full copy is found */ if (tmp_file->write_size > 0) break; + + tmp_backup = tmp_backup->parent_backup_link; } } @@ -1254,6 +1254,11 @@ restore_non_data_file(parray *parent_chain, pgBackup *dest_backup, if (!tmp_file) elog(ERROR, "Failed to locate a full copy of non-data file \"%s\"", to_fullpath); + if (tmp_file->write_size <= 0) + elog(ERROR, "Full copy of non-data file has invalid size. " + "Metadata corruption in backup %s in file: \"%s\"", + base36enc(tmp_backup->start_time), to_fullpath); + if (tmp_file->external_dir_num == 0) join_path_components(from_root, tmp_backup->root_dir, DATABASE_DIR); else