From 4bb9b775bf49132fb5206a9c39f727c1774ff0ce Mon Sep 17 00:00:00 2001 From: Sergey Cherkashin <4erkashin@list.ru> Date: Tue, 27 Nov 2018 17:57:43 +0300 Subject: [PATCH] Remove flag is_extra, use extra_dir_num instead --- src/backup.c | 2 +- src/dir.c | 15 +++++---------- src/pg_probackup.h | 1 - src/restore.c | 19 ++++++++++--------- 4 files changed, 16 insertions(+), 21 deletions(-) diff --git a/src/backup.c b/src/backup.c index 9f2f1b6f..18e7d635 100644 --- a/src/backup.c +++ b/src/backup.c @@ -702,7 +702,7 @@ do_backup_instance(void) char *dir_name; if (!is_remote_backup) - if (file->is_extra) + if (file->extra_dir_num) dir_name = GetRelativePath(file->path, file->extradir); else dir_name = GetRelativePath(file->path, pgdata); diff --git a/src/dir.c b/src/dir.c index 8b1c193f..890355dd 100644 --- a/src/dir.c +++ b/src/dir.c @@ -175,7 +175,6 @@ pgFileNew(const char *path, bool omit_symlink, int extra_dir_num) file = pgFileInit(path); file->size = st.st_size; file->mode = st.st_mode; - file->is_extra = extra_dir_num > 0; file->extra_dir_num = extra_dir_num; file->extradir = NULL; @@ -228,6 +227,7 @@ pgFileInit(const char *path) /* Number of blocks readed during backup */ file->n_blocks = BLOCKNUM_INVALID; file->compress_alg = NOT_DEFINED_COMPRESS; + file->extra_dir_num = 0; return file; } @@ -1198,18 +1198,16 @@ print_file_list(FILE *out, const parray *files, const char *root) /* omit root directory portion */ if (root && strstr(path, root) == path) path = GetRelativePath(path, root); - else if(file->is_extra) + else if(file->extra_dir_num) path = GetRelativePath(path, file->extradir); fprintf(out, "{\"path\":\"%s\", \"size\":\"" INT64_FORMAT "\", " "\"mode\":\"%u\", \"is_datafile\":\"%u\", " "\"is_cfs\":\"%u\", \"crc\":\"%u\", " - "\"compress_alg\":\"%s\", \"is_extra\":\"%u\"" - ", \"extra_dir_num\":\"%u\"", + "\"compress_alg\":\"%s\", \"extra_dir_num\":\"%u\"", path, file->write_size, file->mode, file->is_datafile ? 1 : 0, file->is_cfs ? 1 : 0, file->crc, - deparse_compress_alg(file->compress_alg), - file->is_extra ? 1 : 0, file->extra_dir_num); + deparse_compress_alg(file->compress_alg), file->extra_dir_num); if (file->extradir) fprintf(out, ",\"extradir\":\"%s\"", file->extradir); @@ -1402,7 +1400,6 @@ dir_read_file_list(const char *root, const char *extra_path, const char *file_tx mode, /* bit length of mode_t depends on platforms */ is_datafile, is_cfs, - is_extra, extra_dir_num, crc, segno, @@ -1416,7 +1413,6 @@ dir_read_file_list(const char *root, const char *extra_path, const char *file_tx get_control_value(buf, "is_cfs", NULL, &is_cfs, false); get_control_value(buf, "crc", NULL, &crc, true); get_control_value(buf, "compress_alg", compress_alg_string, NULL, false); - get_control_value(buf, "is_extra", NULL, &is_extra, false); get_control_value(buf, "extra_dir_num", NULL, &extra_dir_num, false); if (root) @@ -1433,8 +1429,7 @@ dir_read_file_list(const char *root, const char *extra_path, const char *file_tx file = pgFileInit(filepath); - file->is_extra = is_extra ? true : false; - if (is_extra) + if (extra_dir_num) { get_control_value(buf, "extradir", extradir_str, NULL, true); file->extradir = pgut_strdup(extradir_str); diff --git a/src/pg_probackup.h b/src/pg_probackup.h index 83cbbb2c..2ad13b2a 100644 --- a/src/pg_probackup.h +++ b/src/pg_probackup.h @@ -116,7 +116,6 @@ typedef struct pgFile int n_blocks; /* size of the file in blocks, readed during DELTA backup */ bool is_cfs; /* Flag to distinguish files compressed by CFS*/ bool is_database; - bool is_extra; bool extra_dir_num; /* Number of extra directory. 0 if not extra */ char *extradir; /* File from extra directory */ bool exists_in_prev; /* Mark files, both data and regular, that exists in previous backup */ diff --git a/src/restore.c b/src/restore.c index c4e7c1a6..de1ba4e5 100644 --- a/src/restore.c +++ b/src/restore.c @@ -478,17 +478,18 @@ restore_backup(pgBackup *backup) char dirpath[MAXPGPATH]; char *dir_name; - if (file->is_extra) - dir_name = GetRelativePath(file->path, extra_path); - else - dir_name = GetRelativePath(file->path, database_path); - - elog(VERBOSE, "Create directory \"%s\" NAME %s", dir_name, file->name); - - if (file->is_extra) + if (file->extra_dir_num) + { join_path_components(dirpath, file->extradir, dir_name); + elog(VERBOSE, "Create directory \"%s\" NAME %s", dir_name, file->name); + dir_name = GetRelativePath(file->path, extra_path); + } else + { + dir_name = GetRelativePath(file->path, database_path); + elog(VERBOSE, "Create directory \"%s\" NAME %s", dir_name, file->name); join_path_components(dirpath, pgdata, dir_name); + } dir_create_dir(dirpath, DIR_PERMISSION); } @@ -659,7 +660,7 @@ restore_files(void *arg) false, parse_program_version(arguments->backup->program_version)); } - else if (file->is_extra) + else if (file->extra_dir_num) copy_file(from_root, file->extradir, file); else copy_file(from_root, pgdata, file);