#include <system_info.h>
#endif
+static char *g_old_path = NULL;
+
int _media_util_check_file_exist(const char *path)
{
int exist;
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;
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;
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);
char *cond_ptr = cond;
if (cond_ptr == NULL) {
- SAFE_FREE(old_path);
media_content_error("memory allocation failed");
return MEDIA_CONTENT_ERROR_INVALID_OPERATION;
}
}
/* 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++;
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;
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;
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;