Add function to trim the path
[platform/core/api/media-content.git] / src / media_util_private.c
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) {