Use file name that contains path info 40/243240/4
authorhyunho <hhstark.kang@samsung.com>
Fri, 4 Sep 2020 06:54:17 +0000 (15:54 +0900)
committerhyunho <hhstark.kang@samsung.com>
Mon, 7 Sep 2020 02:30:12 +0000 (11:30 +0900)
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 <hhstark.kang@samsung.com>
notification/src/notification_shared_file.c

index c8bcfe6..b7ce797 100644 (file)
@@ -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);