From fb4ae4a2356804d64e51213c43632bd78629d922 Mon Sep 17 00:00:00 2001 From: stalkerg Date: Tue, 13 Sep 2016 19:50:59 +0300 Subject: [PATCH] Fix recalc checksums during restore for segno > 0. --- data.c | 2 +- dir.c | 26 +++++++++++++++++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/data.c b/data.c index c78b9541..eb57d8ae 100644 --- a/data.c +++ b/data.c @@ -519,7 +519,7 @@ restore_data_file(const char *from_root, if (i == BLCKSZ) goto skip_checksum; } - ((PageHeader) page.data)->pd_checksum = pg_checksum_page(page.data, header.block); + ((PageHeader) page.data)->pd_checksum = pg_checksum_page(page.data, file->segno * RELSEG_SIZE + header.block); } skip_checksum: diff --git a/dir.c b/dir.c index 1d851b22..195a5e7f 100644 --- a/dir.c +++ b/dir.c @@ -547,7 +547,7 @@ dir_read_file_list(const char *root, const char *file_txt) pg_crc32 crc; unsigned int mode; /* bit length of mode_t depends on platforms */ struct tm tm; - pgFile *file; + pgFile *file; memset(&tm, 0, sizeof(tm)); if (sscanf(buf, "%s %c %lu %u %o %d-%d-%d %d:%d:%d", @@ -590,6 +590,30 @@ dir_read_file_list(const char *root, const char *file_txt) strcpy(file->path, path); parray_append(files, file); + + if(file->is_datafile) + { + int find_dot; + int check_digit; + char *text_segno; + size_t path_len = strlen(file->path); + for(find_dot = path_len-1; file->path[find_dot] != '.' && find_dot >= 0; find_dot--); + if (find_dot <= 0) + continue; + + text_segno = file->path + find_dot + 1; + for(check_digit=0; text_segno[check_digit] != '\0'; check_digit++) + if (!isdigit(text_segno[check_digit])) + { + check_digit = -1; + break; + } + + if (check_digit == -1) + continue; + + file->segno = (int) strtol(text_segno, NULL, 10); + } } fclose(fp);