/* Flag for items to be published by notification */
static __thread int g_insert_with_noti = FALSE;
-int media_svc_connect(MediaSvcHandle **handle)
+int media_svc_connect(MediaSvcHandle **handle, uid_t uid)
{
int ret = MEDIA_INFO_ERROR_NONE;
MediaDBHandle *db_handle = NULL;
media_svc_debug_func();
#if 1 //Use libmedia_utils API
- ret = media_db_connect(&db_handle);
+ ret = media_db_connect(&db_handle,uid);
if(ret != MS_MEDIA_ERR_NONE)
return _media_svc_error_convert(ret);
#endif
}
-int media_svc_create_table(MediaSvcHandle *handle)
+int media_svc_create_table(MediaSvcHandle *handle, uid_t uid)
{
int ret = MEDIA_INFO_ERROR_NONE;
sqlite3 * db_handle = (sqlite3 *)handle;
media_svc_retvm_if(db_handle == NULL, MEDIA_INFO_ERROR_INVALID_PARAMETER, "Handle is NULL");
/*create media table*/
- ret = _media_svc_create_media_table(handle);
+ ret = _media_svc_create_media_table(handle, uid);
media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
/*create folder table*/
- ret = _media_svc_create_folder_table(handle);
+ ret = _media_svc_create_folder_table(handle, uid);
media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
/*create playlist table*/
- ret = _media_svc_create_playlist_table(handle);
+ ret = _media_svc_create_playlist_table(handle, uid);
media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
/* create album table*/
- ret = _media_svc_create_album_table(handle);
+ ret = _media_svc_create_album_table(handle, uid);
media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
/*create tag table*/
- ret = _media_svc_create_tag_table(handle);
+ ret = _media_svc_create_tag_table(handle,uid);
media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
/*create bookmark table*/
- ret = _media_svc_create_bookmark_table(handle);
+ ret = _media_svc_create_bookmark_table(handle, uid);
media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
#if 0 /*unify media and custom table*/
/*create custom table*/
- ret = _media_svc_create_custom_table(handle);
+ ret = _media_svc_create_custom_table(handle, uid);
media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
#endif
return MEDIA_INFO_ERROR_NONE;
}
-int media_svc_insert_item_end(MediaSvcHandle *handle)
+int media_svc_insert_item_end(MediaSvcHandle *handle, uid_t uid)
{
int ret = MEDIA_INFO_ERROR_NONE;
sqlite3 * db_handle = (sqlite3 *)handle;
if (g_media_svc_insert_item_cur_data_cnt > 0) {
- ret = _media_svc_list_query_do(db_handle, MEDIA_SVC_QUERY_INSERT_ITEM);
+ ret = _media_svc_list_query_do(db_handle, MEDIA_SVC_QUERY_INSERT_ITEM, uid);
if (g_insert_with_noti) {
media_svc_debug("sending noti list");
_media_svc_publish_noti_list(g_media_svc_insert_item_cur_data_cnt);
return ret;
}
-int media_svc_insert_item_bulk(MediaSvcHandle *handle, media_svc_storage_type_e storage_type, const char *path, int is_burst)
+int media_svc_insert_item_bulk(MediaSvcHandle *handle, media_svc_storage_type_e storage_type, const char *path, int is_burst, uid_t uid)
{
int ret = MEDIA_INFO_ERROR_NONE;
sqlite3 * db_handle = (sqlite3 *)handle;
} else if(media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE) {
ret = _media_svc_extract_image_metadata(&content_info, media_type);
} else {
- ret = _media_svc_extract_media_metadata(handle, &content_info, media_type, drm_contentInfo);
+ ret = _media_svc_extract_media_metadata(handle, &content_info, media_type, drm_contentInfo, uid);
}
SAFE_FREE(drm_contentInfo);
media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
/*Set or Get folder id*/
- ret = _media_svc_get_and_append_folder_id_by_path(handle, path, storage_type, folder_uuid);
+ ret = _media_svc_get_and_append_folder_id_by_path(handle, path, storage_type, folder_uuid, uid);
media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
ret = __media_svc_malloc_and_strncpy(&content_info.folder_uuid, folder_uuid);
if (g_media_svc_insert_item_data_cnt == 1) {
- ret = _media_svc_insert_item_with_data(db_handle, &content_info, is_burst, FALSE);
+ ret = _media_svc_insert_item_with_data(db_handle, &content_info, is_burst, FALSE, uid);
media_svc_retv_del_if(ret != MEDIA_INFO_ERROR_NONE, ret, &content_info);
if (g_insert_with_noti)
} 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(db_handle, &content_info, is_burst, TRUE);
+ ret = _media_svc_insert_item_with_data(db_handle, &content_info, is_burst, TRUE, uid);
media_svc_retv_del_if(ret != MEDIA_INFO_ERROR_NONE, ret, &content_info);
if (g_insert_with_noti)
} 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(db_handle, &content_info, is_burst, TRUE);
+ ret = _media_svc_insert_item_with_data(db_handle, &content_info, is_burst, TRUE, uid);
media_svc_retv_del_if(ret != MEDIA_INFO_ERROR_NONE, ret, &content_info);
if (g_insert_with_noti)
_media_svc_insert_item_to_noti_list(&content_info, g_media_svc_insert_item_cur_data_cnt);
- ret = _media_svc_list_query_do(db_handle, MEDIA_SVC_QUERY_INSERT_ITEM);
+ ret = _media_svc_list_query_do(db_handle, MEDIA_SVC_QUERY_INSERT_ITEM, uid);
media_svc_retv_del_if(ret != MEDIA_INFO_ERROR_NONE, ret, &content_info);
if (g_insert_with_noti) {
return MEDIA_INFO_ERROR_NONE;
}
-int media_svc_insert_item_immediately(MediaSvcHandle *handle, media_svc_storage_type_e storage_type, const char *path)
+int media_svc_insert_item_immediately(MediaSvcHandle *handle, media_svc_storage_type_e storage_type, const char *path, uid_t uid)
{
int ret = MEDIA_INFO_ERROR_NONE;
sqlite3 * db_handle = (sqlite3 *)handle;
ret = _media_svc_extract_image_metadata(&content_info, media_type);
media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
} else {
- ret = _media_svc_extract_media_metadata(handle, &content_info, media_type, drm_contentInfo);
+ ret = _media_svc_extract_media_metadata(handle, &content_info, media_type, drm_contentInfo, uid);
media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
}
/*Set or Get folder id*/
- ret = _media_svc_get_and_append_folder_id_by_path(handle, path, storage_type, folder_uuid);
+ ret = _media_svc_get_and_append_folder_id_by_path(handle, path, storage_type, folder_uuid, uid);
media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
ret = __media_svc_malloc_and_strncpy(&content_info.folder_uuid, folder_uuid);
int width = 0;
int height = 0;
- ret = thumbnail_request_from_db_with_size(content_info.path, thumb_path, sizeof(thumb_path), &width, &height);
+ ret = thumbnail_request_from_db_with_size(content_info.path, thumb_path, sizeof(thumb_path), &width, &height, uid);
if (ret < 0) {
media_svc_error("thumbnail_request_from_db failed: %d", ret);
} else {
media_svc_debug("thumbnail_request_from_db success: %s", thumb_path);
- __media_svc_malloc_and_strncpy(&(content_info.thumbnail_path), thumb_path);
+ ret = __media_svc_malloc_and_strncpy(&(content_info.thumbnail_path), thumb_path);
+ if (ret < 0) {
+ media_svc_error("__media_svc_malloc_and_strncpy failed : %d", ret);
+ }
}
if (content_info.media_meta.width <= 0)
content_info.media_meta.height = height;
}
#endif
- ret = _media_svc_insert_item_with_data(db_handle, &content_info, FALSE, FALSE);
+ ret = _media_svc_insert_item_with_data(db_handle, &content_info, FALSE, FALSE, uid);
if (ret == MEDIA_INFO_ERROR_NONE) {
media_svc_debug("Insertion is successful. Sending noti for this");
return ret;
}
-int media_svc_insert_folder(MediaSvcHandle *handle, media_svc_storage_type_e storage_type, const char *path)
+int media_svc_insert_folder(MediaSvcHandle *handle, media_svc_storage_type_e storage_type, const char *path, uid_t uid)
{
int ret = MEDIA_INFO_ERROR_NONE;
sqlite3 * db_handle = (sqlite3 *)handle;
folder_name = g_path_get_basename(path);
folder_modified_date = _media_svc_get_file_time(path);
- ret = _media_svc_append_folder(handle, storage_type, folder_uuid, path, folder_name, folder_modified_date);
+ ret = _media_svc_append_folder(handle, storage_type, folder_uuid, path, folder_name, folder_modified_date, uid);
SAFE_FREE(folder_name);
if (ret < MEDIA_INFO_ERROR_NONE) {
return MEDIA_INFO_ERROR_NONE;
}
-int media_svc_move_item_end(MediaSvcHandle *handle)
+int media_svc_move_item_end(MediaSvcHandle *handle, uid_t uid)
{
int ret = MEDIA_INFO_ERROR_NONE;
sqlite3 * db_handle = (sqlite3 *)handle;
if (g_media_svc_move_item_cur_data_cnt > 0) {
- ret = _media_svc_list_query_do(db_handle, MEDIA_SVC_QUERY_MOVE_ITEM);
+ ret = _media_svc_list_query_do(db_handle, MEDIA_SVC_QUERY_MOVE_ITEM, uid);
}
/*clean up old folder path*/
- ret = _media_svc_update_folder_table(handle);
+ ret = _media_svc_update_folder_table(handle, uid);
media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
g_media_svc_move_item_data_cnt = 1;
}
int media_svc_move_item(MediaSvcHandle *handle, media_svc_storage_type_e src_storage, const char *src_path,
- media_svc_storage_type_e dest_storage, const char *dest_path)
+ media_svc_storage_type_e dest_storage, const char *dest_path, uid_t uid)
{
int ret = MEDIA_INFO_ERROR_NONE;
sqlite3 * db_handle = (sqlite3 *)handle;
}
/*check and update folder*/
- ret = _media_svc_get_and_append_folder_id_by_path(handle, dest_path, dest_storage, folder_uuid);
+ ret = _media_svc_get_and_append_folder_id_by_path(handle, dest_path, dest_storage, folder_uuid, uid);
media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
/*get filename*/
ret = _media_svc_get_thumbnail_path_by_path(handle, src_path, old_thumb_path);
media_svc_retv_if((ret != MEDIA_INFO_ERROR_NONE) && (ret != MEDIA_INFO_ERROR_DATABASE_NO_RECORD), ret);
- _media_svc_get_thumbnail_path(dest_storage, new_thumb_path, dest_path, THUMB_EXT);
+ /* If old thumb path is default or not */
+ if (strncmp(old_thumb_path, _media_svc_get_thumb_default_path(uid), sizeof(_media_svc_get_thumb_default_path(uid))) == 0) {
+ strncpy(new_thumb_path, _media_svc_get_thumb_default_path(uid), sizeof(new_thumb_path));
+ } else {
+ _media_svc_get_thumbnail_path(dest_storage, 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(handle, src_path, dest_storage, dest_path, file_name, modified_time, folder_uuid, new_thumb_path, FALSE);
+ ret = _media_svc_update_item_by_path(handle, 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(handle, src_path, dest_storage, dest_path, file_name, modified_time, folder_uuid, NULL, FALSE);
+ ret = _media_svc_update_item_by_path(handle, src_path, dest_storage, dest_path, file_name, modified_time, folder_uuid, NULL, FALSE, uid);
}
SAFE_FREE(file_name);
media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
/*update folder modified_time*/
folder_path = g_path_get_dirname(dest_path);
- ret = _media_svc_update_folder_modified_time_by_folder_uuid(handle, folder_uuid, folder_path, FALSE);
+ ret = _media_svc_update_folder_modified_time_by_folder_uuid(handle, folder_uuid, folder_path, FALSE, uid);
SAFE_FREE(folder_path);
media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
- ret = _media_svc_update_folder_table(handle);
+ ret = _media_svc_update_folder_table(handle, uid);
media_svc_retv_if(ret != MEDIA_INFO_ERROR_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(handle, src_path, dest_storage, dest_path, file_name, modified_time, folder_uuid, new_thumb_path, TRUE);
+ ret = _media_svc_update_item_by_path(handle, 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(handle, src_path, dest_storage, dest_path, file_name, modified_time, folder_uuid, NULL, TRUE);
+ ret = _media_svc_update_item_by_path(handle, src_path, dest_storage, dest_path, file_name, modified_time, folder_uuid, NULL, TRUE, uid);
}
SAFE_FREE(file_name);
media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
/*update folder modified_time*/
folder_path = g_path_get_dirname(dest_path);
- ret = _media_svc_update_folder_modified_time_by_folder_uuid(handle, folder_uuid, folder_path, TRUE);
+ ret = _media_svc_update_folder_modified_time_by_folder_uuid(handle, folder_uuid, folder_path, TRUE, uid);
SAFE_FREE(folder_path);
media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
/*update item*/
if((media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE) ||(media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO)) {
- ret = _media_svc_update_item_by_path(handle, src_path, dest_storage, dest_path, file_name, modified_time, folder_uuid, new_thumb_path, TRUE);
+ ret = _media_svc_update_item_by_path(handle, 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(handle, src_path, dest_storage, dest_path, file_name, modified_time, folder_uuid, NULL, TRUE);
+ ret = _media_svc_update_item_by_path(handle, src_path, dest_storage, dest_path, file_name, modified_time, folder_uuid, NULL, TRUE, uid);
}
SAFE_FREE(file_name);
media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
/*update folder modified_time*/
folder_path = g_path_get_dirname(dest_path);
- ret = _media_svc_update_folder_modified_time_by_folder_uuid(handle, folder_uuid, folder_path, TRUE);
+ ret = _media_svc_update_folder_modified_time_by_folder_uuid(handle, folder_uuid, folder_path, TRUE, uid);
SAFE_FREE(folder_path);
media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
/*update db*/
- ret = _media_svc_list_query_do(db_handle, MEDIA_SVC_QUERY_MOVE_ITEM);
+ ret = _media_svc_list_query_do(db_handle, MEDIA_SVC_QUERY_MOVE_ITEM, uid);
media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
g_media_svc_move_item_cur_data_cnt = 0;
/*rename thumbnail file*/
if((media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE) ||(media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO)) {
- if(strlen(old_thumb_path) > 0) {
+ if((strlen(old_thumb_path) > 0) && (strncmp(old_thumb_path, _media_svc_get_thumb_default_path(uid), sizeof(_media_svc_get_thumb_default_path(uid))) != 0)) {
ret = _media_svc_rename_file(old_thumb_path,new_thumb_path);
- media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
+ if (ret < 0)
+ media_svc_error("_media_svc_rename_file failed : %d", ret);
}
}
return MEDIA_INFO_ERROR_NONE;
}
-int media_svc_set_item_validity_end(MediaSvcHandle *handle)
+int media_svc_set_item_validity_end(MediaSvcHandle *handle, uid_t uid)
{
int ret = MEDIA_INFO_ERROR_NONE;
sqlite3 * db_handle = (sqlite3 *)handle;
if (g_media_svc_item_validity_cur_data_cnt > 0) {
- ret = _media_svc_list_query_do(db_handle, MEDIA_SVC_QUERY_SET_ITEM_VALIDITY);
+ ret = _media_svc_list_query_do(db_handle, MEDIA_SVC_QUERY_SET_ITEM_VALIDITY, uid);
}
g_media_svc_item_validity_data_cnt = 1;
return ret;
}
-int media_svc_set_item_validity(MediaSvcHandle *handle, const char *path, int validity)
+int media_svc_set_item_validity(MediaSvcHandle *handle, const char *path, int validity,uid_t uid)
{
int ret = MEDIA_INFO_ERROR_NONE;
sqlite3 * db_handle = (sqlite3 *)handle;
if (g_media_svc_item_validity_data_cnt == 1) {
- return _media_svc_update_item_validity(db_handle, path, validity, FALSE);
+ return _media_svc_update_item_validity(db_handle, 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(db_handle, path, validity, TRUE);
+ ret = _media_svc_update_item_validity(db_handle, path, validity, TRUE, uid);
media_svc_retv_if(ret != MEDIA_INFO_ERROR_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(db_handle, path, validity, TRUE);
+ ret = _media_svc_update_item_validity(db_handle, path, validity, TRUE, uid);
media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
- ret = _media_svc_list_query_do(db_handle, MEDIA_SVC_QUERY_SET_ITEM_VALIDITY);
+ ret = _media_svc_list_query_do(db_handle, MEDIA_SVC_QUERY_SET_ITEM_VALIDITY, uid);
media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
g_media_svc_item_validity_cur_data_cnt = 0;
return MEDIA_INFO_ERROR_NONE;
}
-int media_svc_delete_item_by_path(MediaSvcHandle *handle, const char *path)
+int media_svc_delete_item_by_path(MediaSvcHandle *handle, const char *path, uid_t uid)
{
int ret = MEDIA_INFO_ERROR_NONE;
sqlite3 * db_handle = (sqlite3 *)handle;
media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
/*Delete item*/
- ret = _media_svc_delete_item_by_path(db_handle, path);
+ ret = _media_svc_delete_item_by_path(db_handle, path, uid);
if (ret != MEDIA_INFO_ERROR_NONE) {
media_svc_error("_media_svc_delete_item_by_path failed : %d", ret);
_media_svc_destroy_noti_item(noti_item);
_media_svc_destroy_noti_item(noti_item);
/*Delete thumbnail*/
- if (strlen(thumb_path) > 0) {
- if (_media_svc_remove_file(thumb_path) == FALSE) {
- media_svc_error("fail to remove thumbnail file.");
+ if ((strlen(thumb_path) > 0) && (strncmp(thumb_path, _media_svc_get_thumb_default_path(uid), sizeof(_media_svc_get_thumb_default_path(uid))) != 0)) {
+ int thumb_count = 1;
+ /* Get count of media, which contains same thumbnail for music */
+ if ((media_type == MEDIA_SVC_MEDIA_TYPE_SOUND) ||(media_type == MEDIA_SVC_MEDIA_TYPE_MUSIC)) {
+ ret = _media_svc_get_thumbnail_count(db_handle, thumb_path, &thumb_count);
+ if (ret < MEDIA_INFO_ERROR_NONE) {
+ media_svc_error("Failed to get thumbnail count : %d", ret);
+ }
+ }
+
+ if (thumb_count == 1) {
+ if (_media_svc_remove_file(thumb_path) == FALSE) {
+ media_svc_error("fail to remove thumbnail file.");
+ }
}
}
return MEDIA_INFO_ERROR_NONE;
}
-int media_svc_delete_all_items_in_storage(MediaSvcHandle *handle, media_svc_storage_type_e storage_type)
+int media_svc_delete_all_items_in_storage(MediaSvcHandle *handle, media_svc_storage_type_e storage_type, uid_t uid)
{
int ret = MEDIA_INFO_ERROR_NONE;
sqlite3 * db_handle = (sqlite3 *)handle;
return MEDIA_INFO_ERROR_INVALID_PARAMETER;
}
- ret = _media_svc_truncate_table(db_handle, storage_type);
+ ret = _media_svc_truncate_table(db_handle, storage_type, uid);
media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
- dirpath = (storage_type == MEDIA_SVC_STORAGE_INTERNAL) ? MEDIA_SVC_THUMB_INTERNAL_PATH : MEDIA_SVC_THUMB_EXTERNAL_PATH;
+ dirpath = (storage_type == MEDIA_SVC_STORAGE_INTERNAL) ? _media_svc_get_thumb_internal_path(uid) : _media_svc_get_thumb_external_path(uid);
/* remove thumbnails */
ret = _media_svc_remove_all_files_in_dir(dirpath);
return MEDIA_INFO_ERROR_NONE;
}
-int media_svc_delete_invalid_items_in_storage(MediaSvcHandle *handle, media_svc_storage_type_e storage_type)
+int media_svc_delete_invalid_items_in_storage(MediaSvcHandle *handle, media_svc_storage_type_e storage_type, uid_t uid)
{
sqlite3 * db_handle = (sqlite3 *)handle;
}
/*Delete from DB and remove thumbnail files*/
- return _media_svc_delete_invalid_items(db_handle, storage_type);
+ return _media_svc_delete_invalid_items(db_handle, storage_type, uid);
}
-int media_svc_delete_invalid_items_in_folder(MediaSvcHandle *handle, const char *folder_path)
+int media_svc_delete_invalid_items_in_folder(MediaSvcHandle *handle, const char *folder_path, uid_t uid)
{
sqlite3 * db_handle = (sqlite3 *)handle;
media_svc_retvm_if(db_handle == NULL, MEDIA_INFO_ERROR_INVALID_PARAMETER, "Handle is NULL");
/*Delete from DB and remove thumbnail files*/
- return _media_svc_delete_invalid_folder_items(db_handle, folder_path);
+ return _media_svc_delete_invalid_folder_items(db_handle, folder_path, uid);
}
-int media_svc_set_all_storage_items_validity(MediaSvcHandle *handle, media_svc_storage_type_e storage_type, int validity)
+int media_svc_set_all_storage_items_validity(MediaSvcHandle *handle, media_svc_storage_type_e storage_type, int validity, uid_t uid)
{
sqlite3 * db_handle = (sqlite3 *)handle;
return MEDIA_INFO_ERROR_INVALID_PARAMETER;
}
- return _media_svc_update_storage_item_validity(db_handle, storage_type, validity);
+ return _media_svc_update_storage_item_validity(db_handle, storage_type, validity, uid);
}
-int media_svc_set_folder_items_validity(MediaSvcHandle *handle, const char *folder_path, int validity, int recursive)
+int media_svc_set_folder_items_validity(MediaSvcHandle *handle, const char *folder_path, int validity, int recursive, uid_t uid)
{
sqlite3 * db_handle = (sqlite3 *)handle;
media_svc_retvm_if(!STRING_VALID(folder_path), MEDIA_INFO_ERROR_INVALID_PARAMETER, "folder_path is NULL");
if(recursive)
- return _media_svc_update_recursive_folder_item_validity(db_handle, folder_path, validity);
+ return _media_svc_update_recursive_folder_item_validity(db_handle, folder_path, validity , uid);
else
- return _media_svc_update_folder_item_validity(db_handle, folder_path, validity);
+ return _media_svc_update_folder_item_validity(db_handle, folder_path, validity, uid);
}
-int media_svc_refresh_item(MediaSvcHandle *handle, media_svc_storage_type_e storage_type, const char *path)
+int media_svc_refresh_item(MediaSvcHandle *handle, media_svc_storage_type_e storage_type, const char *path, uid_t uid)
{
int ret = MEDIA_INFO_ERROR_NONE;
sqlite3 * db_handle = (sqlite3 *)handle;
return MEDIA_INFO_ERROR_INVALID_PARAMETER;
}
- /* Get notification info */
- media_svc_noti_item *noti_item = NULL;
- ret = _media_svc_get_noti_info(handle, path, MS_MEDIA_ITEM_FILE, ¬i_item);
- media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
media_svc_content_info_s content_info;
memset(&content_info, 0, sizeof(media_svc_content_info_s));
ret = _media_svc_get_thumbnail_path_by_path(handle, path, thumb_path);
media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
- if (g_file_test(thumb_path, G_FILE_TEST_EXISTS)) {
+ if (g_file_test(thumb_path, G_FILE_TEST_EXISTS) && (strncmp(thumb_path, _media_svc_get_thumb_default_path(uid), sizeof(_media_svc_get_thumb_default_path(uid))) != 0)) {
ret = _media_svc_remove_file(thumb_path);
- media_svc_retv_if(ret != TRUE, ret);
+ if (ret < MEDIA_INFO_ERROR_NONE) {
+ media_svc_error("_media_svc_remove_file failed : %s", thumb_path);
+ }
}
- ret = _media_svc_update_thumbnail_path(handle, path, NULL);
+ ret = _media_svc_update_thumbnail_path(handle, path, NULL, uid);
+ media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
+
+ /* Get notification info */
+ media_svc_noti_item *noti_item = NULL;
+ ret = _media_svc_get_noti_info(handle, path, MS_MEDIA_ITEM_FILE, ¬i_item);
media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
+ media_type = noti_item->media_type;
+
if(media_type == MEDIA_SVC_MEDIA_TYPE_OTHER) {
/*Do nothing.*/
} else if(media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE) {
ret = _media_svc_extract_image_metadata(&content_info, media_type);
- media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
+ if (ret != MEDIA_INFO_ERROR_NONE) {
+ _media_svc_destroy_noti_item(noti_item);
+ return ret;
+ }
} else {
- ret = _media_svc_extract_media_metadata(handle, &content_info, media_type, drm_contentInfo);
- media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
+ ret = _media_svc_extract_media_metadata(handle, &content_info, media_type, drm_contentInfo, uid);
+ if (ret != MEDIA_INFO_ERROR_NONE) {
+ _media_svc_destroy_noti_item(noti_item);
+ return ret;
+ }
}
#if 1
/* Extracting thumbnail */
int width = 0;
int height = 0;
- ret = thumbnail_request_from_db_with_size(content_info.path, thumb_path, sizeof(thumb_path), &width, &height);
+ ret = thumbnail_request_from_db_with_size(content_info.path, thumb_path, sizeof(thumb_path), &width, &height, uid);
if (ret < 0) {
media_svc_error("thumbnail_request_from_db failed: %d", ret);
} else {
media_svc_debug("thumbnail_request_from_db success: %s", thumb_path);
- __media_svc_malloc_and_strncpy(&(content_info.thumbnail_path), thumb_path);
+ ret = __media_svc_malloc_and_strncpy(&(content_info.thumbnail_path), thumb_path);
+ if (ret < 0) {
+ media_svc_error("__media_svc_malloc_and_strncpy failed : %d", ret);
+ }
}
if (content_info.media_meta.width <= 0)
content_info.media_meta.height = height;
}
#endif
- ret = _media_svc_update_item_with_data(db_handle, &content_info);
+ ret = _media_svc_update_item_with_data(db_handle, &content_info, uid);
if (ret == MEDIA_INFO_ERROR_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, media_type, noti_item->media_uuid, noti_item->mime_type);
+ _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);
} else {
media_svc_error("_media_svc_update_item_with_data failed : %d", ret);
}
return ret;
}
-int media_svc_rename_folder(MediaSvcHandle *handle, const char *src_path, const char *dst_path)
+int media_svc_rename_folder(MediaSvcHandle *handle, const char *src_path, const char *dst_path, uid_t uid)
{
sqlite3 * db_handle = (sqlite3 *)handle;
int ret = MEDIA_INFO_ERROR_NONE;
ret = _media_svc_get_noti_info(handle, src_path, MS_MEDIA_ITEM_DIRECTORY, ¬i_item);
media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
- ret = _media_svc_sql_begin_trans(handle);
+ ret = _media_svc_sql_begin_trans(handle,uid);
media_svc_retv_if(ret != MEDIA_INFO_ERROR_NONE, ret);
/* Update all folder record's path, which are matched by old parent path */
update_folder_path_sql = sqlite3_mprintf("UPDATE folder SET path = REPLACE( path, '%q', '%q');", src_path_slash, dst_path_slash);
//ret = _media_svc_sql_query(handle, update_folder_path_sql);
- ret = media_db_request_update_db_batch(update_folder_path_sql);
+ ret = media_db_request_update_db_batch(update_folder_path_sql, uid);
sqlite3_free(update_folder_path_sql);
if (ret != SQLITE_OK) {
media_svc_error("failed to update folder path");
- _media_svc_sql_rollback_trans(handle);
+ _media_svc_sql_rollback_trans(handle, uid);
return MEDIA_INFO_ERROR_DATABASE_INTERNAL;
}
update_folder_modified_time_sql = sqlite3_mprintf("UPDATE folder SET modified_time = %d where path like '%q';", date, dst_path);
- ret = media_db_request_update_db_batch(update_folder_modified_time_sql);
+ ret = media_db_request_update_db_batch(update_folder_modified_time_sql, uid);
//ret = _media_svc_sql_query(handle, update_folder_modified_time_sql);
sqlite3_free(update_folder_modified_time_sql);
if (ret != SQLITE_OK) {
media_svc_error("failed to update folder modified time");
- _media_svc_sql_rollback_trans(handle);
+ _media_svc_sql_rollback_trans(handle, uid);
return MEDIA_INFO_ERROR_DATABASE_INTERNAL;
}
if (ret != SQLITE_OK) {
media_svc_error ("prepare error [%s]", sqlite3_errmsg(handle));
- _media_svc_sql_rollback_trans(handle);
+ _media_svc_sql_rollback_trans(handle, uid);
return MEDIA_INFO_ERROR_DATABASE_INTERNAL;
}
if (replaced_path == NULL) {
media_svc_error("_media_svc_replace_path failed");
SQLITE3_FINALIZE(sql_stmt);
- _media_svc_sql_rollback_trans(handle);
+ _media_svc_sql_rollback_trans(handle, uid);
return MEDIA_INFO_ERROR_INTERNAL;
}
media_svc_storage_type_e storage_type;
if (!no_thumb) {
- ret = _media_svc_get_store_type_by_path(replaced_path, &storage_type);
- if (ret < 0) {
- media_svc_error("_media_svc_get_store_type_by_path failed : %d", ret);
- SAFE_FREE(replaced_path);
- _media_svc_sql_rollback_trans(handle);
- return MEDIA_INFO_ERROR_DATABASE_INTERNAL;
- }
-
- ret = _media_svc_get_thumbnail_path(storage_type, media_new_thumb_path, replaced_path, THUMB_EXT);
- if (ret < 0) {
- media_svc_error("_media_svc_get_thumbnail_path failed : %d", ret);
- SAFE_FREE(replaced_path);
- SQLITE3_FINALIZE(sql_stmt);
- _media_svc_sql_rollback_trans(handle);
- return MEDIA_INFO_ERROR_INTERNAL;
+ /* If old thumb path is default or not */
+ if (strncmp(media_thumb_path, _media_svc_get_thumb_default_path(uid), sizeof(_media_svc_get_thumb_default_path(uid))) == 0) {
+ strncpy(media_new_thumb_path, _media_svc_get_thumb_default_path(uid), sizeof(media_new_thumb_path));
+ } else {
+ ret = _media_svc_get_store_type_by_path(replaced_path, &storage_type);
+ if (ret < 0) {
+ media_svc_error("_media_svc_get_store_type_by_path failed : %d", ret);
+ SAFE_FREE(replaced_path);
+ _media_svc_sql_rollback_trans(handle,uid);
+ return MEDIA_INFO_ERROR_DATABASE_INTERNAL;
+ }
+
+ ret = _media_svc_get_thumbnail_path(storage_type, media_new_thumb_path, replaced_path, THUMB_EXT, uid);
+ if (ret < 0) {
+ media_svc_error("_media_svc_get_thumbnail_path failed : %d", ret);
+ SAFE_FREE(replaced_path);
+ SQLITE3_FINALIZE(sql_stmt);
+ _media_svc_sql_rollback_trans(handle,uid);
+ return MEDIA_INFO_ERROR_INTERNAL;
+ }
}
//media_svc_debug("New media thumbnail path : %s", media_new_thumb_path);
}
}
- ret = media_db_request_update_db_batch(update_item_sql);
+ ret = media_db_request_update_db_batch(update_item_sql,uid);
//ret = _media_svc_sql_query(handle, update_item_sql);
sqlite3_free(update_item_sql);
SAFE_FREE(replaced_path);
if (ret != SQLITE_OK) {
media_svc_error("failed to update item");
SQLITE3_FINALIZE(sql_stmt);
- _media_svc_sql_rollback_trans(handle);
+ _media_svc_sql_rollback_trans(handle,uid);
return MEDIA_INFO_ERROR_DATABASE_INTERNAL;
}
/* Rename thumbnail file of file system */
- if ((!no_thumb) && (media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE || media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO)) {
+ if ((!no_thumb) && (media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE || media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO)
+ && (strncmp(media_thumb_path, _media_svc_get_thumb_default_path(uid), sizeof(_media_svc_get_thumb_default_path(uid))) != 0)) {
ret = _media_svc_rename_file(media_thumb_path, media_new_thumb_path);
if (ret < 0) {
media_svc_error("_media_svc_rename_file failed : %d", ret);
- SQLITE3_FINALIZE(sql_stmt);
- _media_svc_sql_rollback_trans(handle);
-
- return MEDIA_INFO_ERROR_INTERNAL;
}
}
}
SQLITE3_FINALIZE(sql_stmt);
- ret = _media_svc_sql_end_trans(handle);
+ ret = _media_svc_sql_end_trans(handle, uid);
if (ret != MEDIA_INFO_ERROR_NONE) {
media_svc_error("mb_svc_sqlite3_commit_trans failed.. Now start to rollback\n");
- _media_svc_sql_rollback_trans(handle);
+ _media_svc_sql_rollback_trans(handle,uid);
return ret;
}
return MEDIA_INFO_ERROR_NONE;
}
-int media_svc_request_update_db(const char *db_query)
+int media_svc_request_update_db(const char *db_query, uid_t uid)
{
int ret = MEDIA_INFO_ERROR_NONE;
media_svc_retvm_if(!STRING_VALID(db_query), MEDIA_INFO_ERROR_INVALID_PARAMETER, "db_query is NULL");
- ret = _media_svc_request_update_db(db_query);
+ ret = _media_svc_request_update_db(db_query, uid);
return _media_svc_error_convert(ret);
}
media_svc_retvm_if(count == NULL, MEDIA_INFO_ERROR_INVALID_PARAMETER, "count is NULL");
return _media_svc_count_invalid_folder_items(db_handle, folder_path, count);
-}
\ No newline at end of file
+}