From 9a58d0ab527b366d8f23e79b86354bedd4dda6c1 Mon Sep 17 00:00:00 2001 From: Minje Ahn Date: Thu, 24 Nov 2016 14:21:23 +0900 Subject: [PATCH] Fix logic when get the internal path Change-Id: If7ea506b2841bf7d69a8ba9ce366261ca485d264 Signed-off-by: Minje Ahn --- packaging/capi-content-media-content.spec | 2 +- src/media_util_private.c | 74 +++++++++++++++---------------- 2 files changed, 36 insertions(+), 40 deletions(-) diff --git a/packaging/capi-content-media-content.spec b/packaging/capi-content-media-content.spec index c51d7e8..3bca763 100755 --- a/packaging/capi-content-media-content.spec +++ b/packaging/capi-content-media-content.spec @@ -1,6 +1,6 @@ Name: capi-content-media-content Summary: A Media content library in Tizen Native API -Version: 0.2.90 +Version: 0.2.91 Release: 0 Group: Multimedia/API License: Apache-2.0 diff --git a/src/media_util_private.c b/src/media_util_private.c index db15289..07e60a5 100755 --- a/src/media_util_private.c +++ b/src/media_util_private.c @@ -27,6 +27,8 @@ #include #endif +static char *g_old_path = NULL; + int _media_util_check_file_exist(const char *path) { int exist; @@ -175,34 +177,34 @@ 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) { int ret = MEDIA_CONTENT_ERROR_NONE; - char *old_path = NULL; - ret = storage_get_root_directory(STORAGE_TYPE_INTERNAL, &old_path); - if (ret != STORAGE_ERROR_NONE) { - media_content_error("storage_get_directory failed"); - return MEDIA_CONTENT_ERROR_INVALID_OPERATION; + if (!STRING_VALID(g_old_path)) { + ret = storage_get_root_directory(STORAGE_TYPE_INTERNAL, &g_old_path); + if (ret != STORAGE_ERROR_NONE) { + media_content_error("storage_get_directory failed"); + return MEDIA_CONTENT_ERROR_INVALID_OPERATION; + } } media_content_sec_debug("Old condition[%s]", condition); - if (((strstr(condition, "PATH") != NULL) || (strstr(condition, "path") != NULL)) && (strstr(condition, old_path) != NULL)) { + if (((strstr(condition, "PATH") != NULL) || (strstr(condition, "path") != NULL)) && (strstr(condition, g_old_path) != NULL)) { char *cond = strdup(condition); char *repl_cond_ptr = replace_condition; char *cond_ptr = cond; if (cond_ptr == NULL) { - SAFE_FREE(old_path); media_content_error("memory allocation failed"); return MEDIA_CONTENT_ERROR_INVALID_OPERATION; } while (*cond_ptr != '\0') { - if (strlen(cond_ptr) < strlen(old_path)) { + if (strlen(cond_ptr) < strlen(g_old_path)) { memcpy(repl_cond_ptr, cond_ptr, strlen(cond_ptr)); break; } /* replace path only and keep other condition */ - if (memcmp(cond_ptr, old_path, strlen(old_path)) == 0) { + if (memcmp(cond_ptr, g_old_path, strlen(g_old_path)) == 0) { memcpy(repl_cond_ptr, tzplatform_getenv(TZ_USER_CONTENT), strlen(tzplatform_getenv(TZ_USER_CONTENT))); - cond_ptr += strlen(old_path); + cond_ptr += strlen(g_old_path); repl_cond_ptr += strlen(tzplatform_getenv(TZ_USER_CONTENT)); } else { *repl_cond_ptr = *cond_ptr; @@ -215,8 +217,6 @@ int _media_content_replace_path_in_condition(const char *condition, char *replac snprintf(replace_condition, MAX_QUERY_SIZE, "%s", condition); } - SAFE_FREE(old_path); - if (!STRING_VALID(replace_condition)) { media_content_error("replace failed"); return MEDIA_CONTENT_ERROR_INVALID_OPERATION; @@ -230,12 +230,13 @@ int _media_content_replace_path_in_condition(const char *condition, char *replac int _media_content_rollback_path_in_condition(const char *condition, char *replace_condition) { int ret = MEDIA_CONTENT_ERROR_NONE; - char *old_path = NULL; - ret = storage_get_root_directory(STORAGE_TYPE_INTERNAL, &old_path); - if (ret != STORAGE_ERROR_NONE) { - media_content_error("storage_get_directory failed"); - return MEDIA_CONTENT_ERROR_INVALID_OPERATION; + if (!STRING_VALID(g_old_path)) { + ret = storage_get_root_directory(STORAGE_TYPE_INTERNAL, &g_old_path); + if (ret != STORAGE_ERROR_NONE) { + media_content_error("storage_get_directory failed"); + return MEDIA_CONTENT_ERROR_INVALID_OPERATION; + } } media_content_sec_debug("Old condition[%s]", condition); @@ -245,7 +246,6 @@ int _media_content_rollback_path_in_condition(const char *condition, char *repla char *cond_ptr = cond; if (cond_ptr == NULL) { - SAFE_FREE(old_path); media_content_error("memory allocation failed"); return MEDIA_CONTENT_ERROR_INVALID_OPERATION; } @@ -256,9 +256,9 @@ int _media_content_rollback_path_in_condition(const char *condition, char *repla } /* replace path only and keep other condition */ if (memcmp(cond_ptr, tzplatform_getenv(TZ_USER_CONTENT), strlen(tzplatform_getenv(TZ_USER_CONTENT))) == 0) { - memcpy(repl_cond_ptr, old_path, strlen(old_path)); + memcpy(repl_cond_ptr, g_old_path, strlen(g_old_path)); cond_ptr += strlen(tzplatform_getenv(TZ_USER_CONTENT)); - repl_cond_ptr += strlen(old_path); + repl_cond_ptr += strlen(g_old_path); } else { *repl_cond_ptr = *cond_ptr; cond_ptr++; @@ -270,8 +270,6 @@ int _media_content_rollback_path_in_condition(const char *condition, char *repla snprintf(replace_condition, MAX_QUERY_SIZE, "%s", condition); } - SAFE_FREE(old_path); - if (!STRING_VALID(replace_condition)) { media_content_error("replace failed"); return MEDIA_CONTENT_ERROR_INVALID_OPERATION; @@ -285,23 +283,22 @@ int _media_content_rollback_path_in_condition(const char *condition, char *repla int _media_content_replace_path(const char *path, char *replace_path) { int ret = MEDIA_CONTENT_ERROR_NONE; - char *old_path = NULL; - ret = storage_get_root_directory(STORAGE_TYPE_INTERNAL, &old_path); - if (ret != STORAGE_ERROR_NONE) { - media_content_error("storage_get_directory failed"); - return MEDIA_CONTENT_ERROR_INVALID_OPERATION; + if (!STRING_VALID(g_old_path)) { + ret = storage_get_root_directory(STORAGE_TYPE_INTERNAL, &g_old_path); + if (ret != STORAGE_ERROR_NONE) { + media_content_error("storage_get_directory failed"); + return MEDIA_CONTENT_ERROR_INVALID_OPERATION; + } } - if (strncmp(path, old_path, strlen(old_path)) == 0) { + if (strncmp(path, g_old_path, strlen(g_old_path)) == 0) { media_content_sec_debug("Old path[%s]", path); - snprintf(replace_path, MAX_QUERY_SIZE, "%s%s", tzplatform_getenv(TZ_USER_CONTENT), path + strlen(old_path)); + snprintf(replace_path, MAX_QUERY_SIZE, "%s%s", tzplatform_getenv(TZ_USER_CONTENT), path + strlen(g_old_path)); } else { snprintf(replace_path, MAX_QUERY_SIZE, "%s", path); } - SAFE_FREE(old_path); - if (!STRING_VALID(replace_path)) { media_content_error("replace failed"); return MEDIA_CONTENT_ERROR_INVALID_OPERATION; @@ -313,23 +310,22 @@ int _media_content_replace_path(const char *path, char *replace_path) int _media_content_rollback_path(const char *path, char *replace_path) { int ret = MEDIA_CONTENT_ERROR_NONE; - char *old_path = NULL; - ret = storage_get_root_directory(STORAGE_TYPE_INTERNAL, &old_path); - if (ret != STORAGE_ERROR_NONE) { - media_content_error("storage_get_directory failed"); - return MEDIA_CONTENT_ERROR_INVALID_OPERATION; + if (!STRING_VALID(g_old_path)) { + ret = storage_get_root_directory(STORAGE_TYPE_INTERNAL, &g_old_path); + if (ret != STORAGE_ERROR_NONE) { + media_content_error("storage_get_directory failed"); + return MEDIA_CONTENT_ERROR_INVALID_OPERATION; + } } if (strncmp(path, tzplatform_getenv(TZ_USER_CONTENT), strlen(tzplatform_getenv(TZ_USER_CONTENT))) == 0) { media_content_sec_debug("new path[%s]", path); - snprintf(replace_path, MAX_QUERY_SIZE, "%s%s", old_path, path + strlen(tzplatform_getenv(TZ_USER_CONTENT))); + snprintf(replace_path, MAX_QUERY_SIZE, "%s%s", g_old_path, path + strlen(tzplatform_getenv(TZ_USER_CONTENT))); } else { snprintf(replace_path, MAX_QUERY_SIZE, "%s", path); } - SAFE_FREE(old_path); - if (!STRING_VALID(replace_path)) { media_content_error("replace failed"); return MEDIA_CONTENT_ERROR_INVALID_OPERATION; -- 2.7.4