From 51a5b15e09255d6c9bc4bd4a209b498a14f7b507 Mon Sep 17 00:00:00 2001 From: Sung-jae Park Date: Fri, 4 Jan 2013 21:34:06 +0900 Subject: Revise the spec file Change the package name of the web livebox provider. (From org.tizen.data-provider-webapp-slave to livebox.web-provider) Clear the files in the shared folder first before initiate the master. Add reader & always folder parse code from conf file. Change-Id: I10415faadda3dd267d728ce71b029abdb770964e --- src/conf.c | 26 ++++++++++++++++++++++++++ src/main.c | 9 +++++++++ src/util.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 86 insertions(+) (limited to 'src') diff --git a/src/conf.c b/src/conf.c index a86747c..f7e3cf7 100644 --- a/src/conf.c +++ b/src/conf.c @@ -64,6 +64,8 @@ HAPI struct conf g_conf = { .conf = "/opt/usr/live/%s/etc/%s.conf", .image = "/opt/usr/share/live_magazine/", .slave_log = "/opt/usr/share/live_magazine/log", + .reader = "/opt/usr/share/live_magazine/reader", + .always = "/opt/usr/share/live_magazine/always", .script = "/opt/usr/live/%s/res/script/%s.edj", .root = "/opt/usr/live/", .script_port = "/opt/usr/live/script_port/", @@ -245,6 +247,22 @@ static void db_path_handler(char *buffer) DbgPrint("DB Path: %s\n", g_conf.path.db); } +static void reader_path_handler(char *buffer) +{ + g_conf.path.reader = strdup(buffer); + if (!g_conf.path.reader) + ErrPrint("Heap: %s\n", strerror(errno)); + DbgPrint("Reader Path: %s\n", g_conf.path.reader); +} + +static void always_path_handler(char *buffer) +{ + g_conf.path.always = strdup(buffer); + if (!g_conf.path.always) + ErrPrint("Heap: %s\n", strerror(errno)); + DbgPrint("Always Path: %s\n", g_conf.path.always); +} + static void log_path_handler(char *buffer) { g_conf.path.slave_log = strdup(buffer); @@ -378,6 +396,14 @@ HAPI int conf_loader(void) .name = "log_path", .handler = log_path_handler, }, + { + .name = "reader_path", + .handler = reader_path_handler, + }, + { + .name = "always_path", + .handler = always_path_handler, + }, { .name = "share_path", .handler = share_path_handler, diff --git a/src/main.c b/src/main.c index 7e8efd2..32538bd 100644 --- a/src/main.c +++ b/src/main.c @@ -226,6 +226,15 @@ int main(int argc, char *argv[]) conf_loader(); + /*! + * \note + * Clear old contents files before start the master provider. + */ + (void)util_unlink_files(ALWAYS_PATH); + (void)util_unlink_files(READER_PATH); + (void)util_unlink_files(IMAGE_PATH); + (void)util_unlink_files(SLAVE_LOG_PATH); + script_init(); app_create(); diff --git a/src/util.c b/src/util.c index 48129b1..13c5ca9 100644 --- a/src/util.c +++ b/src/util.c @@ -21,6 +21,8 @@ #include #include #include +#include +#include #include #include @@ -411,4 +413,53 @@ HAPI char *util_get_file_kept_in_safe(const char *id) return new_path; } +HAPI int util_unlink_files(const char *folder) +{ + struct stat info; + DIR *handle; + struct dirent *entry; + char *abspath; + int len; + + if (lstat(folder, &info) < 0) { + ErrPrint("Error: %s\n", strerror(errno)); + return -EIO; + } + + if (!S_ISDIR(info.st_mode)) { + ErrPrint("Error: %s is not a folder", folder); + return -EINVAL; + } + + handle = opendir(folder); + if (!handle) { + ErrPrint("Error: %s\n", strerror(errno)); + return -EIO; + } + + while ((entry = readdir(handle))) { + if (!strcmp(entry->d_name, ".")) + continue; + + if (!strcmp(entry->d_name, "..")) + continue; + + len = strlen(folder) + strlen(entry->d_name) + 3; + abspath = calloc(1, len); + if (!abspath) { + ErrPrint("Heap: %s\n", strerror(errno)); + continue; + } + snprintf(abspath, len - 1, "%s/%s", folder, entry->d_name); + + if (unlink(abspath) < 0) + DbgPrint("unlink: %s - %s\n", abspath, strerror(errno)); + + free(abspath); + } + + closedir(handle); + return 0; +} + /* End of a file */ -- cgit v1.2.3