From 2ea8e512f793cbcf18fa5f67812081712d558058 Mon Sep 17 00:00:00 2001 From: Sung-jae Park Date: Thu, 29 Aug 2013 15:09:42 +0900 Subject: [PATCH] Use the uniq desc filename. To prevent from overwriting requested data if the request is duplicated. Change-Id: I0c71c439a8e15d16b1f56bbd484dcb789cf136ba --- lib/src/icon.c | 16 ++++++++++++++-- packaging/libshortcut.spec | 2 +- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/lib/src/icon.c b/lib/src/icon.c index e129c3a..be50f2c 100644 --- a/lib/src/icon.c +++ b/lib/src/icon.c @@ -14,6 +14,7 @@ * limitations under the License. * */ +#include #include #include #include @@ -670,6 +671,7 @@ EAPI int shortcut_icon_request_send(struct shortcut_icon *handle, int size_type, struct packet *packet; struct request_item *item; char *filename; + struct timeval tv; int len; if (!handle || handle->state != CREATED) { @@ -685,14 +687,24 @@ EAPI int shortcut_icon_request_send(struct shortcut_icon *handle, int size_type, group = DEFAULT_ICON_GROUP; } - len = strlen(outfile) + strlen(".desc") + 1; + len = strlen(outfile) + strlen(".desc") + 1 + 30; /* 30 == strlen(tv.tv_sec) + strlen(tv.tv_usec) + 10 (reserved) */ filename = malloc(len); if (!filename) { ErrPrint("Heap: %s\n", strerror(errno)); return -ENOMEM; } - snprintf(filename, len, "%s.desc", outfile); + if (gettimeofday(&tv, NULL) != 0) { + ErrPrint("gettimeofday: %s\n", strerror(errno)); + tv.tv_sec = rand(); + tv.tv_usec = rand(); + } + + ret = snprintf(filename, len, "%s.%lu.%lu.desc", outfile, tv.tv_sec, tv.tv_usec); + if (ret < 0) { + ErrPrint("snprintf: %s\n", strerror(errno)); + goto out; + } ret = shortcut_icon_desc_save(handle->desc, filename); if (ret < 0) { diff --git a/packaging/libshortcut.spec b/packaging/libshortcut.spec index b68ebf6..e5619c6 100644 --- a/packaging/libshortcut.spec +++ b/packaging/libshortcut.spec @@ -1,6 +1,6 @@ Name: libshortcut Summary: Shortcut add feature supporting library -Version: 0.6.6 +Version: 0.6.7 Release: 0 Group: HomeTF/Framework License: Apache License -- 2.7.4