From: hyunho Date: Fri, 4 Sep 2020 06:54:17 +0000 (+0900) Subject: Use file name that contains path info X-Git-Tag: submit/tizen/20200908.020920~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6d33931f89333573d9ab8a6d60f1be5025a936c3;p=platform%2Fcore%2Fapi%2Fnotification.git Use file name that contains path info The temporary files which are generated by the DataProviderMaster, can be overrided if they have same file name but different hierarchy. For now, files have below hierarchy will be copied to the temporary folder with name a.jpg so that one file will override other file. Folder1 | |-a.jpg Folder2 | |-a.jpg To fix this problem, let's use following naming rule for the temporary files. _{folder name}_{file name} According to this naming rule, above example files' name will be _Folder1_a.jpg and _Folder2_a.jpg Change-Id: I8d19b1a7f9ee998da2e7da90a79bd645bf8b960c Signed-off-by: hyunho --- diff --git a/notification/src/notification_shared_file.c b/notification/src/notification_shared_file.c index c8bcfe6f..b7ce797a 100644 --- a/notification/src/notification_shared_file.c +++ b/notification/src/notification_shared_file.c @@ -75,6 +75,7 @@ typedef struct target_app_info { char *dbus_sender_name; } target_app_info_s; +static const char *__last_index_of(const char *path, const char *search); static bool __make_sharing_dir(const char *dir) { GFile *noti_dir = NULL; @@ -103,10 +104,12 @@ static bool __make_sharing_dir(const char *dir) } static char *__get_data_path_by_pkg_id(const char *pkg_id, - const char *file_name, uid_t uid) + const char *file_path, uid_t uid) { const char *path; - char dir[PATH_MAX]; + char dir[PATH_MAX * 2]; + char rel_file_path[PATH_MAX]; + const char *pkg_path; if (pkg_id == NULL) return NULL; @@ -118,13 +121,27 @@ static char *__get_data_path_by_pkg_id(const char *pkg_id, if (path == NULL) return NULL; - snprintf(dir, sizeof(dir), "%s/%s/%s", path, pkg_id, NOTI_PRIV_DATA_DIR); + pkg_path = __last_index_of(file_path, pkg_id); + if (pkg_path == NULL) { + ERR("Wrong file path : cannot find pkgid"); + return NULL; + } + + snprintf(rel_file_path, sizeof(rel_file_path), "%s", + pkg_path + strlen(pkg_id)); + + for (int i = 0; i < strlen(rel_file_path); i++) { + if (rel_file_path[i] == '/') + rel_file_path[i] = '_'; + } + snprintf(dir, sizeof(dir), "%s/%s/%s", + path, pkg_id, NOTI_PRIV_DATA_DIR); if (__make_sharing_dir(dir) == false) return NULL; snprintf(dir, sizeof(dir), "%s/%s/%s/%s", path, pkg_id, - NOTI_PRIV_DATA_DIR, file_name); + NOTI_PRIV_DATA_DIR, rel_file_path); return strdup(dir); } @@ -674,8 +691,7 @@ char *notification_check_file_path_is_private(const char *pkg_id, } if (__is_RO_file(smack_label)) - dst_path = __get_data_path_by_pkg_id(pkg_id, - __last_index_of(file_path, "/") + 1, uid); + dst_path = __get_data_path_by_pkg_id(pkg_id, file_path, uid); if (dst_path == NULL && __is_private_file(smack_label, pkg_id)) { dst_path = strdup(file_path);