From: Minje Ahn Date: Tue, 3 Apr 2018 06:29:34 +0000 (+0900) Subject: Add function for invalid storage X-Git-Tag: submit/tizen/20180411.083552~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F93%2F174593%2F4;p=platform%2Fcore%2Fmultimedia%2Flibmedia-service.git Add function for invalid storage Change-Id: I12eee14bbb4fbb6b60f8f53d9b46bee3077efb3d Signed-off-by: Minje Ahn --- diff --git a/include/media-svc.h b/include/media-svc.h index 2a3c0f8..468f702 100755 --- a/include/media-svc.h +++ b/include/media-svc.h @@ -71,7 +71,6 @@ int media_svc_insert_item_immediately_with_data(MediaSvcHandle *handle, media_sv void media_svc_destroy_content_info(media_svc_content_info_s *content_info); int media_svc_generate_uuid(char **uuid); -int media_svc_get_mmc_info(MediaSvcHandle *handle, char **storage_name, char **storage_path, int *validity, bool *info_exist); int media_svc_check_storage(MediaSvcHandle *handle, const char *storage_id, char **storage_path, int *validity, uid_t uid); int media_svc_insert_storage(MediaSvcHandle *handle, const char *storage_id, const char *storage_name, const char *storage_path, media_svc_storage_type_e storage_type, uid_t uid); int media_svc_update_storage(MediaSvcHandle *handle, const char *storage_id, const char *storage_path, uid_t uid); diff --git a/packaging/libmedia-service.spec b/packaging/libmedia-service.spec index 17253bc..01e896e 100644 --- a/packaging/libmedia-service.spec +++ b/packaging/libmedia-service.spec @@ -1,6 +1,6 @@ Name: libmedia-service Summary: Media information service library for multimedia applications -Version: 0.3.29 +Version: 0.3.30 Release: 0 Group: Multimedia/Libraries License: Apache-2.0 and PD diff --git a/plugin/media-content-plugin.c b/plugin/media-content-plugin.c index ed403ee..0042727 100755 --- a/plugin/media-content-plugin.c +++ b/plugin/media-content-plugin.c @@ -496,24 +496,6 @@ int get_uuid(void * handle, char **uuid, char **err_msg) return MEDIA_SVC_PLUGIN_ERROR_NONE; } -int get_mmc_info(void * handle, char **storage_name, char **storage_path, int *validity, bool *info_exist, char **err_msg) -{ - int ret = MEDIA_SVC_PLUGIN_ERROR_NONE; - - if (handle == NULL) { - __set_error_message(ERR_HANDLE, err_msg); - return MEDIA_SVC_PLUGIN_ERROR; - } - - ret = media_svc_get_mmc_info(handle, storage_name, storage_path, validity, info_exist); - if (ret < 0) { - __set_error_message(MS_MEDIA_ERR_DB_NO_RECORD, err_msg); - return MEDIA_SVC_PLUGIN_ERROR; - } - - return MEDIA_SVC_PLUGIN_ERROR_NONE; -} - int check_storage(void * handle, const char *storage_id, char **storage_path, int *validity, uid_t uid, char **err_msg) { int ret = MEDIA_SVC_PLUGIN_ERROR_NONE; diff --git a/src/common/media-svc-media.c b/src/common/media-svc-media.c index cb73bf0..1f45f5c 100755 --- a/src/common/media-svc-media.c +++ b/src/common/media-svc-media.c @@ -110,7 +110,7 @@ int _media_svc_insert_item_with_data(sqlite3 *handle, const char *storage_id, me /* Get thumbnail for burst shot */ char thumb_path[MEDIA_SVC_PATHNAME_SIZE + 1] = {0, }; - ret = _media_svc_create_thumbnail(content_info->path, thumb_path, sizeof(thumb_path), content_info->media_type, uid); + ret = _media_svc_create_thumbnail(content_info->storage_uuid, content_info->path, thumb_path, sizeof(thumb_path), content_info->media_type, uid); if (ret == MS_MEDIA_ERR_NONE) content_info->thumbnail_path = g_strdup(thumb_path); } diff --git a/src/common/media-svc-storage.c b/src/common/media-svc-storage.c index 91d525f..6222904 100755 --- a/src/common/media-svc-storage.c +++ b/src/common/media-svc-storage.c @@ -26,35 +26,6 @@ #include "media-svc-util.h" #include "media-svc-storage.h" -int _media_svc_get_mmc_info(MediaSvcHandle *handle, char **storage_name, char **storage_path, int *validity, bool *info_exist) -{ - int ret = MS_MEDIA_ERR_NONE; - sqlite3_stmt *sql_stmt = NULL; - char *sql = NULL; - - sql = sqlite3_mprintf("SELECT storage_name, storage_path, validity FROM '%q' WHERE storage_uuid=%Q", MEDIA_SVC_DB_TABLE_STORAGE, MEDIA_SVC_DB_TABLE_MEDIA); - - ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt); - if (ret != MS_MEDIA_ERR_NONE) { - *storage_name = NULL; - *storage_path = NULL; - *validity = 0; - *info_exist = FALSE; - - return ret; - } - - *storage_name = g_strdup((const char *)sqlite3_column_text(sql_stmt, 0)); - *storage_path = g_strdup((const char *)sqlite3_column_text(sql_stmt, 1)); - *validity = sqlite3_column_int(sql_stmt, 2); - - *info_exist = TRUE; - - SQLITE3_FINALIZE(sql_stmt); - - return MS_MEDIA_ERR_NONE; -} - int _media_svc_check_storage(sqlite3 *handle, const char *storage_id, char **storage_path, int *validity, uid_t uid) { int ret = MS_MEDIA_ERR_NONE; @@ -163,13 +134,94 @@ int _media_svc_delete_storage(const char *storage_id, uid_t uid) return ret; } +int _media_svc_delete_invalid_storage(sqlite3 *handle, media_svc_storage_type_e storage_type, uid_t uid) +{ + int ret = MS_MEDIA_ERR_NONE; + char *sql = NULL; + char *storage_id = NULL; + char *thumb_path = NULL; + sqlite3_stmt *sql_stmt = NULL; + GArray *storage_list = NULL; + + /* Get invalid storage_uuid (with storage_type)*/ + sql = sqlite3_mprintf("SELECT storage_uuid FROM '%q' WHERE validity = 0 AND storage_type=%d;", MEDIA_SVC_DB_TABLE_STORAGE, storage_type); + ret = _media_svc_sql_prepare_to_step_simple(handle, sql, &sql_stmt); + media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret); + + storage_list = g_array_new(false, false, sizeof(char *)); + + while (sqlite3_step(sql_stmt) == SQLITE_ROW) { + storage_id = g_strdup((const char *)sqlite3_column_text(sql_stmt, 0)); + if (storage_id != NULL) + g_array_append_val(storage_list, storage_id); + + storage_id = NULL; + } + + SQLITE3_FINALIZE(sql_stmt); + + while (storage_list->len > 0) { + storage_id = g_array_index(storage_list, char *, 0); + storage_list = g_array_remove_index(storage_list, 0); + + ret = ms_user_get_thumb_store_path(uid, storage_type, storage_id, &thumb_path); + if (ret != MS_MEDIA_ERR_NONE) { + media_svc_error("Fail to get thumbnail directory"); + goto ERROR; + } + + ret = _media_svc_remove_dir(storage_type, thumb_path); + if (ret != MS_MEDIA_ERR_NONE) { + media_svc_error("Fail to remove thumbnail directory[%s]", thumb_path); + goto ERROR; + } + + /* remove media before drop table (for clear playlist, and tag table)*/ + sql = sqlite3_mprintf("DELETE FROM '%q';DROP TABLE '%q';", storage_id); + ret = _media_svc_sql_query(sql, uid); + SQLITE3_SAFE_FREE(sql); + if (ret != MS_MEDIA_ERR_NONE) { + media_svc_error("Fail to drop table[%s]", storage_id); + goto ERROR; + } + + SAFE_FREE(storage_id); + } + + /* Update storage, folder table */ + sql = sqlite3_mprintf("DELETE FROM '%q' WHERE validity=0 AND storage_type=%d;DELETE FROM '%q' WHERE validity=0 AND storage_type=%d;", + MEDIA_SVC_DB_TABLE_STORAGE, storage_type, MEDIA_SVC_DB_TABLE_FOLDER, storage_type); + + ret = _media_svc_sql_query(sql, uid); + SQLITE3_SAFE_FREE(sql); + if (ret != MS_MEDIA_ERR_NONE) { + media_svc_error("Fail to update storage table"); + goto ERROR; + } + +ERROR: + SAFE_FREE(storage_id); + SAFE_FREE(thumb_path); + + while (storage_list->len > 0) { + storage_id = g_array_index(storage_list, char *, 0); + storage_list = g_array_remove_index(storage_list, 0); + SAFE_FREE(storage_id); + } + + g_array_free(storage_list, false); + storage_list = NULL; + + return ret; +} + int _media_svc_update_storage_validity(const char *storage_id, int validity, uid_t uid) { int ret = MS_MEDIA_ERR_NONE; char *sql = NULL; if (storage_id == NULL) - sql = sqlite3_mprintf("UPDATE '%q' SET validity=%d WHERE storage_uuid != 'media';", MEDIA_SVC_DB_TABLE_STORAGE, validity); + sql = sqlite3_mprintf("UPDATE '%q' SET validity=%d WHERE storage_uuid!='media';", MEDIA_SVC_DB_TABLE_STORAGE, validity); else sql = sqlite3_mprintf("UPDATE '%q' SET validity=%d WHERE storage_uuid=%Q;", MEDIA_SVC_DB_TABLE_STORAGE, validity, storage_id); diff --git a/src/common/media-svc-util.c b/src/common/media-svc-util.c index cceedba..61dfe4b 100755 --- a/src/common/media-svc-util.c +++ b/src/common/media-svc-util.c @@ -712,7 +712,7 @@ int _media_svc_remove_file(const char *path) } } -int _media_svc_remove_all_files_in_dir(const char *dir_path) +int _media_svc_remove_dir(media_svc_storage_type_e storage_type, const char *dir_path) { char filename[MEDIA_SVC_PATHNAME_SIZE] = {0, }; GDir *dir = NULL; @@ -740,10 +740,18 @@ int _media_svc_remove_all_files_in_dir(const char *dir_path) g_dir_close(dir); + if (storage_type != MEDIA_SVC_STORAGE_INTERNAL) { + /* Remove directory when external storage */ + if (g_rmdir(dir_path) != 0) { + media_svc_error("Failed to remove directory"); + return MS_MEDIA_ERR_INTERNAL; + } + } + return MS_MEDIA_ERR_NONE; } -int _media_svc_get_thumbnail_path(media_svc_storage_type_e storage_type, media_svc_media_type_e media_type, char *thumb_path, const char *pathname, const char *img_format, uid_t uid) +int _media_svc_get_thumbnail_path(const char *storage_id, media_svc_storage_type_e storage_type, media_svc_media_type_e media_type, char *thumb_path, const char *pathname, const char *img_format, uid_t uid) { int ret = MS_MEDIA_ERR_NONE; char file_ext[MEDIA_SVC_FILE_EXT_LEN_MAX + 1] = {0, }; @@ -751,7 +759,7 @@ int _media_svc_get_thumbnail_path(media_svc_storage_type_e storage_type, media_s char *thumb_dir = NULL; char *thumbfile_ext = NULL; - ret = ms_user_get_thumb_store_path(uid, storage_type, &thumb_dir); + ret = ms_user_get_thumb_store_path(uid, storage_type, storage_id, &thumb_dir); if (!STRING_VALID(thumb_dir)) { media_svc_error("ms_user_get_thumb_store_path failed"); return MS_MEDIA_ERR_INTERNAL; @@ -1545,7 +1553,7 @@ int _media_svc_extract_media_metadata(sqlite3 *handle, media_svc_content_info_s mmf_error = mm_file_get_attrs(tag, &err_attr_name, MM_FILE_TAG_ARTWORK_MIME, &p, &artwork_mime_size, NULL); if ((mmf_error == FILEINFO_ERROR_NONE) && (artwork_mime_size > 0)) { - ret = _media_svc_get_thumbnail_path(content_info->storage_type, content_info->media_type, thumb_path, content_info->path, p, uid); + ret = _media_svc_get_thumbnail_path(content_info->storage_uuid, content_info->storage_type, content_info->media_type, thumb_path, content_info->path, p, uid); if (ret != MS_MEDIA_ERR_NONE) media_svc_error("Fail to Get Thumbnail Path"); @@ -1805,7 +1813,7 @@ int __media_svc_get_proper_thumb_size(unsigned int orig_w, unsigned int orig_h, return MS_MEDIA_ERR_NONE; } -int _media_svc_create_thumbnail(const char *path, char *thumb_path, int max_length, media_svc_media_type_e media_type, uid_t uid) +int _media_svc_create_thumbnail(const char *storage_id, const char *path, char *thumb_path, int max_length, media_svc_media_type_e media_type, uid_t uid) { int ret = MS_MEDIA_ERR_NONE; unsigned int origin_w = 0; @@ -1840,7 +1848,7 @@ int _media_svc_create_thumbnail(const char *path, char *thumb_path, int max_leng media_svc_sec_debug("Path[%s] Type[%d]", path, media_type); //1. make hash path - ret = _media_svc_get_thumbnail_path(store_type, media_type, thumb_path, path, THUMB_EXT, uid); + ret = _media_svc_get_thumbnail_path(storage_id, store_type, media_type, thumb_path, path, THUMB_EXT, uid); if (ret != MS_MEDIA_ERR_NONE) { media_svc_error("_media_svc_get_thumbnail_path failed - %d", ret); SAFE_STRLCPY(thumb_path, "", MAX_FILEPATH_LEN); diff --git a/src/common/media-svc.c b/src/common/media-svc.c index 10207c5..5db097c 100755 --- a/src/common/media-svc.c +++ b/src/common/media-svc.c @@ -446,7 +446,7 @@ int media_svc_insert_item_immediately(MediaSvcHandle *handle, const char *storag if (media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE || media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO) { char thumb_path[MEDIA_SVC_PATHNAME_SIZE + 1] = {0, }; - ret = _media_svc_create_thumbnail(content_info.path, thumb_path, sizeof(thumb_path), media_type, uid); + ret = _media_svc_create_thumbnail(content_info.storage_uuid, content_info.path, thumb_path, sizeof(thumb_path), media_type, uid); if (ret == MS_MEDIA_ERR_NONE) content_info.thumbnail_path = g_strdup(thumb_path); } @@ -692,13 +692,13 @@ int media_svc_delete_all_items_in_storage(const char *storage_id, media_svc_stor media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret); if (storage_type != MEDIA_SVC_STORAGE_EXTERNAL_USB) { - ret = ms_user_get_thumb_store_path(uid, (ms_user_storage_type_e)storage_type, &thumb_path); + ret = ms_user_get_thumb_store_path(uid, (ms_user_storage_type_e)storage_type, storage_id, &thumb_path); if (!STRING_VALID(thumb_path)) { media_svc_error("fail to get thumbnail path"); return MS_MEDIA_ERR_INTERNAL; } - ret = _media_svc_remove_all_files_in_dir(thumb_path); + ret = _media_svc_remove_dir(storage_type, thumb_path); SAFE_FREE(thumb_path); media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret); } @@ -815,7 +815,7 @@ int media_svc_refresh_item(MediaSvcHandle *handle, const char *storage_id, media if (media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE || media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO) { memset(thumb_path, 0, sizeof(thumb_path)); - ret = _media_svc_create_thumbnail(content_info.path, thumb_path, sizeof(thumb_path), media_type, uid); + ret = _media_svc_create_thumbnail(content_info.storage_uuid, content_info.path, thumb_path, sizeof(thumb_path), media_type, uid); if (ret == MS_MEDIA_ERR_NONE) content_info.thumbnail_path = g_strdup(thumb_path); } @@ -940,7 +940,7 @@ int media_svc_rename_folder(MediaSvcHandle *handle, const char *storage_id, cons return ret; } - ret = _media_svc_get_thumbnail_path(storage_type, media_type, media_new_thumb_path, media_path, THUMB_EXT, uid); + ret = _media_svc_get_thumbnail_path(storage_id, storage_type, media_type, media_new_thumb_path, media_path, THUMB_EXT, uid); if (ret != MS_MEDIA_ERR_NONE) { media_svc_error("_media_svc_get_thumbnail_path failed : %d", ret); SQLITE3_FINALIZE(sql_stmt); @@ -1339,7 +1339,7 @@ int media_svc_insert_item_immediately_with_data(MediaSvcHandle *handle, media_sv if (media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE || media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO) { char thumb_path[MEDIA_SVC_PATHNAME_SIZE + 1] = {0, }; - ret = _media_svc_create_thumbnail(_new_content_info.path, thumb_path, sizeof(thumb_path), media_type, uid); + ret = _media_svc_create_thumbnail(_new_content_info.storage_uuid, _new_content_info.path, thumb_path, sizeof(thumb_path), media_type, uid); if (ret == MS_MEDIA_ERR_NONE) _new_content_info.thumbnail_path = g_strdup(thumb_path); } @@ -1426,15 +1426,6 @@ int media_svc_generate_uuid(char **uuid) return MS_MEDIA_ERR_NONE; } -int media_svc_get_mmc_info(MediaSvcHandle *handle, char **storage_name, char **storage_path, int *validity, bool *info_exist) -{ - sqlite3 * db_handle = (sqlite3 *)handle; - - media_svc_retvm_if(db_handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL"); - - return _media_svc_get_mmc_info(db_handle, storage_name, storage_path, validity, info_exist); -} - int media_svc_check_storage(MediaSvcHandle *handle, const char *storage_id, char **storage_path, int *validity, uid_t uid) { sqlite3 * db_handle = (sqlite3 *)handle; @@ -1471,13 +1462,15 @@ int media_svc_insert_storage(MediaSvcHandle *handle, const char *storage_id, con ret = _media_svc_append_storage(storage_id, storage_name, storage_path, storage_type, uid); media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "append storage failed : %d", ret); - if (strcmp(storage_id, MEDIA_SVC_DB_TABLE_MEDIA)) { - ret = _media_svc_create_media_table_with_id(storage_id, uid); - media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "create media table failed : %d", ret); + ret = _media_svc_create_media_table_with_id(storage_id, uid); + media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "create media table failed : %d", ret); - ret = _media_svc_update_media_view(db_handle, uid); - media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "update media view failed : %d", ret); - } + ret = _media_svc_update_media_view(db_handle, uid); + media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "update media view failed : %d", ret); + + /* Remove external storage that validity is 0 */ + ret = _media_svc_delete_invalid_storage(db_handle, storage_type, uid); + media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "Delete invalid storage failed : %d", ret); return ret; } @@ -1501,7 +1494,7 @@ int media_svc_delete_storage(MediaSvcHandle *handle, const char *storage_id, uid if (ret != MS_MEDIA_ERR_NONE) media_svc_error("fail to _media_svc_delete_folder_by_storage_id. error : [%d]", ret); - if (storage_type == MEDIA_SVC_STORAGE_EXTERNAL_USB) { + if (storage_type != MEDIA_SVC_STORAGE_INTERNAL) { ret = _media_svc_drop_media_table(storage_id, uid); media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "drop table failed : %d", ret); @@ -1820,7 +1813,7 @@ int media_svc_create_thumbnail(const char *storage_id, const char *file_path, in return MS_MEDIA_ERR_UNSUPPORTED_CONTENT; // 2. try to create thumbnail - ret = _media_svc_create_thumbnail(file_path, thumb_path, MEDIA_SVC_PATHNAME_SIZE, media_type, uid); + ret = _media_svc_create_thumbnail(storage_id, file_path, thumb_path, MEDIA_SVC_PATHNAME_SIZE, media_type, uid); if (ret != MS_MEDIA_ERR_NONE) { media_svc_error("Failed to create thumbnail [%d]", ret); if (ret == MS_MEDIA_ERR_UNSUPPORTED_CONTENT) diff --git a/src/include/common/media-svc-storage.h b/src/include/common/media-svc-storage.h index 0ff104c..76ed4f8 100755 --- a/src/include/common/media-svc-storage.h +++ b/src/include/common/media-svc-storage.h @@ -24,11 +24,11 @@ #include -int _media_svc_get_mmc_info(MediaSvcHandle *handle, char **storage_name, char **storage_path, int *validity, bool *info_exist); int _media_svc_check_storage(sqlite3 *handle, const char *storage_id, char **storage_path, int *validity, uid_t uid); int _media_svc_append_storage(const char *storage_id, const char *storage_name, const char *storage_path, media_svc_storage_type_e storage_type, uid_t uid); int _media_svc_update_storage_path(sqlite3 *handle, const char *storage_id, const char *path, uid_t uid); int _media_svc_delete_storage(const char *storage_id, uid_t uid); +int _media_svc_delete_invalid_storage(sqlite3 *handle, media_svc_storage_type_e storage_type, uid_t uid); int _media_svc_update_storage_validity(const char *storage_id, int validity, uid_t uid); int _media_svc_get_storage_uuid(sqlite3 *handle, const char *path, char *storage_id, uid_t uid); int _media_svc_get_storage_type(sqlite3 *handle, const char *storage_id, media_svc_storage_type_e *storage_type); diff --git a/src/include/common/media-svc-util.h b/src/include/common/media-svc-util.h index b19b1ea..1f042bd 100755 --- a/src/include/common/media-svc-util.h +++ b/src/include/common/media-svc-util.h @@ -52,8 +52,8 @@ extern "C" { char *_media_info_generate_uuid(void); int _media_svc_rename_file(const char *old_name, const char *new_name); int _media_svc_remove_file(const char *path); -int _media_svc_remove_all_files_in_dir(const char *dir_path); -int _media_svc_get_thumbnail_path(media_svc_storage_type_e storage_type, media_svc_media_type_e media_type, char *thumb_path, const char *pathname, const char *img_format, uid_t uid); +int _media_svc_remove_dir(media_svc_storage_type_e storage_type, const char *dir_path); +int _media_svc_get_thumbnail_path(const char *storage_id, media_svc_storage_type_e storage_type, media_svc_media_type_e media_type, char *thumb_path, const char *pathname, const char *img_format, uid_t uid); int _media_svc_get_file_time(const char *full_path); int _media_svc_set_default_value(media_svc_content_info_s *content_info, bool refresh); int _media_svc_set_media_info(media_svc_content_info_s *content_info, const char *storage_id, media_svc_storage_type_e storage_type, @@ -62,7 +62,7 @@ int _media_svc_extract_image_metadata(sqlite3 *handle, media_svc_content_info_s int _media_svc_extract_media_metadata(sqlite3 *handle, media_svc_content_info_s *content_info, uid_t uid); time_t __media_svc_get_timeline_from_str(const char *timstr); void _media_svc_destroy_content_info(media_svc_content_info_s *content_info); -int _media_svc_create_thumbnail(const char *path, char *thumb_path, int max_length, media_svc_media_type_e media_type, uid_t uid); +int _media_svc_create_thumbnail(const char *storage_id, const char *path, char *thumb_path, int max_length, media_svc_media_type_e media_type, uid_t uid); int _media_svc_get_pinyin_str(const char *src_str, char **pinyin_str); bool _media_svc_check_pinyin_support(void); int _media_svc_extract_music_metadata_for_update(sqlite3 *handle, media_svc_content_info_s *content_info, media_svc_media_type_e media_type);