Improve msc_metadata_update
[platform/core/multimedia/libmedia-service.git] / src / common / media-svc.c
index abc7af9..1e81ccc 100755 (executable)
@@ -38,14 +38,8 @@ static __thread int g_media_svc_item_validity_cur_data_cnt = 0;
 static __thread int g_media_svc_insert_item_data_cnt = 1;
 static __thread int g_media_svc_insert_item_cur_data_cnt = 0;
 
-static __thread int g_media_svc_update_item_data_cnt = 1;
-static __thread int g_media_svc_update_item_cur_data_cnt = 0;
-
-static __thread int g_media_svc_insert_folder_data_cnt = 1;
-static __thread int g_media_svc_insert_folder_cur_data_cnt = 0;
-
 /* Flag for items to be published by notification */
-static __thread int g_insert_with_noti = FALSE;
+static __thread bool g_insert_with_noti = false;
 
 #define BATCH_REQUEST_MAX 300
 
@@ -187,10 +181,8 @@ int media_svc_get_modified_time(sqlite3 *handle, const char *storage_id, const c
        return _media_svc_get_modified_time(handle, storage_id, path, modified_time);
 }
 
-int media_svc_insert_item_begin(int data_cnt, int with_noti, int from_pid)
+int media_svc_insert_item_begin(int data_cnt, bool with_noti, int from_pid)
 {
-       media_svc_debug("Transaction data count : [%d]", data_cnt);
-
        media_svc_retvm_if(data_cnt < 1, MS_MEDIA_ERR_INVALID_PARAMETER, "data_cnt shuld be bigger than 1");
 
        g_media_svc_insert_item_data_cnt = data_cnt;
@@ -203,7 +195,7 @@ int media_svc_insert_item_begin(int data_cnt, int with_noti, int from_pid)
                        return MS_MEDIA_ERR_OUT_OF_MEMORY;
 
                _media_svc_set_noti_from_pid(from_pid);
-               g_insert_with_noti = TRUE;
+               g_insert_with_noti = true;
        }
 
        return MS_MEDIA_ERR_NONE;
@@ -222,7 +214,7 @@ int media_svc_insert_item_end(uid_t uid)
                        media_svc_debug("sending noti list");
                        _media_svc_publish_noti_list(g_media_svc_insert_item_cur_data_cnt);
                        _media_svc_destroy_noti_list(g_media_svc_insert_item_cur_data_cnt);
-                       g_insert_with_noti = FALSE;
+                       g_insert_with_noti = false;
                        _media_svc_set_noti_from_pid(-1);
                }
        }
@@ -237,35 +229,34 @@ int media_svc_insert_item_bulk(sqlite3 *handle, const char *storage_id, ms_user_
 {
        int ret = MS_MEDIA_ERR_NONE;
        char folder_uuid[MEDIA_SVC_UUID_SIZE + 1] = {0, };
-       media_svc_media_type_e media_type;
 
        media_svc_retvm_if(handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
        media_svc_retvm_if(!STRING_VALID(storage_id), MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
        media_svc_retvm_if(!STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
-       media_svc_retvm_if(_media_svc_check_storage_type(storage_type) != TRUE, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid storage_type");
+       media_svc_retvm_if(!_media_svc_is_valid_storage_type(storage_type), MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid storage_type");
 
        media_svc_content_info_s content_info;
        memset(&content_info, 0, sizeof(media_svc_content_info_s));
 
        /*Set media info*/
        /* if drm_contentinfo is not NULL, the file is OMA DRM.*/
-       ret = _media_svc_set_media_info(&content_info, storage_id, storage_type, path, &media_type, FALSE);
+       ret = _media_svc_set_media_info(&content_info, storage_id, storage_type, path, false);
        if (ret != MS_MEDIA_ERR_NONE)
                return ret;
 
-       if (media_type == MEDIA_SVC_MEDIA_TYPE_OTHER
-       || (media_type == MEDIA_SVC_MEDIA_TYPE_PVR)
-       || (media_type == MEDIA_SVC_MEDIA_TYPE_UHD)
-       || (media_type == MEDIA_SVC_MEDIA_TYPE_SCSA))
-               media_svc_debug("Do nothing[%d]", media_type);
-       else if (media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE)
+       if (content_info.media_type == MEDIA_SVC_MEDIA_TYPE_OTHER
+       || (content_info.media_type == MEDIA_SVC_MEDIA_TYPE_PVR)
+       || (content_info.media_type == MEDIA_SVC_MEDIA_TYPE_UHD)
+       || (content_info.media_type == MEDIA_SVC_MEDIA_TYPE_SCSA))
+               media_svc_debug("Do nothing[%d]", content_info.media_type);
+       else if (content_info.media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE)
                ret = _media_svc_extract_image_metadata(&content_info);
        else
-               ret = _media_svc_extract_media_metadata(handle, &content_info, uid);
+               ret = _media_svc_extract_media_metadata(handle, true, &content_info, uid);
        media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);
 
        /*Set or Get folder id*/
-       ret = _media_svc_get_and_append_folder_id_by_path(handle, storage_id, path, storage_type, folder_uuid, uid);
+       ret = _media_svc_get_and_append_folder_id_by_path(handle, true, storage_id, path, storage_type, folder_uuid, uid);
        media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);
 
        content_info.folder_uuid = g_strdup(folder_uuid);
@@ -273,7 +264,7 @@ int media_svc_insert_item_bulk(sqlite3 *handle, const char *storage_id, ms_user_
 
        if (g_media_svc_insert_item_data_cnt == 1) {
 
-               ret = _media_svc_insert_item_with_data(handle, storage_id, &content_info, FALSE, uid);
+               ret = _media_svc_insert_item_with_data(true, storage_id, &content_info, false, uid);
                media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);
 
                if (g_insert_with_noti)
@@ -281,7 +272,7 @@ int media_svc_insert_item_bulk(sqlite3 *handle, const char *storage_id, ms_user_
 
        } else if (g_media_svc_insert_item_cur_data_cnt < (g_media_svc_insert_item_data_cnt - 1)) {
 
-               ret = _media_svc_insert_item_with_data(handle, storage_id, &content_info, TRUE, uid);
+               ret = _media_svc_insert_item_with_data(true, storage_id, &content_info, true, uid);
                media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);
 
                if (g_insert_with_noti)
@@ -291,7 +282,7 @@ int media_svc_insert_item_bulk(sqlite3 *handle, const char *storage_id, ms_user_
 
        } else if (g_media_svc_insert_item_cur_data_cnt == (g_media_svc_insert_item_data_cnt - 1)) {
 
-               ret = _media_svc_insert_item_with_data(handle, storage_id, &content_info, TRUE, uid);
+               ret = _media_svc_insert_item_with_data(true, storage_id, &content_info, true, uid);
                media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);
 
                if (g_insert_with_noti)
@@ -326,36 +317,35 @@ int media_svc_insert_item_immediately(sqlite3 *handle, const char *storage_id, m
 {
        int ret = MS_MEDIA_ERR_NONE;
        char folder_uuid[MEDIA_SVC_UUID_SIZE + 1] = {0, };
-       media_svc_media_type_e media_type;
 
        media_svc_retvm_if(handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
        media_svc_retvm_if(!STRING_VALID(storage_id), MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
        media_svc_retvm_if(!STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
-       media_svc_retvm_if(_media_svc_check_storage_type(storage_type) != TRUE, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid storage_type");
+       media_svc_retvm_if(!_media_svc_is_valid_storage_type(storage_type), MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid storage_type");
 
        media_svc_content_info_s content_info;
        memset(&content_info, 0, sizeof(media_svc_content_info_s));
 
        /*Set media info*/
-       ret = _media_svc_set_media_info(&content_info, storage_id, storage_type, path, &media_type, FALSE);
+       ret = _media_svc_set_media_info(&content_info, storage_id, storage_type, path, false);
        if (ret != MS_MEDIA_ERR_NONE)
                return ret;
 
-       if (media_type == MEDIA_SVC_MEDIA_TYPE_OTHER
-       || (media_type == MEDIA_SVC_MEDIA_TYPE_PVR)
-       || (media_type == MEDIA_SVC_MEDIA_TYPE_UHD)
-       || (media_type == MEDIA_SVC_MEDIA_TYPE_SCSA)) {
+       if (content_info.media_type == MEDIA_SVC_MEDIA_TYPE_OTHER
+       || (content_info.media_type == MEDIA_SVC_MEDIA_TYPE_PVR)
+       || (content_info.media_type == MEDIA_SVC_MEDIA_TYPE_UHD)
+       || (content_info.media_type == MEDIA_SVC_MEDIA_TYPE_SCSA)) {
                /*Do nothing.*/
-       } else if (media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE) {
+       } else if (content_info.media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE) {
                ret = _media_svc_extract_image_metadata(&content_info);
        } else {
-               ret = _media_svc_extract_media_metadata(handle, &content_info, uid);
+               ret = _media_svc_extract_media_metadata(handle, false, &content_info, uid);
        }
 
        media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);
 
        /*Set or Get folder id*/
-       ret = _media_svc_get_and_append_folder_id_by_path(handle, storage_id, path, storage_type, folder_uuid, uid);
+       ret = _media_svc_get_and_append_folder_id_by_path(handle, false, storage_id, path, storage_type, folder_uuid, uid);
        media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);
 
        content_info.folder_uuid = g_strdup(folder_uuid);
@@ -363,20 +353,20 @@ int media_svc_insert_item_immediately(sqlite3 *handle, const char *storage_id, m
 
        /* Extracting thumbnail */
        if (content_info.thumbnail_path == NULL) {
-               if (media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE || media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO) {
+               if (content_info.media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE || content_info.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.path, thumb_path, content_info.media_type, uid);
                        if (ret == MS_MEDIA_ERR_NONE)
                                content_info.thumbnail_path = g_strdup(thumb_path);
                }
        }
 
-       ret = _media_svc_insert_item_with_data(handle, storage_id, &content_info, FALSE, uid);
+       ret = _media_svc_insert_item_with_data(false, storage_id, &content_info, false, uid);
 
        if (ret == MS_MEDIA_ERR_NONE) {
                media_svc_debug("Insertion is successful. Sending noti for this");
-               _media_svc_publish_noti(MS_MEDIA_ITEM_FILE, MS_MEDIA_ITEM_INSERT, content_info.path, content_info.media_type, content_info.media_uuid, content_info.mime_type);
+               _media_svc_publish_noti(MS_MEDIA_ITEM_INSERT, content_info.path, content_info.media_type, content_info.media_uuid, content_info.mime_type);
        } else if (ret == MS_MEDIA_ERR_DB_CONSTRAINT_FAIL) {
                media_svc_error("This item is already inserted. This may be normal operation because other process already did this");
        }
@@ -385,7 +375,13 @@ int media_svc_insert_item_immediately(sqlite3 *handle, const char *storage_id, m
        return ret;
 }
 
-int media_svc_move_item(sqlite3 *handle, const char *src_path, const char *dest_path, uid_t uid)
+int media_svc_move_item(sqlite3 *handle,
+                                                               const char *src_path,
+                                                               const char *dest_path,
+                                                               const char *media_id,
+                                                               int media_type,
+                                                               const char *mime_type,
+                                                               uid_t uid)
 {
        int ret = MS_MEDIA_ERR_NONE;
        char *file_name = NULL;
@@ -397,13 +393,14 @@ int media_svc_move_item(sqlite3 *handle, const char *src_path, const char *dest_
        char dst_stg_id[MEDIA_SVC_UUID_SIZE + 1] = {0, };
        ms_user_storage_type_e org_stg_type = MS_USER_STORAGE_INTERNAL;
        ms_user_storage_type_e dst_stg_type = MS_USER_STORAGE_INTERNAL;
-       int media_type = -1;
 
        media_svc_debug_fenter();
 
        media_svc_retvm_if(handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
        media_svc_retvm_if(!STRING_VALID(src_path), MS_MEDIA_ERR_INVALID_PARAMETER, "src_path is NULL");
        media_svc_retvm_if(!STRING_VALID(dest_path), MS_MEDIA_ERR_INVALID_PARAMETER, "dest_path is NULL");
+       media_svc_retvm_if(!STRING_VALID(media_id), MS_MEDIA_ERR_INVALID_PARAMETER, "media_id is NULL");
+       media_svc_retvm_if(!STRING_VALID(mime_type), MS_MEDIA_ERR_INVALID_PARAMETER, "mime_type is NULL");
 
        /* Get storage_id */
        ret = _media_svc_get_storage_uuid(handle, src_path, org_stg_id, uid);
@@ -417,7 +414,7 @@ int media_svc_move_item(sqlite3 *handle, const char *src_path, const char *dest_
        media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
 
        /*check and update folder*/
-       ret = _media_svc_get_and_append_folder_id_by_path(handle, dst_stg_id, dest_path, dst_stg_type, folder_uuid, uid);
+       ret = _media_svc_get_and_append_folder_id_by_path(handle, false, dst_stg_id, dest_path, dst_stg_type, folder_uuid, uid);
        media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
 
        /*get filename*/
@@ -426,13 +423,6 @@ int media_svc_move_item(sqlite3 *handle, const char *src_path, const char *dest_
        /*get modified_time*/
        modified_time = _media_svc_get_file_time(dest_path);
 
-       ret = _media_svc_get_media_type_by_path(handle, org_stg_id, src_path, &media_type);
-       if (ret != MS_MEDIA_ERR_NONE) {
-               media_svc_error("_media_svc_get_media_type_by_path failed");
-               SAFE_FREE(file_name);
-               return ret;
-       }
-
        /*get old thumbnail_path and remove thumbnail */
        ret = _media_svc_get_thumbnail_path_by_path(handle, src_path, old_thumb_path);
        if ((ret != MS_MEDIA_ERR_NONE) && (ret != MS_MEDIA_ERR_DB_NO_RECORD)) {
@@ -453,15 +443,7 @@ int media_svc_move_item(sqlite3 *handle, const char *src_path, const char *dest_
        media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
 
        media_svc_debug("Move is successful. Sending noti for this");
-
-       /* Get notification info */
-       media_svc_noti_item *noti_item = NULL;
-       ret = _media_svc_get_noti_info(handle, dst_stg_id, dest_path, MS_MEDIA_ITEM_FILE, &noti_item);
-       media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
-
-       /* Send notification for move */
-       _media_svc_publish_noti(MS_MEDIA_ITEM_FILE, MS_MEDIA_ITEM_UPDATE, src_path, media_type, noti_item->media_uuid, noti_item->mime_type);
-       _media_svc_destroy_noti_item(noti_item);
+       _media_svc_publish_noti(MS_MEDIA_ITEM_UPDATE, src_path, media_type, media_id, mime_type);
 
        /*update folder modified_time*/
        folder_path = g_path_get_dirname(dest_path);
@@ -505,18 +487,18 @@ int media_svc_set_item_validity(const char *storage_id, const char *path, int va
 
        if (g_media_svc_item_validity_data_cnt == 1) {
 
-               return _media_svc_update_item_validity(storage_id, path, validity, FALSE, uid);
+               return _media_svc_update_item_validity(storage_id, path, validity, false, uid);
 
        } else if (g_media_svc_item_validity_cur_data_cnt < (g_media_svc_item_validity_data_cnt - 1)) {
 
-               ret = _media_svc_update_item_validity(storage_id, path, validity, TRUE, uid);
+               ret = _media_svc_update_item_validity(storage_id, path, validity, true, uid);
                media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
 
                g_media_svc_item_validity_cur_data_cnt++;
 
        } else if (g_media_svc_item_validity_cur_data_cnt == (g_media_svc_item_validity_data_cnt - 1)) {
 
-               ret = _media_svc_update_item_validity(storage_id, path, validity, TRUE, uid);
+               ret = _media_svc_update_item_validity(storage_id, path, validity, true, uid);
                media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
 
                ret = _media_svc_list_query_do(MEDIA_SVC_QUERY_SET_ITEM_VALIDITY, uid);
@@ -537,46 +519,32 @@ int media_svc_delete_item_by_path(sqlite3 *handle, const char *storage_id, const
 {
        int ret = MS_MEDIA_ERR_NONE;
        char thumb_path[MEDIA_SVC_PATHNAME_SIZE] = {0, };
+       media_svc_noti_item *noti_item = NULL;
 
        media_svc_debug_fenter();
 
-       int media_type = -1;
-       ret = _media_svc_get_media_type_by_path(handle, storage_id, path, &media_type);
-       media_svc_retv_if((ret != MS_MEDIA_ERR_NONE), ret);
-
        /*Get thumbnail path to delete*/
        ret = _media_svc_get_thumbnail_path_by_path(handle, path, thumb_path);
        media_svc_retv_if((ret != MS_MEDIA_ERR_NONE) && (ret != MS_MEDIA_ERR_DB_NO_RECORD), ret);
 
-       if (g_media_svc_insert_item_data_cnt == 1) {
-
-               /* Get notification info */
-               media_svc_noti_item *noti_item = NULL;
-               ret = _media_svc_get_noti_info(handle, storage_id, path, MS_MEDIA_ITEM_FILE, &noti_item);
-               media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
-
-               /*Delete item*/
-               ret = _media_svc_delete_item_by_path(storage_id, path, FALSE, uid);
-               if (ret != MS_MEDIA_ERR_NONE) {
-                       media_svc_error("_media_svc_delete_item_by_path failed : %d", ret);
-                       _media_svc_destroy_noti_item(noti_item);
-
-                       return ret;
-               }
+       /* Get notification info */
+       ret = _media_svc_get_noti_info(handle, storage_id, path, &noti_item);
+       media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
 
-               /* Send notification */
-               media_svc_debug("Deletion is successful. Sending noti for this");
-               _media_svc_publish_noti(MS_MEDIA_ITEM_FILE, MS_MEDIA_ITEM_DELETE, path, media_type, noti_item->media_uuid, noti_item->mime_type);
+       /*Delete item*/
+       ret = _media_svc_delete_item_by_path(storage_id, path, uid);
+       if (ret != MS_MEDIA_ERR_NONE) {
+               media_svc_error("_media_svc_delete_item_by_path failed : %d", ret);
                _media_svc_destroy_noti_item(noti_item);
-       } else {
-               ret = _media_svc_delete_item_by_path(storage_id, path, TRUE, uid);
-               if (ret != MS_MEDIA_ERR_NONE) {
-                       media_svc_error("_media_svc_delete_item_by_path failed : %d", ret);
-                       return ret;
-               }
 
+               return ret;
        }
 
+       /* Send notification */
+       media_svc_debug("Deletion is successful. Sending noti for this");
+       _media_svc_publish_noti(MS_MEDIA_ITEM_DELETE, path, noti_item->media_type, noti_item->media_uuid, noti_item->mime_type);
+       _media_svc_destroy_noti_item(noti_item);
+
        /*Delete thumbnail*/
        if (STRING_VALID(thumb_path)) {
                ret = _media_svc_remove_file(thumb_path);
@@ -587,22 +555,21 @@ int media_svc_delete_item_by_path(sqlite3 *handle, const char *storage_id, const
        return MS_MEDIA_ERR_NONE;
 }
 
-int media_svc_refresh_item(sqlite3 *handle, const char *storage_id, ms_user_storage_type_e storage_type, const char *path, uid_t uid)
+int media_svc_refresh_item(sqlite3 *handle, bool is_direct, const char *storage_id, ms_user_storage_type_e storage_type, const char *path, uid_t uid)
 {
        int ret = MS_MEDIA_ERR_NONE;
-       media_svc_media_type_e media_type;
        char thumb_path[MEDIA_SVC_PATHNAME_SIZE + 1] = {0, };
 
        media_svc_retvm_if(handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
        media_svc_retvm_if(!STRING_VALID(storage_id), MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
        media_svc_retvm_if(!STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
-       media_svc_retvm_if(_media_svc_check_storage_type(storage_type) != TRUE, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid storage_type");
+       media_svc_retvm_if(!_media_svc_is_valid_storage_type(storage_type), MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid storage_type");
 
        media_svc_content_info_s content_info;
        memset(&content_info, 0, sizeof(media_svc_content_info_s));
 
        /*Set media info*/
-       ret = _media_svc_set_media_info(&content_info, storage_id, storage_type, path, &media_type, TRUE);
+       ret = _media_svc_set_media_info(&content_info, storage_id, storage_type, path, true);
        if (ret != MS_MEDIA_ERR_NONE)
                return ret;
 
@@ -629,24 +596,23 @@ int media_svc_refresh_item(sqlite3 *handle, const char *storage_id, ms_user_stor
 
        /* Get notification info */
        media_svc_noti_item *noti_item = NULL;
-       ret = _media_svc_get_noti_info(handle, storage_id, path, MS_MEDIA_ITEM_FILE, &noti_item);
+       ret = _media_svc_get_noti_info(handle, storage_id, path, &noti_item);
        if (ret != MS_MEDIA_ERR_NONE) {
                _media_svc_destroy_content_info(&content_info);
                return ret;
        }
 
-       media_type = noti_item->media_type;
-       content_info.media_type = media_type;
+       content_info.media_type = noti_item->media_type;
 
-       if (media_type == MEDIA_SVC_MEDIA_TYPE_OTHER
-       || (media_type == MEDIA_SVC_MEDIA_TYPE_PVR)
-       || (media_type == MEDIA_SVC_MEDIA_TYPE_UHD)
-       || (media_type == MEDIA_SVC_MEDIA_TYPE_SCSA))
-               media_svc_debug("Do nothing [%d]", media_type);
-       else if (media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE)
+       if (content_info.media_type == MEDIA_SVC_MEDIA_TYPE_OTHER
+       || (content_info.media_type == MEDIA_SVC_MEDIA_TYPE_PVR)
+       || (content_info.media_type == MEDIA_SVC_MEDIA_TYPE_UHD)
+       || (content_info.media_type == MEDIA_SVC_MEDIA_TYPE_SCSA))
+               media_svc_debug("Do nothing [%d]", content_info.media_type);
+       else if (content_info.media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE)
                ret = _media_svc_extract_image_metadata(&content_info);
        else
-               ret = _media_svc_extract_media_metadata(handle, &content_info, uid);
+               ret = _media_svc_extract_media_metadata(handle, is_direct, &content_info, uid);
 
        if (ret != MS_MEDIA_ERR_NONE) {
                _media_svc_destroy_noti_item(noti_item);
@@ -656,20 +622,20 @@ int media_svc_refresh_item(sqlite3 *handle, const char *storage_id, ms_user_stor
 
        /* Extracting thumbnail */
        if (content_info.thumbnail_path == NULL) {
-               if (media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE || media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO) {
+               if (content_info.media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE || content_info.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.path, thumb_path, content_info.media_type, uid);
                        if (ret == MS_MEDIA_ERR_NONE)
                                content_info.thumbnail_path = g_strdup(thumb_path);
                }
        }
 
-       ret = _media_svc_update_item_with_data(storage_id, &content_info, uid);
+       ret = _media_svc_update_item_with_data(is_direct, storage_id, &content_info, uid);
 
        if (ret == MS_MEDIA_ERR_NONE) {
                media_svc_debug("Update is successful. Sending noti for this");
-               _media_svc_publish_noti(MS_MEDIA_ITEM_FILE, MS_MEDIA_ITEM_UPDATE, content_info.path, noti_item->media_type, noti_item->media_uuid, noti_item->mime_type);
+               _media_svc_publish_noti(MS_MEDIA_ITEM_UPDATE, content_info.path, noti_item->media_type, noti_item->media_uuid, noti_item->mime_type);
        } else {
                media_svc_error("_media_svc_update_item_with_data failed : %d", ret);
        }
@@ -680,36 +646,11 @@ int media_svc_refresh_item(sqlite3 *handle, const char *storage_id, ms_user_stor
        return ret;
 }
 
-int media_svc_send_dir_update_noti(sqlite3 *handle, const char *storage_id, const char *dir_path, const char *folder_id, media_item_update_type_e update_type, int pid)
+int media_svc_send_dir_update_noti(const char *dir_path, const char *folder_id, media_item_update_type_e update_type, int pid)
 {
-       int ret = MS_MEDIA_ERR_NONE;
-       char *uuid = NULL;
-
-       media_svc_retvm_if(handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
        media_svc_retvm_if(!STRING_VALID(dir_path), MS_MEDIA_ERR_INVALID_PARAMETER, "dir_path is NULL");
 
-       /* Get notification info */
-       media_svc_noti_item *noti_item = NULL;
-       ret = _media_svc_get_noti_info(handle, storage_id, dir_path, MS_MEDIA_ITEM_DIRECTORY, &noti_item);
-       media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
-
-       if (folder_id != NULL) {
-               uuid = strndup(folder_id, strlen(folder_id));
-       } else {
-               if (noti_item->media_uuid != NULL) {
-                       uuid = strndup(noti_item->media_uuid, strlen(noti_item->media_uuid));
-               } else {
-                       _media_svc_destroy_noti_item(noti_item);
-                       media_svc_error("folder uuid is wrong");
-                       return MS_MEDIA_ERR_DB_INTERNAL;
-               }
-       }
-
-       ret = _media_svc_publish_dir_noti_v2(MS_MEDIA_ITEM_DIRECTORY, update_type, dir_path, -1, uuid, NULL, pid);
-       _media_svc_destroy_noti_item(noti_item);
-       SAFE_FREE(uuid);
-
-       return ret;
+       return _media_svc_publish_dir_noti(update_type, dir_path, folder_id, pid);
 }
 
 int media_svc_check_db_upgrade(sqlite3 *handle, int user_version, uid_t uid)
@@ -719,93 +660,91 @@ int media_svc_check_db_upgrade(sqlite3 *handle, int user_version, uid_t uid)
        return _media_svc_check_db_upgrade(handle, user_version, uid);
 }
 
-int media_svc_update_item_begin(int data_cnt)
+static void __media_svc_noti_all_storage(sqlite3 *handle, uid_t uid)
 {
-       media_svc_debug("Transaction data count : [%d]", data_cnt);
-
-       media_svc_retvm_if(data_cnt < 1, MS_MEDIA_ERR_INVALID_PARAMETER, "data_cnt shuld be bigger than 1");
+       int ret = MS_MEDIA_ERR_NONE;
+       char *root_path = NULL;
+       GArray *path_list = NULL;
 
-       g_media_svc_update_item_data_cnt = data_cnt;
-       g_media_svc_update_item_cur_data_cnt = 0;
+       ms_user_get_internal_root_path(uid, &root_path);
+       ret = _media_svc_publish_dir_noti(MS_MEDIA_ITEM_UPDATE, root_path, NULL, 0);
+       if (ret != MS_MEDIA_ERR_NONE)
+               media_svc_error("Fail to send noti");
 
-       return MS_MEDIA_ERR_NONE;
-}
+       SAFE_FREE(root_path);
 
-int media_svc_update_item_end(uid_t uid)
-{
-       int ret = MS_MEDIA_ERR_NONE;
+       path_list = g_array_new(FALSE, FALSE, sizeof(char *));
+       _media_svc_get_storage_path(handle, &path_list);
 
-       media_svc_debug_fenter();
+       while (path_list->len != 0) {
+               root_path = g_array_index(path_list , char *, 0);
+               g_array_remove_index(path_list, 0);
 
-       if (g_media_svc_update_item_cur_data_cnt > 0)
-               ret = _media_svc_list_query_do(MEDIA_SVC_QUERY_UPDATE_ITEM, uid);
+               ret = _media_svc_publish_dir_noti(MS_MEDIA_ITEM_UPDATE, root_path, NULL, 0);
+               if (ret != MS_MEDIA_ERR_NONE)
+                       media_svc_error("Fail to send noti");
 
-       g_media_svc_update_item_data_cnt = 1;
-       g_media_svc_update_item_cur_data_cnt = 0;
+               SAFE_FREE(root_path);
+       }
 
-       return ret;
+       g_array_free(path_list, false);
 }
 
-int media_svc_update_item_meta(const char *file_path, const char *storage_id, int storage_type, uid_t uid)
+int media_svc_update_item_meta(sqlite3 *handle, uid_t uid)
 {
        int ret = MS_MEDIA_ERR_NONE;
-       media_svc_media_type_e media_type;
+       /* NOTICE : After 6.0, change 'media_view' to 'media', add 'AND validity=1', and no need storage id */
+       char *sql = NULL;
        media_svc_content_info_s content_info;
-       memset(&content_info, 0, sizeof(media_svc_content_info_s));
+       media_svc_file_s *file_info = NULL;
+       GArray *path_list = NULL;
 
-       /*Set media info*/
-       ret = _media_svc_set_media_info(&content_info, storage_id, storage_type, file_path, &media_type, FALSE);
-       if (ret != MS_MEDIA_ERR_NONE)
-               return ret;
-
-       if (media_type == MEDIA_SVC_MEDIA_TYPE_MUSIC)
-               ret = _media_svc_extract_music_metadata_for_update(&content_info, media_type);
-       else {
-               _media_svc_destroy_content_info(&content_info);
-               return MS_MEDIA_ERR_NONE;
-       }
+       path_list = g_array_new(FALSE, FALSE, sizeof(media_svc_file_s *));
+       media_svc_retvm_if(!path_list, MS_MEDIA_ERR_OUT_OF_MEMORY, "Allocation failed");
 
+       sql = sqlite3_mprintf("SELECT media_path, storage_uuid FROM %q WHERE media_type=3", MEDIA_SVC_DB_VIEW_MEDIA);
+       ret = _media_svc_get_media(handle, sql, &path_list);
        if (ret != MS_MEDIA_ERR_NONE) {
-               _media_svc_destroy_content_info(&content_info);
+               media_svc_error("Fail to get media list");
+               g_array_free(path_list, false);
                return ret;
        }
 
-       if (g_media_svc_update_item_data_cnt == 1) {
-
-               ret = _media_svc_update_meta_with_data(&content_info);
-               media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);
+       while (path_list->len != 0) {
+               file_info = g_array_index(path_list, media_svc_file_s *, 0);
+               g_array_remove_index(path_list, 0);
 
-       } else if (g_media_svc_update_item_cur_data_cnt < (g_media_svc_update_item_data_cnt - 1)) {
-
-               ret = _media_svc_update_meta_with_data(&content_info);
-               media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);
-
-               g_media_svc_update_item_cur_data_cnt++;
-
-       } else if (g_media_svc_update_item_cur_data_cnt == (g_media_svc_update_item_data_cnt - 1)) {
+               memset(&content_info, 0, sizeof(media_svc_content_info_s));
+               ret = _media_svc_extract_music_metadata_for_update(&content_info, file_info->storage_id, file_info->path);
+               if (ret != MS_MEDIA_ERR_NONE) {
+                       media_svc_error("Fail to extract metadata");
+                       _media_svc_destroy_content_info(&content_info);
+                       SAFE_FREE(file_info);
+                       continue;
+               }
 
                ret = _media_svc_update_meta_with_data(&content_info);
-               media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);
-
-               ret = _media_svc_list_query_do(MEDIA_SVC_QUERY_UPDATE_ITEM, uid);
-               media_svc_retv_del_if(ret != MS_MEDIA_ERR_NONE, ret, &content_info);
-
-               g_media_svc_update_item_cur_data_cnt = 0;
+               if (ret != MS_MEDIA_ERR_NONE)
+                       media_svc_error("Fail to append item[%s]", content_info.path);
 
-       } else {
-               media_svc_error("Error in media_svc_update_item_meta");
                _media_svc_destroy_content_info(&content_info);
-               return MS_MEDIA_ERR_INTERNAL;
+               SAFE_FREE(file_info);
        }
 
-       _media_svc_destroy_content_info(&content_info);
+       g_array_free(path_list, false);
+
+       ret = _media_svc_list_query_do(MEDIA_SVC_QUERY_UPDATE_ITEM, uid);
+       media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "_media_svc_list_query_do failed");
+
+       /* Noti for this */
+       __media_svc_noti_all_storage(handle, uid);
 
        return ret;
 }
 
-int media_svc_publish_noti(media_item_type_e update_item, media_item_update_type_e update_type, const char *path, media_type_e media_type, const char *uuid, const char *mime_type)
+int media_svc_publish_noti(media_item_update_type_e update_type, const char *path, media_type_e media_type, const char *uuid, const char *mime_type)
 {
-       return _media_svc_publish_noti(update_item, update_type, path, media_type, uuid, mime_type);
+       return _media_svc_publish_noti(update_type, path, media_type, uuid, mime_type);
 }
 
 int media_svc_get_pinyin(const char *src_str, char **pinyin_str)
@@ -868,7 +807,7 @@ int media_svc_insert_storage(sqlite3 *handle, const char *storage_id, const char
        media_svc_retvm_if(handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
        media_svc_retvm_if(storage_id == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
        media_svc_retvm_if(storage_path == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "storage_path is NULL");
-       media_svc_retvm_if(_media_svc_check_storage_type(storage_type) != TRUE, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid storage_type");
+       media_svc_retvm_if(!_media_svc_is_valid_storage_type(storage_type), MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid storage_type");
 
        ret = _media_svc_append_storage(storage_id, storage_path, storage_type, uid);
        media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "append storage failed : %d", ret);
@@ -886,75 +825,19 @@ int media_svc_insert_storage(sqlite3 *handle, const char *storage_id, const char
        return ret;
 }
 
-int media_svc_insert_folder_begin(int data_cnt)
-{
-       media_svc_debug("Transaction data count : [%d]", data_cnt);
-
-       media_svc_retvm_if(data_cnt < 1, MS_MEDIA_ERR_INVALID_PARAMETER, "data_cnt shuld be bigger than 1");
-
-       g_media_svc_insert_folder_data_cnt = data_cnt;
-       g_media_svc_insert_folder_cur_data_cnt = 0;
-
-       return MS_MEDIA_ERR_NONE;
-}
-
-int media_svc_insert_folder_end(uid_t uid)
-{
-       int ret = MS_MEDIA_ERR_NONE;
-
-       media_svc_debug_fenter();
-
-       if (g_media_svc_insert_folder_cur_data_cnt > 0)
-               ret = _media_svc_list_query_do(MEDIA_SVC_QUERY_INSERT_FOLDER, uid);
-
-       g_media_svc_insert_folder_data_cnt = 1;
-       g_media_svc_insert_folder_cur_data_cnt = 0;
-
-       return ret;
-}
-
 int media_svc_insert_folder(sqlite3 *handle, const char *storage_id, ms_user_storage_type_e storage_type, const char *path, uid_t uid)
 {
-       int ret = MS_MEDIA_ERR_NONE;
-       char folder_uuid[MEDIA_SVC_UUID_SIZE+1] = {0,};
-
        media_svc_retvm_if(handle == NULL, MS_MEDIA_ERR_INVALID_PARAMETER, "Handle is NULL");
        media_svc_retvm_if(!STRING_VALID(storage_id), MS_MEDIA_ERR_INVALID_PARAMETER, "storage_id is NULL");
        media_svc_retvm_if(!STRING_VALID(path), MS_MEDIA_ERR_INVALID_PARAMETER, "path is NULL");
-       media_svc_retvm_if(_media_svc_check_storage_type(storage_type) != TRUE, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid storage_type");
-
-       if (g_media_svc_insert_folder_data_cnt == 1) {
+       media_svc_retvm_if(!_media_svc_is_valid_storage_type(storage_type), MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid storage_type");
 
-               ret = _media_svc_get_and_append_folder_id_by_folder_path(handle, storage_id, path, storage_type, folder_uuid, FALSE, uid);
-
-       } else if (g_media_svc_insert_folder_cur_data_cnt < (g_media_svc_insert_folder_data_cnt - 1)) {
-
-               ret = _media_svc_get_and_append_folder_id_by_folder_path(handle, storage_id, path, storage_type, folder_uuid, TRUE, uid);
-               media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
-
-               g_media_svc_insert_folder_cur_data_cnt++;
-
-       } else if (g_media_svc_insert_folder_cur_data_cnt == (g_media_svc_insert_folder_data_cnt - 1)) {
-
-               ret = _media_svc_get_and_append_folder_id_by_folder_path(handle, storage_id, path, storage_type, folder_uuid, TRUE, uid);
-               media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
-
-               ret = _media_svc_list_query_do(MEDIA_SVC_QUERY_INSERT_FOLDER, uid);
-               media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
-
-               g_media_svc_insert_folder_cur_data_cnt = 0;
-
-       } else {
-               media_svc_error("Error in media_svc_set_insert_folder");
-               return MS_MEDIA_ERR_INTERNAL;
-       }
-
-       return ret;
+       return _media_svc_get_and_append_folder_id_by_folder_path(handle, storage_id, path, storage_type, uid);
 }
 
 int media_svc_set_folder_validity(sqlite3 *handle, const char *storage_id, const char *start_path, int validity, bool is_recursive, uid_t uid)
 {
-       return _media_svc_set_folder_validity(handle, storage_id, start_path, validity, is_recursive, uid);
+       return _media_svc_set_folder_validity(handle, true, storage_id, start_path, validity, is_recursive, uid);
 }
 
 int media_svc_check_folder_exist_by_path(sqlite3 *handle, const char *storage_id, const char *folder_path)
@@ -1002,7 +885,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(file_path, thumb_path, 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)
@@ -1010,7 +893,7 @@ int media_svc_create_thumbnail(const char *storage_id, const char *file_path, in
        }
 
        // 3. Update creation result to media db
-       sql = sqlite3_mprintf("UPDATE '%q' SET thumbnail_path='%q' WHERE path='%q';", storage_id, thumb_path, file_path);
+       sql = sqlite3_mprintf("UPDATE '%q' SET media_thumbnail_path='%q' WHERE media_path='%q';", storage_id, thumb_path, file_path);
 
        ret = _media_svc_sql_query(sql, uid);
        SQLITE3_SAFE_FREE(sql);