From ebf0373f00a305c7dd08da347da8539d012bf61c Mon Sep 17 00:00:00 2001 From: Tudor Marcu Date: Thu, 22 Jun 2017 11:49:50 -0700 Subject: [PATCH] Add check_mix_exists() function Signed-off-by: Tudor Marcu --- src/globals.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/globals.c b/src/globals.c index c4d35506..ab3ebae1 100644 --- a/src/globals.c +++ b/src/globals.c @@ -173,6 +173,40 @@ void print_time_stats(timelist *head) } } +/* If the MIX_BUNDLES_DIR has any content then we can run through + * adding the mix data to the OS */ +bool check_mix_exists(void) +{ + DIR *dir; + struct dirent *entry; + char *fullpath; + int i; + + string_or_die(&fullpath, "%s%s", path_prefix, MIX_DIR); + + dir = opendir(fullpath); + if (dir == NULL) { + free(fullpath); + return false; + } + for(i = 0; i < 3; i++) { + entry = readdir(dir); + if (!entry) { + break; + } + if (!strcmp(entry->d_name, ".") || + !strcmp(entry->d_name, "..")) { + continue; + } + } + /* If more than /. & /.. exists, then at least one bundle exists */ + if (i > 2) { + return true; + } else { + return false; + } +} + int get_value_from_path(char **contents, const char *path, bool is_abs_path) { char line[LINE_MAX];