Skip to content

Commit c1e81ed

Browse files
committed
Code cleanup. Start removing global variables in pg_probackup.c
1 parent da2c49d commit c1e81ed

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

src/init.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,34 +17,34 @@
1717
* Initialize backup catalog.
1818
*/
1919
int
20-
do_init(void)
20+
do_init(char *backup_catalog_path)
2121
{
2222
char path[MAXPGPATH];
2323
char arclog_path_dir[MAXPGPATH];
2424
int results;
2525

26-
results = pg_check_dir(backup_path);
26+
results = pg_check_dir(backup_catalog_path);
2727
if (results == 4) /* exists and not empty*/
2828
elog(ERROR, "backup catalog already exist and it's not empty");
2929
else if (results == -1) /*trouble accessing directory*/
3030
{
3131
int errno_tmp = errno;
3232
elog(ERROR, "cannot open backup catalog directory \"%s\": %s",
33-
backup_path, strerror(errno_tmp));
33+
backup_catalog_path, strerror(errno_tmp));
3434
}
3535

3636
/* create backup catalog root directory */
37-
dir_create_dir(backup_path, DIR_PERMISSION, false);
37+
dir_create_dir(backup_catalog_path, DIR_PERMISSION, false);
3838

3939
/* create backup catalog data directory */
40-
join_path_components(path, backup_path, BACKUPS_DIR);
40+
join_path_components(path, backup_catalog_path, BACKUPS_DIR);
4141
dir_create_dir(path, DIR_PERMISSION, false);
4242

4343
/* create backup catalog wal directory */
44-
join_path_components(arclog_path_dir, backup_path, "wal");
44+
join_path_components(arclog_path_dir, backup_catalog_path, "wal");
4545
dir_create_dir(arclog_path_dir, DIR_PERMISSION, false);
4646

47-
elog(INFO, "Backup catalog '%s' successfully inited", backup_path);
47+
elog(INFO, "Backup catalog '%s' successfully inited", backup_catalog_path);
4848
return 0;
4949
}
5050

src/pg_probackup.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22
*
33
* pg_probackup.c: Backup/Recovery manager for PostgreSQL.
44
*
5+
* This is an entry point for the program.
6+
* Parse command name and it's options, verify them and call a
7+
* do_***() function that implements the command.
8+
*
9+
* Avoid using global variables in the code.
10+
* Pass all needed information as funciton arguments.
11+
*
512
* Portions Copyright (c) 2009-2013, NIPPON TELEGRAPH AND TELEPHONE CORPORATION
613
* Portions Copyright (c) 2015-2019, Postgres Professional
714
*
@@ -28,6 +35,7 @@ const char *PROGRAM_URL = "https://github.com/postgrespro/pg_probackup";
2835
const char *PROGRAM_EMAIL = "https://github.com/postgrespro/pg_probackup/issues";
2936

3037
/* directory options */
38+
/* TODO make it local variable, pass as an argument to all commands that need it. */
3139
char *backup_path = NULL;
3240
/*
3341
* path or to the data files in the backup catalog
@@ -739,7 +747,7 @@ main(int argc, char *argv[])
739747
case DELETE_INSTANCE_CMD:
740748
return do_delete_instance();
741749
case INIT_CMD:
742-
return do_init();
750+
return do_init(backup_path);
743751
case BACKUP_CMD:
744752
{
745753
current.stream = stream_wal;

src/pg_probackup.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -839,7 +839,7 @@ extern void merge_chain(parray *parent_chain,
839839
extern parray *read_database_map(pgBackup *backup);
840840

841841
/* in init.c */
842-
extern int do_init(void);
842+
extern int do_init(char *backup_catalog_path);
843843
extern int do_add_instance(InstanceConfig *instance);
844844

845845
/* in archive.c */

0 commit comments

Comments
 (0)