Add function to trim the path 75/172275/2 accepted/tizen/4.0/unified/20180314.062109 submit/tizen_4.0/20180313.065725
authorMinje Ahn <minje.ahn@samsung.com>
Tue, 13 Mar 2018 05:29:23 +0000 (14:29 +0900)
committerMinje ahn <minje.ahn@samsung.com>
Tue, 13 Mar 2018 05:59:58 +0000 (05:59 +0000)
Change-Id: I1bcad384162740b0242a0cdd1e87e78220c42585
Signed-off-by: Minje Ahn <minje.ahn@samsung.com>
src/common/include/media-common-types.h
src/common/media-common-utils.c

index 45920e7..8cb08ae 100755 (executable)
@@ -62,6 +62,7 @@ typedef enum {
 #define MS_STRING_VALID(str)   \
                                                                ((str != NULL && strlen(str) > 0) ? TRUE : FALSE)
 #define SAFE_STRLCPY(dst, src, n)      g_strlcpy(dst, src, n);
+#define SAFE_STRLCAT(dst, src, n)      g_strlcat(dst, src, n);
 
 /*System default folder definition*/
 #define FAT_FILENAME_LEN_MAX           255     /* not inc null */
index 0447f72..2e6bac3 100755 (executable)
@@ -253,11 +253,36 @@ int ms_check_ignore_dir(const char *full_path, uid_t uid)
        return ret;
 }
 
+void __ms_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));
+       SAFE_STRLCPY(buf, input_path, sizeof(buf));
+
+       while ((pos = strstr(buf, "//")) != NULL) {
+               memset(tmp, 0, sizeof(tmp));
+               SAFE_STRLCPY(tmp, buf, pos - buf + 1);
+               SAFE_STRLCAT(tmp, pos + 1, sizeof(tmp));
+
+               memset(buf, 0, sizeof(buf));
+               SAFE_STRLCPY(buf, tmp, sizeof(buf));
+       }
+
+       if (g_str_has_suffix(buf, "/"))
+               *output_path = g_strndup(buf, strlen(buf) - 1);
+       else
+               *output_path = g_strdup(buf);
+}
+
 int ms_check_scan_ignore(char * path, uid_t uid)
 {
        int ret = MS_MEDIA_ERR_NONE;
        const char *ignore_file = ".scan_ignore";
        char *tmp_path = NULL;
+       char *org_path = NULL;
        char ignore_path[MS_FILE_PATH_LEN_MAX] = {0, };
 
 #ifndef _USE_TVPD_MODE
@@ -272,10 +297,13 @@ int ms_check_scan_ignore(char * path, uid_t uid)
 
        /* Check for symbolic link */
        tmp_path = realpath(path, NULL);
+       /* Get trimmed path */
+       __ms_trim_path(path, &org_path);
 
 #ifdef _USE_TVPD_MODE
-       if (g_strcmp0(tmp_path, path) != 0) {
+       if (g_strcmp0(tmp_path, org_path) != 0) {
                MS_SAFE_FREE(tmp_path);
+               MS_SAFE_FREE(org_path);
                MS_DBG_ERR("symbolic link(directory)");
                return MS_MEDIA_ERR_INVALID_PATH;
        }
@@ -284,20 +312,23 @@ int ms_check_scan_ignore(char * path, uid_t uid)
                ms_user_get_mediashared_path(uid, &mediashared);
                snprintf(replace, MS_FILE_PATH_LEN_MAX, "%s%s", mediashared, tmp_path + strlen(MEDIA_SHARE_PATH));
                MS_SAFE_FREE(mediashared);
-               if (g_strcmp0(replace, path) != 0) {
+               if (g_strcmp0(replace, org_path) != 0) {
                        MS_SAFE_FREE(tmp_path);
+                       MS_SAFE_FREE(org_path);
                        MS_DBG_ERR("symbolic link(directory)");
                        return MS_MEDIA_ERR_INVALID_PATH;
                }
        } else {
-               if (g_strcmp0(tmp_path, path) != 0) {
+               if (g_strcmp0(tmp_path, org_path) != 0) {
                        MS_SAFE_FREE(tmp_path);
+                       MS_SAFE_FREE(org_path);
                        MS_DBG_ERR("symbolic link(directory)");
                        return MS_MEDIA_ERR_INVALID_PATH;
                }
        }
 #endif
        MS_SAFE_FREE(tmp_path);
+       MS_SAFE_FREE(org_path);
 
        if (g_file_test(path, G_FILE_TEST_IS_DIR)) {
                memset(ignore_path, 0, sizeof(ignore_path));