From 470032482a419dc858ddf9cd0f17a199fd3b1dab Mon Sep 17 00:00:00 2001 From: Minje Ahn Date: Tue, 13 Mar 2018 14:29:23 +0900 Subject: [PATCH] Add function to trim the path Change-Id: I1bcad384162740b0242a0cdd1e87e78220c42585 Signed-off-by: Minje Ahn --- src/common/include/media-common-types.h | 1 + src/common/media-common-utils.c | 37 ++++++++++++++++++++++++++++++--- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/src/common/include/media-common-types.h b/src/common/include/media-common-types.h index 45920e7..8cb08ae 100755 --- a/src/common/include/media-common-types.h +++ b/src/common/include/media-common-types.h @@ -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 */ diff --git a/src/common/media-common-utils.c b/src/common/media-common-utils.c index 0447f72..2e6bac3 100755 --- a/src/common/media-common-utils.c +++ b/src/common/media-common-utils.c @@ -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)); -- 2.7.4