Update image/desc filename management code
authorSung-jae Park <nicesj.park@samsung.com>
Wed, 4 Sep 2013 04:43:06 +0000 (13:43 +0900)
committerSung-jae Park <nicesj.park@samsung.com>
Wed, 4 Sep 2013 04:43:06 +0000 (13:43 +0900)
Every update will change the image/desc filename.

Change-Id: Iaeb2e9ca8cfd8419f39b68e9be4c429b2838cfb0

include/livebox_internal.h
packaging/liblivebox-viewer.spec
src/client.c
src/livebox.c

index 9744c1a..cbbefbc 100644 (file)
@@ -45,6 +45,7 @@ extern struct livebox *lb_ref(struct livebox *handler);
 extern struct livebox *lb_unref(struct livebox *handler);
 extern int lb_send_delete(struct livebox *handler, ret_cb_t cb, void *data);
 extern int lb_delete_all(void);
+extern void lb_set_filename(struct livebox *handler, const char *filename);
 
 enum lb_type { /*!< Must have to be sync with data-provider-master */
        _LB_TYPE_NONE = 0x0,
index f26a2dd..f31055d 100644 (file)
@@ -1,6 +1,6 @@
 Name: liblivebox-viewer
 Summary: Library for developing the application.
-Version: 0.14.1
+Version: 0.14.2
 Release: 1
 Group: HomeTF/Livebox
 License: Flora License
index ff64fa3..c94b92e 100644 (file)
@@ -460,17 +460,19 @@ static struct packet *master_lb_updated(pid_t pid, int handle, const struct pack
        const char *fbfile;
        const char *content;
        const char *title;
+       const char *safe_file;
        struct livebox *handler;
        int lb_w;
        int lb_h;
        double priority;
        int ret;
 
-       ret = packet_get(packet, "sssiidss",
+       ret = packet_get(packet, "sssiidsss",
                                &pkgname, &id,
                                &fbfile, &lb_w, &lb_h,
-                               &priority, &content, &title);
-       if (ret != 8) {
+                               &priority, &content, &title,
+                               &safe_file);
+       if (ret != 9) {
                ErrPrint("Invalid argument\n");
                goto out;
        }
@@ -496,6 +498,7 @@ static struct packet *master_lb_updated(pid_t pid, int handle, const struct pack
        lb_set_content(handler, content);
        lb_set_title(handler, title);
        lb_set_size(handler, lb_w, lb_h);
+       lb_set_filename(handler, safe_file);
 
        if (lb_text_lb(handler)) {
                (void)parse_desc(handler, livebox_filename(handler), 0);
index 27d1290..0b5ddcd 100644 (file)
@@ -19,6 +19,7 @@
 #include <stdlib.h> /* malloc */
 #include <string.h> /* strdup */
 #include <math.h>
+#include <unistd.h>
 
 #include <aul.h>
 #include <dlog.h>
@@ -2678,49 +2679,6 @@ struct livebox *lb_find_livebox_by_timestamp(double timestamp)
        return NULL;
 }
 
-static inline char *get_file_kept_in_safe(const char *id)
-{
-       const char *path;
-       char *new_path;
-       int len;
-       int base_idx;
-
-       path = util_uri_to_path(id);
-       if (!path) {
-               ErrPrint("Invalid URI(%s)\n", id);
-               return NULL;
-       }
-
-       /*!
-        * \TODO: REMOVE ME
-        */
-       if (s_info.prevent_overwrite) {
-               new_path = strdup(path);
-               if (!new_path) {
-                       ErrPrint("Heap: %s\n", strerror(errno));
-               }
-
-               return new_path;
-       }
-
-
-       len = strlen(path);
-       base_idx = len - 1;
-
-       while (base_idx > 0 && path[base_idx] != '/') base_idx--;
-       base_idx += (path[base_idx] == '/');
-
-       new_path = malloc(len + 10);
-       if (!new_path) {
-               ErrPrint("Heap: %s\n", strerror(errno));
-               return NULL;
-       }
-
-       strncpy(new_path, path, base_idx);
-       snprintf(new_path + base_idx, len + 10 - base_idx, "reader/%s", path + base_idx);
-       return new_path;
-}
-
 struct livebox *lb_new_livebox(const char *pkgname, const char *id, double timestamp)
 {
        struct livebox *handler;
@@ -2746,14 +2704,6 @@ struct livebox *lb_new_livebox(const char *pkgname, const char *id, double times
                return NULL;
        }
 
-       handler->filename = get_file_kept_in_safe(id);
-       if (!handler->filename) {
-               handler->filename = strdup(util_uri_to_path(id));
-               if (!handler->filename) {
-                       ErrPrint("Error: %s\n", strerror(errno));
-               }
-       }
-
        handler->timestamp = timestamp;
        handler->lb.type = _LB_TYPE_FILE;
        handler->pd.type = _PD_TYPE_SCRIPT;
@@ -2847,17 +2797,22 @@ void lb_set_id(struct livebox *handler, const char *id)
        if (!handler->id) {
                ErrPrint("Error: %s\n", strerror(errno));
        }
+}
 
+void lb_set_filename(struct livebox *handler, const char *filename)
+{
        if (handler->filename) {
+               if (unlink(handler->filename) < 0) {
+                       ErrPrint("unlink: %s\n", strerror(errno));
+               }
+
                free(handler->filename);
        }
 
-       handler->filename = get_file_kept_in_safe(id);
+       handler->filename = strdup(filename);
        if (!handler->filename) {
-               handler->filename = strdup(util_uri_to_path(id));
-               if (!handler->filename) {
-                       ErrPrint("Error: %s\n", strerror(errno));
-               }
+               ErrPrint("Heap: %s\n", strerror(errno));
+               return;
        }
 }
 
@@ -3063,7 +3018,7 @@ struct livebox *lb_unref(struct livebox *handler)
        }
 
        if (handler->filename) {
-               util_unlink(handler->filename);
+               (void)util_unlink(handler->filename);
        }
 
        dlist_remove_data(s_info.livebox_list, handler);