Add function to trim the path 99/172299/1 accepted/tizen/unified/20180314.062138 submit/tizen/20180313.065351
authorMinje Ahn <minje.ahn@samsung.com>
Tue, 13 Mar 2018 06:44:06 +0000 (15:44 +0900)
committerMinje Ahn <minje.ahn@samsung.com>
Tue, 13 Mar 2018 06:44:06 +0000 (15:44 +0900)
Change-Id: I6fa4bb11965eb86ae0b0ddf48e6c9ea363fcb23a
Signed-off-by: Minje Ahn <minje.ahn@samsung.com>
include/media_util_private.h
include_product/media_util_private.h
src/media_content.c
src/media_util_private.c

index 89b95eb..5db2d36 100755 (executable)
@@ -31,6 +31,7 @@ extern "C" {
  */
 bool _media_util_check_support_media_type(const char *path);
 int _media_util_check_file_exist(const char *path);
+void _media_util_trim_path(const char *input_path, char **output_path);
 int _media_util_check_ignore_file(const char *path, bool *ignore);
 int _media_util_check_ignore_dir(const char *dir_path, bool *ignore);
 int _media_content_replace_path_in_condition(const char *condition, char *replace_condition, bool replace);
index 0abd2fe..1b638fd 100755 (executable)
@@ -31,6 +31,7 @@ extern "C" {
  */
 bool _media_util_check_support_media_type(const char *path);
 int _media_util_check_file_exist(const char *path);
+void _media_util_trim_path(const char *input_path, char **output_path);
 int _media_util_check_ignore_file(const char *path, bool *ignore);
 int _media_util_check_ignore_dir(const char *dir_path, bool *ignore);
 int _media_content_replace_path_in_condition(const char *condition, char *replace_condition, bool replace);
index 0e708e6..3f88054 100755 (executable)
@@ -1478,11 +1478,8 @@ static int __media_content_check_dir(const char *path)
 
        /* Check symbolic link directory */
        real = realpath(path, NULL);
-       /* remove if suffix is '/' */
-       if (g_str_has_suffix(path, "/"))
-               origin = g_strndup(path, strlen(path) - 1);
-       else
-               origin = g_strdup(path);
+       /* Get trimmed path */
+       _media_util_trim_path(path, &origin);
 
 #ifdef _USE_TVPD_MODE
        if (g_strcmp0(real, origin) != 0) {
index d963500..77ca1af 100755 (executable)
@@ -76,6 +76,33 @@ int _media_util_check_file_exist(const char *path)
        return MEDIA_CONTENT_ERROR_NONE;
 }
 
+void _media_util_trim_path(const char *input_path, char **output_path)
+{
+       char buf[4096] = {0,};
+       char tmp[4096] = {0,};
+       char *pos = NULL;
+
+       memset(buf, 0, sizeof(buf));
+       if (!SAFE_STRLCPY(buf, input_path, sizeof(buf)))
+               media_content_sec_debug("Truncation occurred[%d]", strlen(input_path));
+
+       while ((pos = strstr(buf, "//")) != NULL) {
+               memset(tmp, 0, sizeof(tmp));
+               if (!SAFE_STRLCPY(tmp, buf, pos - buf + 1))
+                       media_content_sec_debug("Truncation occurred");
+               SAFE_STRLCAT(tmp, pos + 1, sizeof(tmp));
+
+               memset(buf, 0, sizeof(buf));
+               if (!SAFE_STRLCPY(buf, tmp, sizeof(buf)))
+                       media_content_sec_debug("Truncation occurred[%d]", strlen(tmp));
+       }
+
+       if (g_str_has_suffix(buf, "/"))
+               *output_path = g_strndup(buf, strlen(buf) - 1);
+       else
+               *output_path = g_strdup(buf);
+}
+
 int _media_util_check_ignore_file(const char *path, bool *ignore)
 {
        media_content_retvm_if(!STRING_VALID(path), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid path");
@@ -112,11 +139,8 @@ int _media_util_check_ignore_file(const char *path, bool *ignore)
 
        /* Check symbolic directory */
        tmp_path = realpath(path, NULL);
-       /* remove if suffix is '/' */
-       if (g_str_has_suffix(path, "/"))
-               org_path = g_strndup(path, strlen(path) - 1);
-       else
-               org_path = g_strdup(path);
+       /* Get trimmed path */
+       _media_util_trim_path(path, &org_path);
 
 #ifdef _USE_TVPD_MODE
        if (g_strcmp0(tmp_path, org_path) != 0) {