From ca2601efc7af8c653d4e92ac8a7f8ec306afcf81 Mon Sep 17 00:00:00 2001 From: Castulo Martinez Date: Thu, 7 May 2020 10:00:17 -0700 Subject: [PATCH] Consolidate functions to track bundles Currently we have two functions to track bundles, bundles should always be tracked in the same location, if there is an exception to this rule then it should be handled separately. Signed-off-by: Castulo Martinez --- src/cmds/verify.c | 9 ++++++++- src/swupd_lib/bundle.c | 15 +++------------ src/swupd_lib/bundle.h | 15 ++------------- 3 files changed, 13 insertions(+), 26 deletions(-) diff --git a/src/cmds/verify.c b/src/cmds/verify.c index 1f3cb4bb..be6f24f3 100644 --- a/src/cmds/verify.c +++ b/src/cmds/verify.c @@ -1285,7 +1285,14 @@ brick_the_system_and_clean_curl: /* make sure the bundle was in fact valid and will * be installed before creating the tracking file */ if (list_search(bundles_subs, bundle, cmp_sub_component_string)) { - track_bundle_in_statedir(bundle, new_os_statedir); + char *tracking_file = sys_path_join("%s/bundles/%s", new_os_statedir, bundle); + int fd = open(tracking_file, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR); + if (fd) { + close(fd); + } else { + debug("The tracking file %s failed to be created\n", tracking_file); + } + FREE(tracking_file); } } FREE(new_os_statedir); diff --git a/src/swupd_lib/bundle.c b/src/swupd_lib/bundle.c index a92eed63..5515be5a 100644 --- a/src/swupd_lib/bundle.c +++ b/src/swupd_lib/bundle.c @@ -208,17 +208,14 @@ int required_by(struct list **reqd_by, const char *bundle_name, struct manifest return count; } -void track_bundle_in_statedir(const char *bundle_name, const char *state_dir) +void track_bundle(const char *bundle_name) { int ret = 0; int fd; - char *tracking_dir; char *tracking_file; - tracking_dir = sys_path_join("%s/%s", state_dir, "bundles"); - tracking_file = sys_path_join("%s/%s", tracking_dir, bundle_name); - /* touch a tracking file */ + tracking_file = statedir_get_tracking_file(bundle_name); fd = open(tracking_file, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR); if (fd < 0) { ret = -1; @@ -228,17 +225,11 @@ void track_bundle_in_statedir(const char *bundle_name, const char *state_dir) out: if (ret) { - debug("Issue creating tracking file in %s for %s\n", tracking_dir, bundle_name); + debug("Issue creating tracking file %s for %s\n", tracking_file, bundle_name); } - FREE(tracking_dir); FREE(tracking_file); } -void track_bundle(const char *bundle_name) -{ - track_bundle_in_statedir(bundle_name, globals.state_dir); -} - static char *get_bundles_dir(void) { return sys_path_join("%s/%s", globals.path_prefix, BUNDLES_DIR); diff --git a/src/swupd_lib/bundle.h b/src/swupd_lib/bundle.h index 13ed7359..d3205c9f 100644 --- a/src/swupd_lib/bundle.h +++ b/src/swupd_lib/bundle.h @@ -43,22 +43,11 @@ bool is_tracked_bundle(const char *bundle_name); int required_by(struct list **reqd_by, const char *bundle_name, struct manifest *mom, int recursion, struct list *exclusions, char *msg, bool include_optional); /** - * @brief Creates a tracking file in the tracking directory within the - * specified state directory. - * If there are no tracked files in that directory (directory is empty - * or does not exist), copy the tracking directory at - * path_prefix/usr/share/clear/bundles to the tracking directory to - * initiate the tracking files. + * @brief Creates a tracking file in the tracking directory. + * This function does not return an error code because weird state in this * directory must be handled gracefully whenever encountered. * @param bundle_name The name of the bundle. - * @param state_dir The path to the state directory. - */ -void track_bundle_in_statedir(const char *bundle_name, const char *state_dir); - -/** - * @brief Similar to track_bundle_in_statedir() but uses the global state_dir. - * @param bundle_name The name of the bundle. */ void track_bundle(const char *bundle_name);