diff --git a/src/init.c b/src/init.c index 1ab6dc0f..51e628f0 100644 --- a/src/init.c +++ b/src/init.c @@ -17,34 +17,34 @@ * Initialize backup catalog. */ int -do_init(void) +do_init(char *backup_catalog_path) { char path[MAXPGPATH]; char arclog_path_dir[MAXPGPATH]; int results; - results = pg_check_dir(backup_path); + results = pg_check_dir(backup_catalog_path); if (results == 4) /* exists and not empty*/ elog(ERROR, "backup catalog already exist and it's not empty"); else if (results == -1) /*trouble accessing directory*/ { int errno_tmp = errno; elog(ERROR, "cannot open backup catalog directory \"%s\": %s", - backup_path, strerror(errno_tmp)); + backup_catalog_path, strerror(errno_tmp)); } /* create backup catalog root directory */ - dir_create_dir(backup_path, DIR_PERMISSION, false); + dir_create_dir(backup_catalog_path, DIR_PERMISSION, false); /* create backup catalog data directory */ - join_path_components(path, backup_path, BACKUPS_DIR); + join_path_components(path, backup_catalog_path, BACKUPS_DIR); dir_create_dir(path, DIR_PERMISSION, false); /* create backup catalog wal directory */ - join_path_components(arclog_path_dir, backup_path, "wal"); + join_path_components(arclog_path_dir, backup_catalog_path, "wal"); dir_create_dir(arclog_path_dir, DIR_PERMISSION, false); - elog(INFO, "Backup catalog '%s' successfully inited", backup_path); + elog(INFO, "Backup catalog '%s' successfully inited", backup_catalog_path); return 0; } diff --git a/src/pg_probackup.c b/src/pg_probackup.c index 37d87230..5479f78c 100644 --- a/src/pg_probackup.c +++ b/src/pg_probackup.c @@ -2,6 +2,13 @@ * * pg_probackup.c: Backup/Recovery manager for PostgreSQL. * + * This is an entry point for the program. + * Parse command name and it's options, verify them and call a + * do_***() function that implements the command. + * + * Avoid using global variables in the code. + * Pass all needed information as funciton arguments. + * * Portions Copyright (c) 2009-2013, NIPPON TELEGRAPH AND TELEPHONE CORPORATION * Portions Copyright (c) 2015-2019, Postgres Professional * @@ -28,6 +35,7 @@ const char *PROGRAM_URL = "https://github.com/postgrespro/pg_probackup"; const char *PROGRAM_EMAIL = "https://github.com/postgrespro/pg_probackup/issues"; /* directory options */ +/* TODO make it local variable, pass as an argument to all commands that need it. */ char *backup_path = NULL; /* * path or to the data files in the backup catalog @@ -739,7 +747,7 @@ main(int argc, char *argv[]) case DELETE_INSTANCE_CMD: return do_delete_instance(); case INIT_CMD: - return do_init(); + return do_init(backup_path); case BACKUP_CMD: { current.stream = stream_wal; diff --git a/src/pg_probackup.h b/src/pg_probackup.h index 18bf87bb..b169b223 100644 --- a/src/pg_probackup.h +++ b/src/pg_probackup.h @@ -839,7 +839,7 @@ extern void merge_chain(parray *parent_chain, extern parray *read_database_map(pgBackup *backup); /* in init.c */ -extern int do_init(void); +extern int do_init(char *backup_catalog_path); extern int do_add_instance(InstanceConfig *instance); /* in archive.c */