/**
* @brief Moves the media info to the given destination path in the media database.
- * @details After moving or renaming a file in the filesystem, call this function to update the database.
+ * @details After moving or renaming a file in the filesystem, call this function to update the database. \n
+ * If the source path and destination path are the same, then this API does nothing.
+ * If you want to refresh media information, you should use media_content_scan_file() API.
*
* @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
*
ret = _media_content_replace_path(_media->file_path, org_repl_path);
media_content_retvm_if(!STRING_VALID(org_repl_path), MEDIA_CONTENT_ERROR_INVALID_OPERATION, "path replacement failed");
+ /* If the two paths are the same, do nothing */
+ media_content_retvm_if(g_strcmp0(repl_path, org_repl_path) == 0, MEDIA_CONTENT_ERROR_NONE, "Same path");
+
ret = __media_info_check_file_validity(repl_path);
media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
return _content_error_capi(MEDIA_CONTENT_TYPE, ret);
}
+ /*Delete the media info of the dest_path if it already exists.*/
+ ret = media_svc_check_item_exist_by_path(_content_get_db_handle(), storage_id, repl_path);
+ if (ret == MS_MEDIA_ERR_NONE) {
+ /* Exists */
+ ret = media_svc_delete_item_by_path(_content_get_db_handle(), storage_id, repl_path, _content_get_uid());
+ if (ret != MS_MEDIA_ERR_NONE) {
+ media_content_error("media_svc_delete_item_by_path failed : %d", ret);
+ return _content_error_capi(MEDIA_CONTENT_TYPE, ret);
+ }
+ } else if (ret != MS_MEDIA_ERR_NONE && ret != MS_MEDIA_ERR_DB_NO_RECORD) {
+ media_content_error("media_svc_check_item_exist_by_path failed : %d", ret);
+ return _content_error_capi(MEDIA_CONTENT_TYPE, ret);
+ }
+
ret = media_svc_move_item(_content_get_db_handle(), storage_id, src_storage_type, org_repl_path, dst_storage_type, repl_path, _content_get_uid());
return _content_error_capi(MEDIA_CONTENT_TYPE, ret);
}