Fix logic when get the internal path 65/99765/1 accepted/tizen/common/20161129.173525 accepted/tizen/ivi/20161130.015407 accepted/tizen/mobile/20161130.015150 accepted/tizen/tv/20161130.015236 accepted/tizen/wearable/20161130.015321 submit/tizen/20161129.052917
authorMinje Ahn <minje.ahn@samsung.com>
Thu, 24 Nov 2016 05:21:23 +0000 (14:21 +0900)
committerMinje Ahn <minje.ahn@samsung.com>
Thu, 24 Nov 2016 05:21:23 +0000 (14:21 +0900)
Change-Id: If7ea506b2841bf7d69a8ba9ce366261ca485d264
Signed-off-by: Minje Ahn <minje.ahn@samsung.com>
packaging/capi-content-media-content.spec
src/media_util_private.c

index c51d7e8f440fb9d35595682e68001eb2a23e6833..3bca763220f0ae0a290fed95398cc03cce604259 100755 (executable)
@@ -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
index db15289ec9079c9dfde77ac5e6aacb94e4f89e9c..07e60a5a5b8d364d43e1e6b16448bb8d6d502f44 100755 (executable)
@@ -27,6 +27,8 @@
 #include <system_info.h>
 #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;