From c244d36be318dd1cbba063644b4dbca665dcc22a Mon Sep 17 00:00:00 2001 From: Mario Alfredo Carrillo Arevalo Date: Fri, 13 Jan 2017 12:04:01 -0600 Subject: [PATCH] Add function that reads local installed bundles This function reads installed bundles from local standard directory and store them in a list pointer passed as argument, this function is the base for functionality as listing installed bundles to user. Signed-off-by: Mario Alfredo Carrillo Arevalo --- include/swupd.h | 1 + src/bundle.c | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/include/swupd.h b/include/swupd.h index b2e3fb5b..2b902675 100644 --- a/include/swupd.h +++ b/include/swupd.h @@ -310,6 +310,7 @@ extern int remove_bundle(const char *bundle_name); extern int list_installable_bundles(); extern int install_bundles_frontend(char **bundles); extern int add_subscriptions(struct list *bundles, struct list **subs, int current_version, struct manifest *mom, int recursion); +void read_local_bundles(struct list **list_bundles); /* telemetry.c */ typedef enum telem_prio_t { diff --git a/src/bundle.c b/src/bundle.c index 0aab6e8e..97d9d018 100644 --- a/src/bundle.c +++ b/src/bundle.c @@ -589,3 +589,33 @@ clean_and_exit: return ret; } + +/* + * This function will read /usr/share/clear/bundles/ + * in order to get the bundle names, these will be + * saved in a list. + */ +void read_local_bundles(struct list **list_bundles) +{ + char *path = NULL; + DIR *dir; + struct dirent *ent; + + string_or_die(&path, "%s/%s", path_prefix, BUNDLES_DIR); + + dir = opendir(path); + if (dir) { + while ((ent = readdir(dir))) { + if ((strcmp(ent->d_name, ".") == 0) || + (strcmp(ent->d_name, "..") == 0)) { + continue; + } + + *list_bundles = list_append_data(*list_bundles, ent->d_name); + } + + closedir(dir); + } + + free(path); +}