static __thread GList *g_media_svc_item_validity_query_list = NULL;
static __thread GList *g_media_svc_insert_item_query_list = NULL;
-__thread GList *g_media_svc_move_item_query_list = NULL;
static __thread GList *g_media_svc_update_item_query_list = NULL;
static __thread GList *g_media_svc_update_list = NULL;
-static int __media_svc_get_invalid_records_with_thumbnail(sqlite3 *handle, media_svc_storage_type_e storage_type, GArray **thumb_path)
+static int __media_svc_get_invalid_records_with_thumbnail(sqlite3 *handle, const char *storage_id, GArray **thumb_path)
{
int ret = MS_MEDIA_ERR_NONE;
sqlite3_stmt *sql_stmt = NULL;
- char *sql = sqlite3_mprintf("SELECT thumbnail_path FROM '%q' WHERE validity=0 AND storage_type=%d AND thumbnail_path IS NOT NULL", MEDIA_SVC_DB_TABLE_MEDIA, storage_type);
+ char *sql = sqlite3_mprintf("SELECT thumbnail_path FROM '%q' WHERE validity=0 AND thumbnail_path IS NOT NULL", storage_id);
media_svc_debug("[SQL query] : %s", sql);
/*If external USB, no need this process */
if (storage_type != MEDIA_SVC_STORAGE_EXTERNAL_USB) {
- ret = __media_svc_get_invalid_records_with_thumbnail(handle, storage_type, &thumb_list);
+ ret = __media_svc_get_invalid_records_with_thumbnail(handle, storage_id, &thumb_list);
if (ret != MS_MEDIA_ERR_NONE) {
media_svc_error("error when get thumbnail record");
g_array_free(thumb_list, false);
return ret;
}
}
-
+ /* MMC FIX:: Remove storage_type from query */
char *sql = sqlite3_mprintf("DELETE FROM '%q' WHERE validity = 0 AND storage_type = %d;", storage_id, storage_type);
ret = _media_svc_sql_query(sql, uid);
return ret;
}
-int _media_svc_update_item_by_path(const char *src_path, media_svc_storage_type_e dest_storage, const char *dest_path,
- const char *file_name, int modified_time, const char *folder_uuid, const char *thumb_path, bool stack_query, uid_t uid)
+int _media_svc_update_item_by_path(const char *org_storage_id, const char *src_path, const char *dst_storage_id, media_svc_storage_type_e dest_storage, const char *dest_path, const char *file_name, int modified_time, const char *folder_uuid, uid_t uid)
{
/* update path, filename, modified_time, folder_uuid, thumbnail_path, */
/* played_count, last_played_time, last_played_position, favourite, storaget_type*/
+ /* NOTICE (This operation is abnormal. Modifications should be cautious.)
+ 1. Update source to destination info
+ 2. Insert destination table
+ 3. Remove source info
+ */
int ret = MS_MEDIA_ERR_NONE;
- char *sql = NULL;
+ char *update = sqlite3_mprintf("UPDATE '%q' SET path=%Q, file_name=%Q, modified_time=%d, folder_uuid=%Q, storage_type=%d, storage_uuid='%q', played_count=0, last_played_time=0, last_played_position=0 WHERE path=%Q;",
+ org_storage_id, dest_path, file_name, modified_time, folder_uuid, dest_storage, dst_storage_id, src_path);
+ char *insert = sqlite3_mprintf("INSERT OR REPLACE INTO '%q' SELECT * FROM '%q' WHERE path = '%q';", dst_storage_id, org_storage_id, dest_path);
+ char *remove = sqlite3_mprintf("DELETE FROM '%q' WHERE path = '%q';", org_storage_id, dest_path);
+ char *query = NULL;
+
+ if (strcmp(org_storage_id, dst_storage_id) != 0)
+ query = sqlite3_mprintf("%s %s %s", update, insert, remove);
+ else
+ query = sqlite3_mprintf("%s %s", update, insert);
- if (thumb_path != NULL) {
- sql = sqlite3_mprintf("UPDATE '%q' SET path=%Q, file_name=%Q, modified_time=%d, folder_uuid=%Q, thumbnail_path=%Q, storage_type=%d, \
- played_count=0, last_played_time=0, last_played_position=0 WHERE path=%Q;",
- MEDIA_SVC_DB_TABLE_MEDIA, dest_path, file_name, modified_time, folder_uuid, thumb_path, dest_storage, src_path);
- } else {
- sql = sqlite3_mprintf("UPDATE '%q' SET path=%Q, file_name=%Q, modified_time=%d, folder_uuid=%Q, storage_type=%d, \
- played_count=0, last_played_time=0, last_played_position=0 WHERE path=%Q;",
- MEDIA_SVC_DB_TABLE_MEDIA, dest_path, file_name, modified_time, folder_uuid, dest_storage, src_path);
- }
+ SQLITE3_SAFE_FREE(update);
+ SQLITE3_SAFE_FREE(insert);
+ SQLITE3_SAFE_FREE(remove);
- if (!stack_query) {
- ret = _media_svc_sql_query(sql, uid);
- SQLITE3_SAFE_FREE(sql);
- } else {
- _media_svc_sql_query_add(&g_media_svc_move_item_query_list, &sql);
- }
+ ret = _media_svc_sql_query(query, uid);
+ SQLITE3_SAFE_FREE(query);
return ret;
}
if (query_type == MEDIA_SVC_QUERY_SET_ITEM_VALIDITY)
ret = _media_svc_sql_query_list(&g_media_svc_item_validity_query_list, uid);
- else if (query_type == MEDIA_SVC_QUERY_MOVE_ITEM)
- ret = _media_svc_sql_query_list(&g_media_svc_move_item_query_list, uid);
else if (query_type == MEDIA_SVC_QUERY_INSERT_ITEM)
ret = _media_svc_sql_query_list(&g_media_svc_insert_item_query_list, uid);
else if (query_type == MEDIA_SVC_QUERY_UPDATE_ITEM)
static __thread int g_media_svc_item_validity_data_cnt = 1;
static __thread int g_media_svc_item_validity_cur_data_cnt = 0;
-static __thread int g_media_svc_move_item_data_cnt = 1;
-static __thread int g_media_svc_move_item_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;
return ret;
}
-int media_svc_move_item(MediaSvcHandle *handle, const char *storage_id, media_svc_storage_type_e src_storage, const char *src_path,
- media_svc_storage_type_e dest_storage, const char *dest_path, uid_t uid)
+int media_svc_move_item(MediaSvcHandle *handle, const char *src_path, const char *dest_path, uid_t uid)
{
int ret = MS_MEDIA_ERR_NONE;
sqlite3 *db_handle = (sqlite3 *)handle;
int modified_time = 0;
char folder_uuid[MEDIA_SVC_UUID_SIZE + 1] = {0, };
char old_thumb_path[MEDIA_SVC_PATHNAME_SIZE] = {0, };
- char new_thumb_path[MEDIA_SVC_PATHNAME_SIZE] = {0, };
+ char org_stg_id[MEDIA_SVC_UUID_SIZE + 1] = {0, };
+ 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(db_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(__media_svc_check_storage(src_storage) != TRUE, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid src_storage");
- media_svc_retvm_if(__media_svc_check_storage(dest_storage) != TRUE, MS_MEDIA_ERR_INVALID_PARAMETER, "Invalid dest_storage");
+
+ /* Get storage_id */
+ ret = _media_svc_get_storage_uuid(db_handle, src_path, org_stg_id, uid);
+ media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
+ ret = _media_svc_get_storage_uuid(db_handle, dest_path, dst_stg_id, uid);
+ media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
+ /* Get storage_type */
+ ret = ms_user_get_storage_type(uid, src_path, &org_stg_type);
+ media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
+ ret = ms_user_get_storage_type(uid, dest_path, &dst_stg_type);
+ media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
/*check and update folder*/
- ret = _media_svc_get_and_append_folder_id_by_path(db_handle, storage_id, dest_path, dest_storage, folder_uuid, uid);
+ ret = _media_svc_get_and_append_folder_id_by_path(db_handle, dst_stg_id, dest_path, dst_stg_type, folder_uuid, uid);
media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
/*get filename*/
/*get modified_time*/
modified_time = _media_svc_get_file_time(dest_path);
- /*get thumbnail_path to update. only for Imgae and Video items. Audio share album_art(thumbnail)*/
- ret = _media_svc_get_media_type_by_path(db_handle, storage_id, src_path, &media_type);
+ ret = _media_svc_get_media_type_by_path(db_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;
}
- if ((media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE) || (media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO)) {
- /*get old thumbnail_path*/
- ret = _media_svc_get_thumbnail_path_by_path(db_handle, src_path, old_thumb_path);
- if ((ret != MS_MEDIA_ERR_NONE) && (ret != MS_MEDIA_ERR_DB_NO_RECORD)) {
- media_svc_error("_media_svc_get_thumbnail_path_by_path failed");
- SAFE_FREE(file_name);
- return ret;
- }
-
- _media_svc_get_thumbnail_path(dest_storage, media_type, new_thumb_path, dest_path, THUMB_EXT, uid);
- }
-
- if (g_media_svc_move_item_data_cnt == 1) {
-
- /*update item*/
- if ((media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE) || (media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO))
- ret = _media_svc_update_item_by_path(src_path, dest_storage, dest_path, file_name, modified_time, folder_uuid, new_thumb_path, FALSE, uid);
- else
- ret = _media_svc_update_item_by_path(src_path, dest_storage, dest_path, file_name, modified_time, folder_uuid, NULL, FALSE, uid);
-
- SAFE_FREE(file_name);
- 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(db_handle, storage_id, dest_path, MS_MEDIA_ITEM_FILE, ¬i_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);
-
- /*update folder modified_time*/
- folder_path = g_path_get_dirname(dest_path);
- ret = _media_svc_update_folder_modified_time_by_folder_uuid(folder_uuid, folder_path, FALSE, uid);
- SAFE_FREE(folder_path);
- media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
-
- ret = _media_svc_update_folder_table(storage_id, uid);
- media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
-
- } else if (g_media_svc_move_item_cur_data_cnt < (g_media_svc_move_item_data_cnt - 1)) {
-
- /*update item*/
- if ((media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE) || (media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO))
- ret = _media_svc_update_item_by_path(src_path, dest_storage, dest_path, file_name, modified_time, folder_uuid, new_thumb_path, TRUE, uid);
- else
- ret = _media_svc_update_item_by_path(src_path, dest_storage, dest_path, file_name, modified_time, folder_uuid, NULL, TRUE, uid);
-
+ /*get old thumbnail_path and remove thumbnail */
+ ret = _media_svc_get_thumbnail_path_by_path(db_handle, src_path, old_thumb_path);
+ if ((ret != MS_MEDIA_ERR_NONE) && (ret != MS_MEDIA_ERR_DB_NO_RECORD)) {
+ media_svc_error("_media_svc_get_thumbnail_path_by_path failed");
SAFE_FREE(file_name);
- media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
-
- /*update folder modified_time*/
- folder_path = g_path_get_dirname(dest_path);
- ret = _media_svc_update_folder_modified_time_by_folder_uuid(folder_uuid, folder_path, TRUE, uid);
- SAFE_FREE(folder_path);
- media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
-
- g_media_svc_move_item_cur_data_cnt++;
-
- } else if (g_media_svc_move_item_cur_data_cnt == (g_media_svc_move_item_data_cnt - 1)) {
- /*update item*/
- if ((media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE) || (media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO))
- ret = _media_svc_update_item_by_path(src_path, dest_storage, dest_path, file_name, modified_time, folder_uuid, new_thumb_path, TRUE, uid);
- else
- ret = _media_svc_update_item_by_path(src_path, dest_storage, dest_path, file_name, modified_time, folder_uuid, NULL, TRUE, uid);
+ return ret;
+ }
- SAFE_FREE(file_name);
- media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
+ if (STRING_VALID(old_thumb_path)) {
+ ret = _media_svc_remove_file(old_thumb_path);
+ if (ret != MS_MEDIA_ERR_NONE)
+ media_svc_error("_media_svc_remove_file failed : %d", ret);
+ }
- /*update folder modified_time*/
- folder_path = g_path_get_dirname(dest_path);
- ret = _media_svc_update_folder_modified_time_by_folder_uuid(folder_uuid, folder_path, TRUE, uid);
- SAFE_FREE(folder_path);
- media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
+ /*move item*/
+ ret = _media_svc_update_item_by_path(org_stg_id, src_path, dst_stg_id, dst_stg_type, dest_path, file_name, modified_time, folder_uuid, uid);
+ SAFE_FREE(file_name);
+ media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
- /*update db*/
- ret = _media_svc_list_query_do(MEDIA_SVC_QUERY_MOVE_ITEM, uid);
- media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
+ media_svc_debug("Move is successful. Sending noti for this");
- g_media_svc_move_item_cur_data_cnt = 0;
+ /* Get notification info */
+ media_svc_noti_item *noti_item = NULL;
+ ret = _media_svc_get_noti_info(db_handle, dst_stg_id, dest_path, MS_MEDIA_ITEM_FILE, ¬i_item);
+ media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
- } else {
- media_svc_error("Error in media_svc_move_item");
- SAFE_FREE(file_name);
- return MS_MEDIA_ERR_INTERNAL;
- }
+ /* 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);
- /*rename thumbnail file*/
- if (STRING_VALID(old_thumb_path)) {
- ret = _media_svc_rename_file(old_thumb_path, new_thumb_path);
- if (ret != MS_MEDIA_ERR_NONE)
- media_svc_error("_media_svc_rename_file failed : %d", ret);
- }
+ /*update folder modified_time*/
+ folder_path = g_path_get_dirname(dest_path);
+ ret = _media_svc_update_folder_modified_time_by_folder_uuid(folder_uuid, folder_path, uid);
+ SAFE_FREE(folder_path);
+ media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
return MS_MEDIA_ERR_NONE;
}
ret = _media_svc_get_folder_info_by_foldername(db_handle, storage_id, folder_path, folder_uuid, &sto_time);
if (ret == MS_MEDIA_ERR_NONE) {
if (sto_time != cur_time)
- ret = _media_svc_update_folder_modified_time_by_folder_uuid(folder_uuid, folder_path, FALSE, uid);
+ ret = _media_svc_update_folder_modified_time_by_folder_uuid(folder_uuid, folder_path, uid);
}
return ret;
return _media_svc_get_media_type(path, mediatype);
}
-int media_svc_create_thumbnail(const char *file_path, int media_type, uid_t uid, char **thumbnail_path)
+int media_svc_create_thumbnail(const char *storage_id, const char *file_path, int media_type, uid_t uid, char **thumbnail_path)
{
int ret = MS_MEDIA_ERR_NONE;
char thumb_path[MEDIA_SVC_PATHNAME_SIZE + 1] = { 0, };
media_svc_error("Failed to create thumbnail [%d]", ret);
// 3. Update creation result to media db
- sql = sqlite3_mprintf("UPDATE %q SET thumbnail_path = '%q' WHERE path='%q';", MEDIA_SVC_DB_TABLE_MEDIA, thumb_path, file_path);
+ sql = sqlite3_mprintf("UPDATE '%q' SET thumbnail_path='%q' WHERE path='%q';", storage_id, thumb_path, file_path);
ret = _media_svc_sql_query(sql, uid);
SQLITE3_SAFE_FREE(sql);