From: Haejeong Kim Date: Fri, 11 Aug 2017 05:26:09 +0000 (+0900) Subject: 1. Check file validity more when batch/burst_shot insert X-Git-Tag: accepted/tizen/unified/20170814.060111^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F21%2F143721%2F2;p=platform%2Fcore%2Fapi%2Fmedia-content.git 1. Check file validity more when batch/burst_shot insert 2. Some code cleanup regarding file validity checking Change-Id: Ied09b61a97cf73f2661c08891e036d93936d3286 --- diff --git a/src/media_info.c b/src/media_info.c index 901761b..c8ee3be 100755 --- a/src/media_info.c +++ b/src/media_info.c @@ -27,6 +27,7 @@ static void __media_info_thumbnail_completed_cb(int error, const char *path, voi static void __media_info_face_completed_cb(int error, const int face_count, void *user_data); static int __media_info_insert_batch(media_batch_insert_e insert_type, const char **path_array, unsigned int array_length, media_insert_completed_cb completed_cb, void *user_data); static int __media_info_set_str_data(media_info_h media, media_info_item_e data_type, const char *str_data); +static int __media_info_check_file_validity(const char *path); static int __media_info_get_media_path_by_id_from_db(const char *media_id, char **path) { @@ -181,7 +182,7 @@ static int __media_info_insert_batch(media_batch_insert_e insert_type, const cha if (STRING_VALID(path_array[idx])) { int size = strlen(path_array[idx]); - ret = _media_util_check_file_exist(path_array[idx]); + ret = __media_info_check_file_validity(path_array[idx]); if (ret != MEDIA_CONTENT_ERROR_NONE) { fclose(fp); if (unlink(list_path) < 0) @@ -307,6 +308,28 @@ int __media_info_get_thumbnail_to_remove(const char *condition_query, const char return ret; } +static int __media_info_check_file_validity(const char *path) +{ + bool ignore = FALSE; + char *folder_path = NULL; + int ret = MEDIA_CONTENT_ERROR_NONE; + + media_content_retvm_if(!STRING_VALID(path), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid path"); + + ret = _media_util_check_ignore_file(path, &ignore); + media_content_retvm_if(ignore == TRUE, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid ignore path"); + + ret = _media_util_check_file_exist(path); + media_content_retvm_if(ret != MEDIA_CONTENT_ERROR_NONE, ret, "invalid path"); + + folder_path = g_path_get_dirname(path); + ret = _media_util_check_ignore_dir(folder_path, &ignore); + SAFE_FREE(folder_path); + media_content_retvm_if(ignore == TRUE, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid folder path"); + + return MEDIA_CONTENT_ERROR_NONE; +} + void _media_info_item_get_detail(sqlite3_stmt* stmt, media_info_h media) { media_info_s *_media = (media_info_s*)media; @@ -453,9 +476,6 @@ int _media_info_get_media_info_from_db(const char *path, const char *storage_id, int media_info_insert_to_db(const char *path, media_info_h *info) { - bool ignore_file = FALSE; - bool ignore_dir = FALSE; - char *folder_path = NULL; char storage_id[MEDIA_CONTENT_UUID_SIZE+1] = {0, }; char repl_path[MAX_PATH_LEN] = {0, }; int ret = MEDIA_CONTENT_ERROR_NONE; @@ -466,18 +486,9 @@ int media_info_insert_to_db(const char *path, media_info_h *info) ret = _media_content_replace_path(path, repl_path); media_content_retvm_if(!STRING_VALID(repl_path), MEDIA_CONTENT_ERROR_INVALID_OPERATION, "path replacement failed"); - ret = _media_util_check_ignore_file(repl_path, &ignore_file); - media_content_retvm_if(ignore_file == TRUE, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid path"); - - ret = _media_util_check_file_exist(repl_path); + ret = __media_info_check_file_validity(repl_path); media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); - folder_path = g_path_get_dirname(repl_path); - ret = _media_util_check_ignore_dir(folder_path, &ignore_dir); - SAFE_FREE(folder_path); - - media_content_retvm_if(ignore_dir == TRUE, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid folder path"); - memset(storage_id, 0x00, sizeof(storage_id)); ret = media_svc_get_storage_id(_content_get_db_handle(), repl_path, storage_id, _content_get_uid()); if (ret != MS_MEDIA_ERR_NONE) { @@ -526,11 +537,7 @@ int media_info_insert_to_db(const char *path, media_info_h *info) return ret; } -int media_info_insert_batch_to_db( - const char **path_array, - unsigned int array_length, - media_insert_completed_cb completed_cb, - void *user_data) +int media_info_insert_batch_to_db(const char **path_array, unsigned int array_length, media_insert_completed_cb completed_cb, void *user_data) { char **repl_path_array = NULL; int idx = 0; @@ -3028,9 +3035,6 @@ int media_info_refresh_metadata_to_db(const char *media_id) int media_info_move_to_db(media_info_h media, const char* dst_path) { int ret = MEDIA_CONTENT_ERROR_NONE; - bool ignore_file = FALSE; - bool ignore_dir = FALSE; - char *folder_path = NULL; media_svc_storage_type_e src_storage_type = 0; media_svc_storage_type_e dst_storage_type = 0; char storage_id[MEDIA_CONTENT_UUID_SIZE+1] = {0, }; @@ -3046,20 +3050,12 @@ int media_info_move_to_db(media_info_h media, const char* dst_path) media_info_s *_media = (media_info_s*)media; - ret = _media_util_check_ignore_file(repl_path, &ignore_file); - media_content_retvm_if(ignore_file == TRUE, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid path"); ret = _media_content_replace_path(_media->file_path, org_repl_path); media_content_retvm_if(!STRING_VALID(org_repl_path), MEDIA_CONTENT_ERROR_INVALID_OPERATION, "path replacement failed"); - ret = _media_util_check_file_exist(repl_path); + ret = __media_info_check_file_validity(repl_path); media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); - folder_path = g_path_get_dirname(repl_path); - ret = _media_util_check_ignore_dir(folder_path, &ignore_dir); - SAFE_FREE(folder_path); - - media_content_retvm_if(ignore_dir == TRUE, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid folder path"); - ret = media_svc_get_storage_type(org_repl_path, &src_storage_type, _content_get_uid()); if (ret != MS_MEDIA_ERR_NONE) { media_content_sec_error("media_svc_get_storage_type failed : %d", ret); @@ -3567,7 +3563,6 @@ int media_info_create(const char *path, media_info_h *media) int ret = MEDIA_CONTENT_ERROR_NONE; char storage_id[MEDIA_CONTENT_UUID_SIZE+1] = {0, }; media_svc_storage_type_e storage_type = 0; - bool ignore_file = FALSE; char repl_path[MAX_PATH_LEN] = {0, }; media_content_warn("DEPRECATION WARNING: media_info_create() is deprecated and will be removed from next release. Use media_info_insert_to_db() instead."); @@ -3577,22 +3572,11 @@ int media_info_create(const char *path, media_info_h *media) ret = _media_content_replace_path(path, repl_path); media_content_retvm_if(!STRING_VALID(repl_path), MEDIA_CONTENT_ERROR_INVALID_OPERATION, "path replacement failed"); - ret = _media_util_check_ignore_file(repl_path, &ignore_file); - media_content_retvm_if(ignore_file == TRUE, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid path"); - memset(storage_id, 0x00, sizeof(storage_id)); - bool ignore_dir = FALSE; - char *folder_path = NULL; - - ret = _media_util_check_file_exist(repl_path); + ret = __media_info_check_file_validity(repl_path); media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); - folder_path = g_path_get_dirname(repl_path); - ret = _media_util_check_ignore_dir(folder_path, &ignore_dir); - SAFE_FREE(folder_path); - media_content_retvm_if(ignore_dir == TRUE, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid folder path"); - ret = media_svc_get_storage_id(_content_get_db_handle(), repl_path, storage_id, _content_get_uid()); if (ret != MS_MEDIA_ERR_NONE) { media_content_error("media_svc_get_storage_id failed : %d", ret);