From: chen89.chen Date: Wed, 21 Mar 2018 08:06:25 +0000 (+0800) Subject: add plugin api , folder scan should only delete invalid in folder instead of delete... X-Git-Tag: accepted/tizen/unified/20180322.060218^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=cd0937363012ce2a47261b3d98e36991d1f34d04;p=platform%2Fcore%2Fmultimedia%2Fmedia-server.git add plugin api , folder scan should only delete invalid in folder instead of delete invalid in storage Change-Id: Iae68637a9ad3d89d3a8321de2a4fd60a2f9a3952 --- diff --git a/src/common/include/media-common-db-svc.h b/src/common/include/media-common-db-svc.h index 87a17f6..d2f315b 100755 --- a/src/common/include/media-common-db-svc.h +++ b/src/common/include/media-common-db-svc.h @@ -71,6 +71,7 @@ typedef int (*SET_ITEM_VALIDITY)(void *, const char *, const char *, int, int, u typedef int (*DELETE_ITEM)(void *, const char *, const char *, uid_t, char **); typedef int (*DELETE_ALL_ITEMS_IN_STORAGE)(void *, const char *, int, uid_t, char **); typedef int (*DELETE_ALL_INVALID_ITMES_IN_STORAGE)(void *, const char *, int, uid_t, char **); +typedef int (*DELETE_ALL_INVALID_ITEMS_IN_FOLDER)(void *, const char *, const char *, bool, uid_t, char**); typedef int (*UPDATE_FOLDER_TIME)(void *, const char *, const char *, uid_t, char **); typedef int (*GET_STORAGE_ID)(void *, const char *, char *, uid_t uid, char **); typedef int (*SET_STORAGE_SCAN_STATUS)(void *, const char *, int, uid_t, char **); @@ -101,6 +102,7 @@ typedef int (*UPDATE_ITEM_META)(void *, const char *, const char *, int, uid_t, typedef int (*UPDATE_ITEM_BEGIN)(void *, int, char **); typedef int (*UPDATE_ITEM_END)(void *, uid_t, char **); +typedef int (*DELETE_INVALID_FOLDER_BY_PATH)(void *, const char *, const char *, uid_t, char **); typedef int (*CHECK_FOLDER_EXIST)(void*, const char*, const char*, char **); typedef int (*GET_FOLDER_ID)(void *, const char *, const char *, char *, char **); typedef int (*GET_EXTRACT_LIST)(void*, const char*, int, int, const char*, int, uid_t, void*, char**); @@ -120,6 +122,7 @@ bool ms_delete_all_items(void **handle, const char *storage_id, ms_user_storage_ int ms_validaty_change_all_items(void **handle, const char *storage_id, ms_user_storage_type_e storage_type, bool validity, uid_t uid); bool ms_delete_invalid_items(void **handle, const char *storage_id, ms_user_storage_type_e storage_type, uid_t uid); int ms_set_folder_item_validity(void **handle, const char *storage_id, const char *path, int validity, int recursive, uid_t uid); +int ms_delete_invalid_items_in_folder(void **handle, const char *storage_id, const char *path, bool is_recursive, uid_t uid); int ms_send_dir_update_noti(void **handle, const char *storage_id, const char *path, const char *folder_id, ms_noti_type_e noti_type, int pid); int ms_update_folder_time(void **handle, const char *storage_id, char *folder_path, uid_t uid); int ms_get_storage_id(void **handle, const char *path, char *storage_id, uid_t uid); @@ -146,6 +149,7 @@ int ms_delete_storage(void **handle, const char *storage_id, uid_t uid); int ms_set_storage_validity(void **handle, const char *storage_id, int validity, uid_t uid); int ms_set_all_storage_validity(void **handle, int validity, uid_t uid); int ms_update_meta_batch(void **handle, const char *path, const char *storage_id, uid_t uid); +int ms_delete_invalid_folder_by_path(void **handle, const char *storage_id, const char *folder_path, uid_t uid); int ms_check_folder_exist(void **handle, const char *storage_id, const char *folder_path); int ms_get_folder_id(void **handle, const char *storage_id, const char *path, char **folder_id); int ms_get_media_type(void **handle, const char *path, int *media_type); diff --git a/src/common/media-common-db-svc.c b/src/common/media-common-db-svc.c index 7d190f3..20c4220 100755 --- a/src/common/media-common-db-svc.c +++ b/src/common/media-common-db-svc.c @@ -57,6 +57,7 @@ enum func_list { eDELETE_INVALID_ITEMS, eSET_FOLDER_ITEM_VALIDITY, eINSERT_BURST, + eDELETE_FOLDER, eSEND_DIR_UPDATE_NOTI, eDELETE_ITEM, eUPDATE_FOLDER_TIME, @@ -85,6 +86,7 @@ enum func_list { eUPDATE_ITEM_META, eUPDATE_ITEM_BEGIN, eUPDATE_ITEM_END, + eDELETE_INVALID_FOLDER_BY_PATH, eCHECK_FOLDER_EXIST, eGET_FOLDER_ID, eGET_MEDIA_TYPE, @@ -166,6 +168,7 @@ int ms_load_functions(void) "delete_all_invalid_items_in_storage", "set_folder_item_validity", "insert_burst_item", + "delete_all_invalid_items_in_folder", "send_dir_update_noti", "delete_item", "update_folder_time", @@ -194,6 +197,7 @@ int ms_load_functions(void) "update_item_meta", "update_item_begin", "update_item_end", + "delete_invalid_folder_by_path", "check_folder_exist", "get_folder_id", "get_media_type", @@ -685,6 +689,24 @@ int ms_set_folder_item_validity(void **handle, const char *storage_id, const cha return MS_MEDIA_ERR_NONE; } +int ms_delete_invalid_items_in_folder(void **handle, const char* storage_id, const char*path, bool is_recursive, uid_t uid) +{ + int lib_index; + int ret; + char *err_msg = NULL; + + for (lib_index = 0; lib_index < lib_num; lib_index++) { + ret = ((DELETE_ALL_INVALID_ITEMS_IN_FOLDER)func_array[lib_index][eDELETE_FOLDER])(handle[lib_index], storage_id, path, is_recursive, uid, &err_msg); /*dlopen*/ + if (ret != 0) { + MS_DBG_ERR("error : %s [%s]", g_array_index(so_array, char*, lib_index), err_msg); + MS_SAFE_FREE(err_msg); + return MS_MEDIA_ERR_DB_UPDATE_FAIL; + } + } + + return MS_MEDIA_ERR_NONE; +} + int ms_send_dir_update_noti(void **handle, const char* storage_id, const char*path, const char*folder_id, ms_noti_type_e noti_type, int pid) { int lib_index; @@ -1098,6 +1120,25 @@ int ms_update_meta_batch(void **handle, const char *path, const char *storage_id return res; } +int ms_delete_invalid_folder_by_path(void **handle, const char *storage_id, const char *folder_path, uid_t uid) +{ + int lib_index; + int res = MS_MEDIA_ERR_NONE; + int ret; + char *err_msg = NULL; + + for (lib_index = 0; lib_index < lib_num; lib_index++) { + ret = ((DELETE_INVALID_FOLDER_BY_PATH)func_array[lib_index][eDELETE_INVALID_FOLDER_BY_PATH])(handle[lib_index], storage_id, folder_path, uid, &err_msg); /*dlopen*/ + if (ret != 0) { + MS_DBG_ERR("error : %s [%s] %s", g_array_index(so_array, char*, lib_index), err_msg, storage_id); + MS_SAFE_FREE(err_msg); + res = MS_MEDIA_ERR_DB_INSERT_FAIL; + } + } + + return res; +} + int ms_check_folder_exist(void **handle, const char *storage_id, const char *folder_path) { int lib_index; diff --git a/src/scanner-v2/media-scanner-scan-v2.c b/src/scanner-v2/media-scanner-scan-v2.c index adcd88c..43cbd9d 100755 --- a/src/scanner-v2/media-scanner-scan-v2.c +++ b/src/scanner-v2/media-scanner-scan-v2.c @@ -1079,6 +1079,7 @@ gboolean msc_directory_scan_thread(void *data) ms_dir_scan_status_e scan_status = MS_DIR_SCAN_NONE; ms_noti_type_e noti_type = MS_ITEM_INSERT; char *folder_uuid = NULL; + bool is_recursive = true; uid_t uid = MEDIA_DEFAULT_UID; while (1) { @@ -1143,6 +1144,7 @@ gboolean msc_directory_scan_thread(void *data) ms_trim_dir_path(scan_data->msg); if (g_file_test(scan_data->msg, G_FILE_TEST_IS_DIR)) { + is_recursive = (scan_type == MS_MSG_DIRECTORY_SCANNING_NON_RECURSIVE) ? false : true; if (ms_check_folder_exist(handle, storage_id, scan_data->msg) == MS_MEDIA_ERR_NONE) { /*already exist in media DB*/ noti_type = MS_ITEM_UPDATE; @@ -1153,6 +1155,7 @@ gboolean msc_directory_scan_thread(void *data) } } else { /*directory is deleted*/ + is_recursive = true; noti_type = MS_ITEM_DELETE; scan_type = MS_MSG_DIRECTORY_SCANNING; scan_data->msg_type = MS_MSG_DIRECTORY_SCANNING; @@ -1269,11 +1272,16 @@ gboolean msc_directory_scan_thread(void *data) __msc_call_dir_scan_cb(); /*delete invalid folder first, then delete invalid item, avoid to folder was deleted but item not when unmount*/ - if (ms_delete_invalid_folder(handle, storage_id, storage_type, scan_data->uid) != MS_MEDIA_ERR_NONE) + /*if (ms_delete_invalid_folder(handle, storage_id, storage_type, scan_data->uid) != MS_MEDIA_ERR_NONE) MS_DBG_ERR("deleting invalid folders in storage failed"); if (!ms_delete_invalid_items(handle, storage_id, storage_type, scan_data->uid)) - MS_DBG_ERR("deleting invalid items in storage failed"); + MS_DBG_ERR("deleting invalid items in storage failed");*/ + + /*revert to 3.0,folder scan should only delete invalid in folder instead of delete invalid in storage*/ + if (ms_delete_invalid_items_in_folder(handle, storage_id, scan_data->msg, is_recursive, uid) != MS_MEDIA_ERR_NONE) { + MS_DBG_ERR("deleting invalid items in folder failed"); + } /*if (ret != MS_MEDIA_ERR_SCANNER_FORCE_STOP) { ms_send_dir_update_noti(handle, storage_id, scan_data->msg, folder_uuid, noti_type, scan_data->pid); @@ -1282,6 +1290,12 @@ gboolean msc_directory_scan_thread(void *data) SCAN_DONE: MS_DBG_WARN("storage_id = [%s], dir Path = [%.*s], pid = [%d]", storage_id, MAX_MSG_SIZE, scan_data->msg, scan_data->pid); if (ret != MS_MEDIA_ERR_SCANNER_FORCE_STOP) { + /*remove invalid folder in folder table.*/ + if (is_recursive == true) { + if (ms_delete_invalid_folder_by_path(handle, storage_id, scan_data->msg, uid) != MS_MEDIA_ERR_NONE) { + MS_DBG_ERR("deleting invalid folder failed"); + } + } if (noti_type == MS_ITEM_DELETE) { ms_send_dir_update_noti(handle, storage_id, scan_data->msg, folder_uuid, noti_type, scan_data->pid); }