mirror of
https://github.com/clearlinux/swupd-client.git
synced 2026-09-08 14:42:02 +00:00
Function for setting a 3rd-party repo to be used
This commit adds a function that will set up a 3rd-party repo to be used so we can reuse the existing code for 3rd-party repos. Signed-off-by: Castulo Martinez <castulo.martinez@intel.com>
This commit is contained in:
committed by
Castulo J. Martinez
parent
184f0b9c22
commit
34380ee3eb
@@ -227,4 +227,29 @@ exit:
|
||||
list_free_list_and_data(repos, repo_free_data);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int third_party_set_repo(const char *state_dir, const char *path_prefix, struct repo *repo)
|
||||
{
|
||||
char *repo_state_dir;
|
||||
char *repo_path_prefix;
|
||||
|
||||
set_content_url(repo->url);
|
||||
|
||||
string_or_die(&repo_path_prefix, "%s/opt/3rd_party/%s", path_prefix, repo->name);
|
||||
set_path_prefix(repo_path_prefix);
|
||||
free_string(&repo_path_prefix);
|
||||
|
||||
/* make sure there are state directories for the 3rd-party
|
||||
* repo if not there already */
|
||||
string_or_die(&repo_state_dir, "%s/3rd_party/%s", state_dir, repo->name);
|
||||
if (create_state_dirs(repo_state_dir)) {
|
||||
free_string(&repo_state_dir);
|
||||
return -1;
|
||||
}
|
||||
set_state_dir(repo_state_dir);
|
||||
free_string(&repo_state_dir);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -63,6 +63,16 @@ int third_party_add_repo(const char *repo_name, const char *repo_url);
|
||||
*/
|
||||
int third_party_remove_repo(char *repo_name);
|
||||
|
||||
/**
|
||||
* @brief This function sets up swupd to use a specific 3rd-party repo.
|
||||
*
|
||||
* @param state_dir the original state directory of the system
|
||||
* @param path_prefix the original path prefix of the system
|
||||
*
|
||||
* @returns 0 on success, -1 on any failure
|
||||
*/
|
||||
int third_party_set_repo(const char *state_dir, const char *path_prefix, struct repo *repo);
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
+2
-2
@@ -76,7 +76,7 @@ static void set_json_format(bool on)
|
||||
}
|
||||
|
||||
/* Sets the content_url global variable */
|
||||
static void set_content_url(char *url)
|
||||
void set_content_url(char *url)
|
||||
{
|
||||
if (globals.content_url) {
|
||||
free_string(&globals.content_url);
|
||||
@@ -193,7 +193,7 @@ static bool is_valid_integer_format(char *str)
|
||||
* NULL, state_dir will be set to its value. Otherwise, the value is the
|
||||
* build-time default (STATE_DIR).
|
||||
*/
|
||||
static bool set_state_dir(char *path)
|
||||
bool set_state_dir(char *path)
|
||||
{
|
||||
if (!path) {
|
||||
error("Statedir shouldn't be NULL\n");
|
||||
|
||||
@@ -81,6 +81,8 @@ 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);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
+11
-2
@@ -188,12 +188,20 @@ static bool validate_tracking_dir(const char *state_dir)
|
||||
* user installed themselves just copy the entire system tracking directory
|
||||
* into the state tracking directory. */
|
||||
if (!is_populated_dir(tracking_dir)) {
|
||||
src = sys_path_join(globals.path_prefix, "/usr/share/clear/bundles");
|
||||
|
||||
if (!sys_file_exists(src)) {
|
||||
/* there is no bundles directory to copy from */
|
||||
free_string(&src);
|
||||
free_string(&tracking_dir);
|
||||
return false;
|
||||
}
|
||||
|
||||
ret = rm_rf(tracking_dir);
|
||||
if (ret) {
|
||||
goto out;
|
||||
}
|
||||
|
||||
src = sys_path_join(globals.path_prefix, "/usr/share/clear/bundles");
|
||||
/* at the point this function is called <bundle_name> is already
|
||||
* installed on the system and therefore has a tracking file under
|
||||
* /usr/share/clear/bundles. A simple cp -a of that directory will
|
||||
@@ -233,7 +241,7 @@ int create_state_dirs(const char *state_dir_path)
|
||||
|
||||
// check for existence
|
||||
if (ensure_root_owned_dir(state_dir_path)) {
|
||||
//state dir doesn't exist
|
||||
// state dir doesn't exist
|
||||
if (mkdir_p(state_dir_path) != 0 || chmod(state_dir_path, S_IRWXU) != 0) {
|
||||
error("failed to create %s\n", state_dir_path);
|
||||
return -1;
|
||||
@@ -247,6 +255,7 @@ int create_state_dirs(const char *state_dir_path)
|
||||
ret = mkdir(dir, S_IRWXU);
|
||||
if (ret) {
|
||||
error("failed to create %s\n", dir);
|
||||
free_string(&dir);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user