mirror of
https://github.com/clearlinux/swupd-client.git
synced 2026-08-27 00:36:02 +00:00
Move function to set the path to the statedir
Moving the function to the appropriate statedir module. Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
This commit is contained in:
committed by
Castulo J. Martinez
parent
62bb6bd8a0
commit
cf263bbd07
Vendored
+3
-3
@@ -314,7 +314,7 @@ enum swupd_code third_party_set_repo(struct repo *repo, bool sigcheck)
|
||||
error("Unable to create the state directories for repository %s\n\n", repo->name);
|
||||
return SWUPD_COULDNT_CREATE_DIR;
|
||||
}
|
||||
set_state_dir(repo_state_dir);
|
||||
statedir_set_path(repo_state_dir);
|
||||
FREE(repo_state_dir);
|
||||
|
||||
return SWUPD_OK;
|
||||
@@ -379,7 +379,7 @@ static enum swupd_code third_party_find_bundle(const char *bundle, struct list *
|
||||
|
||||
clean_and_exit:
|
||||
set_path_prefix(globals_bkp.path_prefix);
|
||||
set_state_dir(globals_bkp.state_dir);
|
||||
statedir_set_path(globals_bkp.state_dir);
|
||||
set_content_url(globals_bkp.content_url);
|
||||
set_version_url(globals_bkp.version_url);
|
||||
|
||||
@@ -444,7 +444,7 @@ enum swupd_code third_party_run_operation(struct list *bundles, const char *repo
|
||||
/* return the global variables to the original values */
|
||||
next:
|
||||
set_path_prefix(globals_bkp.path_prefix);
|
||||
set_state_dir(globals_bkp.state_dir);
|
||||
statedir_set_path(globals_bkp.state_dir);
|
||||
set_content_url(globals_bkp.content_url);
|
||||
set_version_url(globals_bkp.version_url);
|
||||
}
|
||||
|
||||
+1
-1
@@ -929,7 +929,7 @@ enum swupd_code execute_verify_extra(extra_proc_fn_t post_verify_fn)
|
||||
bool invalid_bundle = false;
|
||||
|
||||
if (cmdline_option_statedir_cache != NULL) {
|
||||
ret = set_state_dir_cache(cmdline_option_statedir_cache);
|
||||
ret = statedir_dup_set_path(cmdline_option_statedir_cache);
|
||||
if (ret != true) {
|
||||
error("Failed to set statedir-cache\n");
|
||||
goto clean_args_and_exit;
|
||||
|
||||
+1
-60
@@ -193,65 +193,6 @@ static bool is_valid_integer_format(char *str)
|
||||
return true;
|
||||
}
|
||||
|
||||
/* Initializes the state_dir global variable. If the path parameter is not
|
||||
* NULL, state_dir will be set to its value. Otherwise, the value is the
|
||||
* build-time default (STATE_DIR).
|
||||
*/
|
||||
bool set_state_dir(char *path)
|
||||
{
|
||||
if (!path) {
|
||||
error("Statedir shouldn't be NULL\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (path[0] != '/') {
|
||||
error("State dir must be a full path starting with '/', not '%c'\n", path[0]);
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Prevent some disasters: since the state dir can be destroyed and
|
||||
* reconstructed, make sure we never set those by accident and nuke the
|
||||
* system. */
|
||||
if (!str_cmp(path, "/") || !str_cmp(path, "/var") || !str_cmp(path, "/usr")) {
|
||||
error("Refusing to use '%s' as a state dir because it might be erased first\n", path);
|
||||
return false;
|
||||
}
|
||||
|
||||
FREE(globals.state_dir);
|
||||
string_or_die(&globals.state_dir, "%s", path);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/* Sets the state_dir_cache global variable. If the path parameter is not
|
||||
* NULL, state_dir_cache will be set to its value.
|
||||
*/
|
||||
bool set_state_dir_cache(char *path)
|
||||
{
|
||||
if (!path) {
|
||||
error("Statedir-cache shouldn't be set to NULL\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (path[0] != '/') {
|
||||
error("Statedir-cache must be a full path starting with '/', not '%c'\n", path[0]);
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Prevent some disasters: since the statedir-cache can be destroyed and
|
||||
* reconstructed, make sure we never set those by accident and nuke the
|
||||
* system. */
|
||||
if (!str_cmp(path, "/") || !str_cmp(path, "/var") || !str_cmp(path, "/usr")) {
|
||||
error("Refusing to use '%s' as a statedir-cache because it might be erased first\n", path);
|
||||
return false;
|
||||
}
|
||||
|
||||
FREE(globals.state_dir_cache);
|
||||
string_or_die(&globals.state_dir_cache, "%s", path);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static void set_default_state_dir(void)
|
||||
{
|
||||
string_or_die(&globals.state_dir, "%s", STATE_DIR);
|
||||
@@ -595,7 +536,7 @@ static bool global_parse_opt(int opt, char *optarg)
|
||||
}
|
||||
return true;
|
||||
case 'S':
|
||||
if (!set_state_dir(optarg)) {
|
||||
if (!statedir_set_path(optarg)) {
|
||||
error("Invalid --statedir argument\n\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -95,10 +95,8 @@ void save_cmd(char **argv);
|
||||
|
||||
bool set_path_prefix(char *path);
|
||||
bool set_default_urls(void);
|
||||
bool set_state_dir_cache(char *path);
|
||||
void set_default_path_prefix(void);
|
||||
void set_content_url(char *url);
|
||||
bool set_state_dir(char *path);
|
||||
void set_version_url(char *url);
|
||||
void set_cert_path(char *path);
|
||||
|
||||
|
||||
@@ -172,3 +172,39 @@ int statedir_create_dirs(const char *path)
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static bool set_state_path(char** state, char *path)
|
||||
{
|
||||
if (!path) {
|
||||
error("Statedir shouldn't be NULL\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (path[0] != '/') {
|
||||
error("State dir must be a full path starting with '/', not '%c'\n", path[0]);
|
||||
return false;
|
||||
}
|
||||
|
||||
/* Prevent some disasters: since the state dir can be destroyed and
|
||||
* reconstructed, make sure we never set those by accident and nuke the
|
||||
* system. */
|
||||
if (!str_cmp(path, "/") || !str_cmp(path, "/var") || !str_cmp(path, "/usr")) {
|
||||
error("Refusing to use '%s' as a state dir because it might be erased first\n", path);
|
||||
return false;
|
||||
}
|
||||
|
||||
FREE(*state);
|
||||
*state = sys_path_join("%s", path);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool statedir_set_path(char *path)
|
||||
{
|
||||
return set_state_path(&globals.state_dir, path);
|
||||
}
|
||||
|
||||
bool statedir_dup_set_path(char *path)
|
||||
{
|
||||
return set_state_path(&globals.state_dir_cache, path);
|
||||
}
|
||||
|
||||
@@ -137,6 +137,20 @@ char *statedir_get_version(void);
|
||||
*/
|
||||
int statedir_create_dirs(const char *path);
|
||||
|
||||
/**
|
||||
* @brief Sets the path to the statedir.
|
||||
*
|
||||
* @param path The path of the statedir
|
||||
*/
|
||||
bool statedir_set_path(char *path);
|
||||
|
||||
/**
|
||||
* @brief Sets the path to the duplicate (cache) of the statedir.
|
||||
*
|
||||
* @param path The path of the statedir duplicate
|
||||
*/
|
||||
bool statedir_dup_set_path(char *path);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user