From c67832583e943b6ab3bdecb95b3aef7b110835b1 Mon Sep 17 00:00:00 2001 From: stalkerg Date: Thu, 29 Sep 2016 19:44:59 +0300 Subject: [PATCH] Add backup_label to file_database.txt for all checks. --- backup.c | 11 +++++++++++ data.c | 8 +++++--- dir.c | 4 ++-- pg_arman.h | 1 + 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/backup.c b/backup.c index e288ea7b..d842d97d 100644 --- a/backup.c +++ b/backup.c @@ -888,6 +888,7 @@ get_lsn(PGconn *conn, PGresult *res, XLogRecPtr *lsn, bool stop_backup) char path_backup_label[MAXPGPATH]; char path_tablespace_map[MAXPGPATH]; FILE *fp; + pgFile *file; pgBackupGetPath(¤t, path, lengthof(path), DATABASE_DIR); snprintf(path_backup_label, lengthof(path_backup_label), "%s/backup_label", path); @@ -900,6 +901,11 @@ get_lsn(PGconn *conn, PGresult *res, XLogRecPtr *lsn, bool stop_backup) fwrite(PQgetvalue(res, 0, 1), 1, strlen(PQgetvalue(res, 0, 1)), fp); fclose(fp); + file = pgFileNew(path_backup_label, true); + calc_file(file); + free(file->path); + file->path = strdup("backup_label"); + parray_append(backup_files_list, file); if (strlen(PQgetvalue(res, 0, 2)) == 0) return; @@ -910,6 +916,11 @@ get_lsn(PGconn *conn, PGresult *res, XLogRecPtr *lsn, bool stop_backup) fwrite(PQgetvalue(res, 0, 2), 1, strlen(PQgetvalue(res, 0, 2)), fp); fclose(fp); + file = pgFileNew(path_tablespace_map, true); + calc_file(file); + free(file->path); + file->path = strdup("tablespace_map"); + parray_append(backup_files_list, file); } } diff --git a/data.c b/data.c index eb57d8ae..df30019a 100644 --- a/data.c +++ b/data.c @@ -722,14 +722,16 @@ calc_file(pgFile *file) for (;;) { - if ((read_len = fread(buf, 1, sizeof(buf), in)) != sizeof(buf)) + read_len = fread(buf, 1, sizeof(buf), in); + + if(read_len == 0) break; /* update CRC */ COMP_CRC32C(crc, buf, read_len); - file->write_size += sizeof(buf); - file->read_size += sizeof(buf); + file->write_size += read_len; + file->read_size += read_len; } errno_tmp = errno; diff --git a/dir.c b/dir.c index 195a5e7f..9890aba3 100644 --- a/dir.c +++ b/dir.c @@ -31,7 +31,7 @@ const char *pgdata_exclude[] = NULL }; -static pgFile *pgFileNew(const char *path, bool omit_symlink); +pgFile *pgFileNew(const char *path, bool omit_symlink); static int BlackListCompare(const void *str1, const void *str2); /* create directory, also create parent directories if necessary */ @@ -60,7 +60,7 @@ dir_create_dir(const char *dir, mode_t mode) return 0; } -static pgFile * +pgFile * pgFileNew(const char *path, bool omit_symlink) { struct stat st; diff --git a/pg_arman.h b/pg_arman.h index 5db23d5f..5a997e2d 100644 --- a/pg_arman.h +++ b/pg_arman.h @@ -283,6 +283,7 @@ extern parray *dir_read_file_list(const char *root, const char *file_txt); extern int dir_create_dir(const char *path, mode_t mode); extern void dir_copy_files(const char *from_root, const char *to_root); +extern pgFile *pgFileNew(const char *path, bool omit_symlink); extern void pgFileDelete(pgFile *file); extern void pgFileFree(void *file); extern pg_crc32 pgFileGetCRC(pgFile *file);