Skip to content

Commit 24a7a08

Browse files
committed
Code cleanup. Pass backup_catalog_path explicitly to functions that need it
1 parent c1e81ed commit 24a7a08

File tree

8 files changed

+25
-23
lines changed

8 files changed

+25
-23
lines changed

src/archive.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1046,7 +1046,7 @@ do_archive_get(InstanceConfig *instance, const char *prefetch_dir_arg,
10461046
join_path_components(absolute_wal_file_path, current_dir, wal_file_path);
10471047

10481048
/* full filepath to WAL file in archive directory.
1049-
* backup_path/wal/instance_name/000000010000000000000001 */
1049+
* $BACKUP_PATH/wal/instance_name/000000010000000000000001 */
10501050
join_path_components(backup_wal_file_path, instance->arclog_path, wal_file_name);
10511051

10521052
INSTR_TIME_SET_CURRENT(start_time);

src/backup.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ backup_stopbackup_callback(bool fatal, void *userdata)
8989

9090
/*
9191
* Take a backup of a single postgresql instance.
92-
* Move files from 'pgdata' to a subdirectory in 'backup_path'.
92+
* Move files from 'pgdata' to a subdirectory in backup catalog.
9393
*/
9494
static void
9595
do_backup_instance(PGconn *backup_conn, PGNodeInfo *nodeInfo, bool no_sync, bool backup_logs)

src/catalog.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -692,7 +692,7 @@ IsDir(const char *dirpath, const char *entry, fio_location location)
692692
* actual config of each instance.
693693
*/
694694
parray *
695-
catalog_get_instance_list(void)
695+
catalog_get_instance_list(char *backup_catalog_path)
696696
{
697697
char path[MAXPGPATH];
698698
DIR *dir;
@@ -702,7 +702,7 @@ catalog_get_instance_list(void)
702702
instances = parray_new();
703703

704704
/* open directory and list contents */
705-
join_path_components(path, backup_path, BACKUPS_DIR);
705+
join_path_components(path, backup_catalog_path, BACKUPS_DIR);
706706
dir = opendir(path);
707707
if (dir == NULL)
708708
elog(ERROR, "Cannot open directory \"%s\": %s",

src/init.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ do_init(char *backup_catalog_path)
4949
}
5050

5151
int
52-
do_add_instance(InstanceConfig *instance)
52+
do_add_instance(char *backup_catalog_path, InstanceConfig *instance)
5353
{
5454
char path[MAXPGPATH];
5555
char arclog_path_dir[MAXPGPATH];
@@ -66,14 +66,14 @@ do_add_instance(InstanceConfig *instance)
6666
instance->xlog_seg_size = get_xlog_seg_size(instance->pgdata);
6767

6868
/* Ensure that all root directories already exist */
69-
if (access(backup_path, F_OK) != 0)
70-
elog(ERROR, "Directory does not exist: '%s'", backup_path);
69+
if (access(backup_catalog_path, F_OK) != 0)
70+
elog(ERROR, "Directory does not exist: '%s'", backup_catalog_path);
7171

72-
join_path_components(path, backup_path, BACKUPS_DIR);
72+
join_path_components(path, backup_catalog_path, BACKUPS_DIR);
7373
if (access(path, F_OK) != 0)
7474
elog(ERROR, "Directory does not exist: '%s'", path);
7575

76-
join_path_components(arclog_path_dir, backup_path, "wal");
76+
join_path_components(arclog_path_dir, backup_catalog_path, "wal");
7777
if (access(arclog_path_dir, F_OK) != 0)
7878
elog(ERROR, "Directory does not exist: '%s'", arclog_path_dir);
7979

src/pg_probackup.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -743,7 +743,7 @@ main(int argc, char *argv[])
743743
wal_file_path, wal_file_name, batch_size, !no_validate_wal);
744744
break;
745745
case ADD_INSTANCE_CMD:
746-
return do_add_instance(&instance_config);
746+
return do_add_instance(backup_path, &instance_config);
747747
case DELETE_INSTANCE_CMD:
748748
return do_delete_instance();
749749
case INIT_CMD:
@@ -770,7 +770,7 @@ main(int argc, char *argv[])
770770
if (datname_exclude_list || datname_include_list)
771771
elog(ERROR, "You must specify parameter (-i, --backup-id) for partial validation");
772772

773-
return do_validate_all();
773+
return do_validate_all(backup_path);
774774
}
775775
else
776776
/* PITR validation and, optionally, partial validation */
@@ -779,7 +779,7 @@ main(int argc, char *argv[])
779779
restore_params,
780780
no_sync);
781781
case SHOW_CMD:
782-
return do_show(instance_name, current.backup_id, show_archive);
782+
return do_show(backup_path, instance_name, current.backup_id, show_archive);
783783
case DELETE_CMD:
784784
if (delete_expired && backup_id_string)
785785
elog(ERROR, "You cannot specify --delete-expired and (-i, --backup-id) options together");

src/pg_probackup.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -840,7 +840,7 @@ extern parray *read_database_map(pgBackup *backup);
840840

841841
/* in init.c */
842842
extern int do_init(char *backup_catalog_path);
843-
extern int do_add_instance(InstanceConfig *instance);
843+
extern int do_add_instance(char *backup_catalog_path, InstanceConfig *instance);
844844

845845
/* in archive.c */
846846
extern void do_archive_push(InstanceConfig *instance, char *wal_file_path,
@@ -856,7 +856,8 @@ extern void init_config(InstanceConfig *config, const char *instance_name);
856856
extern InstanceConfig *readInstanceConfigFile(const char *instance_name);
857857

858858
/* in show.c */
859-
extern int do_show(const char *instance_name, time_t requested_backup_id, bool show_archive);
859+
extern int do_show(char *backup_catalog_path, const char *instance_name,
860+
time_t requested_backup_id, bool show_archive);
860861

861862
/* in delete.c */
862863
extern void do_delete(time_t backup_id);
@@ -880,7 +881,7 @@ extern void help_command(ProbackupSubcmd const subcmd);
880881

881882
/* in validate.c */
882883
extern void pgBackupValidate(pgBackup* backup, pgRestoreParams *params);
883-
extern int do_validate_all(void);
884+
extern int do_validate_all(char *backup_catalog_path);
884885
extern int validate_one_page(Page page, BlockNumber absolute_blkno,
885886
XLogRecPtr stop_lsn, PageState *page_st,
886887
uint32 checksum_version);
@@ -906,7 +907,7 @@ extern bool lock_backup(pgBackup *backup, bool strict, bool exclusive);
906907
extern const char *pgBackupGetBackupMode(pgBackup *backup, bool show_color);
907908
extern void pgBackupGetBackupModeColor(pgBackup *backup, char *mode);
908909

909-
extern parray *catalog_get_instance_list(void);
910+
extern parray *catalog_get_instance_list(char *backup_catalog_path);
910911
extern parray *catalog_get_backup_list(const char *instance_name, time_t requested_backup_id);
911912
extern void catalog_lock_backup_list(parray *backup_list, int from_idx,
912913
int to_idx, bool strict, bool exclusive);

src/show.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ static int32 json_level = 0;
7575
* Entry point of pg_probackup SHOW subcommand.
7676
*/
7777
int
78-
do_show(const char *instance_name, time_t requested_backup_id, bool show_archive)
78+
do_show(char *backup_catalog_path, const char *instance_name,
79+
time_t requested_backup_id, bool show_archive)
7980
{
8081
int i;
8182

@@ -93,7 +94,7 @@ do_show(const char *instance_name, time_t requested_backup_id, bool show_archive
9394
*/
9495
if (instance_name == NULL)
9596
{
96-
parray *instances = catalog_get_instance_list();
97+
parray *instances = catalog_get_instance_list(backup_catalog_path);
9798

9899
show_instance_start();
99100
for (i = 0; i < parray_num(instances); i++)
@@ -104,7 +105,7 @@ do_show(const char *instance_name, time_t requested_backup_id, bool show_archive
104105
if (interrupted)
105106
elog(ERROR, "Interrupted during show");
106107

107-
sprintf(backup_instance_path, "%s/%s/%s", backup_path, BACKUPS_DIR, instance->name);
108+
sprintf(backup_instance_path, "%s/%s/%s", backup_catalog_path, BACKUPS_DIR, instance->name);
108109

109110
if (show_archive)
110111
show_instance_archive(instance);

src/validate.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ pgBackupValidateFiles(void *arg)
382382
* If --instance option was provided, validate only backups of this instance.
383383
*/
384384
int
385-
do_validate_all(void)
385+
do_validate_all(char *backup_catalog_path)
386386
{
387387
corrupted_backup_found = false;
388388
skipped_due_to_lock = false;
@@ -395,7 +395,7 @@ do_validate_all(void)
395395
struct dirent *dent;
396396

397397
/* open directory and list contents */
398-
join_path_components(path, backup_path, BACKUPS_DIR);
398+
join_path_components(path, backup_catalog_path, BACKUPS_DIR);
399399
dir = opendir(path);
400400
if (dir == NULL)
401401
elog(ERROR, "cannot open directory \"%s\": %s", path, strerror(errno));
@@ -425,8 +425,8 @@ do_validate_all(void)
425425
*/
426426
instance_name = dent->d_name;
427427
sprintf(backup_instance_path, "%s/%s/%s",
428-
backup_path, BACKUPS_DIR, instance_name);
429-
sprintf(arclog_path, "%s/%s/%s", backup_path, "wal", instance_name);
428+
backup_catalog_path, BACKUPS_DIR, instance_name);
429+
sprintf(arclog_path, "%s/%s/%s", backup_catalog_path, "wal", instance_name);
430430
join_path_components(conf_path, backup_instance_path,
431431
BACKUP_CATALOG_CONF_FILE);
432432
if (config_read_opt(conf_path, instance_options, ERROR, false,

0 commit comments

Comments
 (0)