#define MEDIA_SVC_MAX_COMMIT_SIZE 200
-typedef struct {
- char thumbnail_path[MEDIA_SVC_PATHNAME_SIZE];
-} media_svc_thumbnailpath_s;
-
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_list = NULL;
static __thread int g_media_svc_update_list_count = 0;
-static int __media_svc_count_invalid_records_with_thumbnail(sqlite3 *handle, const char *storage_id, media_svc_storage_type_e storage_type, int *count);
-static int __media_svc_get_invalid_records_with_thumbnail(sqlite3 *handle, const char *storage_id, media_svc_storage_type_e storage_type, int count, media_svc_thumbnailpath_s *thumb_path);
-static int __media_svc_count_invalid_folder_records_with_thumbnail(sqlite3 *handle, const char *storage_id, const char *folder_path, const char *folder_uuid, bool is_recursive, int *count);
-static int __media_svc_get_invalid_folder_records_with_thumbnail(sqlite3 *handle, const char *storage_id, const char *folder_path, const char *folder_uuid, bool is_recursive, int count, media_svc_thumbnailpath_s *thumb_path);
-
-static int __media_svc_count_invalid_records_with_thumbnail(sqlite3 *handle, const char *storage_id, media_svc_storage_type_e storage_type, int *count)
-{
- int ret = MS_MEDIA_ERR_NONE;
- sqlite3_stmt *sql_stmt = NULL;
- char *sql = sqlite3_mprintf("SELECT count(*) FROM '%s' WHERE validity=0 AND storage_type=%d AND thumbnail_path IS NOT NULL",
- storage_id, storage_type);
-
- ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
-
- if (ret != MS_MEDIA_ERR_NONE) {
- media_svc_error("error when __media_svc_count_invalid_records_with_thumbnail. err = [%d]", ret);
- return ret;
- }
-
- *count = sqlite3_column_int(sql_stmt, 0);
-
- SQLITE3_FINALIZE(sql_stmt);
-
- return MS_MEDIA_ERR_NONE;
-
-}
-
-static int __media_svc_get_invalid_records_with_thumbnail(sqlite3 *handle, const char *storage_id, media_svc_storage_type_e storage_type,
- int count, media_svc_thumbnailpath_s * thumb_path)
+static int __media_svc_get_invalid_records_with_thumbnail(sqlite3 *handle, media_svc_storage_type_e storage_type, GArray **thumb_path)
{
int ret = MS_MEDIA_ERR_NONE;
sqlite3_stmt *sql_stmt = NULL;
- int idx = 0;
-
- char *sql = sqlite3_mprintf("SELECT thumbnail_path from (select thumbnail_path, validity from '%s' WHERE storage_type=%d AND thumbnail_path IS NOT NULL GROUP BY thumbnail_path HAVING count() = 1) WHERE validity=0",
- MEDIA_SVC_DB_TABLE_MEDIA, storage_type);
+ char *sql = sqlite3_mprintf("SELECT thumbnail_path FROM '%s' WHERE validity=0 AND storage_type=%d AND thumbnail_path IS NOT NULL", MEDIA_SVC_DB_TABLE_MEDIA, storage_type);
media_svc_debug("[SQL query] : %s", sql);
- ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
- if (ret != MS_MEDIA_ERR_NONE) {
- media_svc_error("error when __media_svc_get_invalid_records_with_thumbnail. err = [%d]", ret);
- return ret;
- }
+ ret = _media_svc_sql_prepare_to_step_simple(handle, sql, &sql_stmt);
+ media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "Query failed. err[%d]", ret);
while (sqlite3_step(sql_stmt) == SQLITE_ROW) {
- SAFE_STRLCPY(thumb_path[idx].thumbnail_path, (const char *)sqlite3_column_text(sql_stmt, 0), sizeof(thumb_path[idx]));
- idx++;
- }
-
- SQLITE3_FINALIZE(sql_stmt);
-
- return MS_MEDIA_ERR_NONE;
-}
-
-static int __media_svc_count_invalid_folder_records_with_thumbnail(sqlite3 *handle, const char *storage_id, const char *folder_path, const char *folder_uuid, bool is_recursive, int *count)
-{
- int ret = MS_MEDIA_ERR_NONE;
- sqlite3_stmt *sql_stmt = NULL;
- char *sql = NULL;
-
- if (is_recursive)
- sql = sqlite3_mprintf("SELECT count(*) FROM '%s' WHERE validity=0 AND path LIKE '%q/%%' AND thumbnail_path IS NOT NULL", storage_id, folder_path);
- else
- sql = sqlite3_mprintf("SELECT count(*) FROM '%s' WHERE validity=0 AND folder_uuid = '%q' AND thumbnail_path IS NOT NULL", storage_id, folder_uuid);
-
- ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
-
- if (ret != MS_MEDIA_ERR_NONE) {
- media_svc_error("error when __media_svc_count_invalid_folder_records_with_thumbnail. err = [%d]", ret);
- return ret;
+ char *path = NULL;
+ path = g_strdup((const char *)sqlite3_column_text(sql_stmt, 0));
+ g_array_append_val(*thumb_path, path);
}
- *count = sqlite3_column_int(sql_stmt, 0);
-
SQLITE3_FINALIZE(sql_stmt);
return MS_MEDIA_ERR_NONE;
-
}
-static int __media_svc_get_invalid_folder_records_with_thumbnail(sqlite3 *handle, const char *storage_id, const char *folder_path, const char *folder_uuid, bool is_recursive,
- int count, media_svc_thumbnailpath_s * thumb_path)
+static int __media_svc_get_invalid_folder_records_with_thumbnail(sqlite3 *handle, const char *folder_path, const char *folder_uuid, bool is_recursive, GArray **thumb_path)
{
int ret = MS_MEDIA_ERR_NONE;
sqlite3_stmt *sql_stmt = NULL;
- int idx = 0;
char *sql = NULL;
if (is_recursive)
- sql = sqlite3_mprintf("SELECT thumbnail_path from (select thumbnail_path, validity from '%s' WHERE path LIKE '%q/%%' AND thumbnail_path IS NOT NULL GROUP BY thumbnail_path HAVING count() = 1) WHERE validity=0", storage_id, folder_path);
+ sql = sqlite3_mprintf("SELECT thumbnail_path FROM '%s' WHERE validity=0 AND path LIKE '%q/%%' AND thumbnail_path IS NOT NULL", MEDIA_SVC_DB_TABLE_MEDIA, folder_path);
else
- sql = sqlite3_mprintf("SELECT thumbnail_path from (select thumbnail_path, validity from '%s' WHERE folder_uuid = '%q' AND thumbnail_path IS NOT NULL GROUP BY thumbnail_path HAVING count() = 1) WHERE validity=0", storage_id, folder_uuid);
+ sql = sqlite3_mprintf("SELECT thumbnail_path FROM '%s' WHERE validity=0 AND folder_uuid = '%q' AND thumbnail_path IS NOT NULL", MEDIA_SVC_DB_TABLE_MEDIA, folder_uuid);
media_svc_debug("[SQL query] : %s", sql);
ret = _media_svc_sql_prepare_to_step_simple(handle, sql, &sql_stmt);
- if (ret != MS_MEDIA_ERR_NONE) {
- media_svc_error("error when __media_svc_get_invalid_folder_records_with_thumbnail. err = [%d]", ret);
- return ret;
- }
+ media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "Query failed. err[%d]", ret);
while (sqlite3_step(sql_stmt) == SQLITE_ROW) {
- SAFE_STRLCPY(thumb_path[idx].thumbnail_path, (const char *)sqlite3_column_text(sql_stmt, 0), sizeof(thumb_path[idx]));
- idx++;
+ char *path = NULL;
+ path = g_strdup((const char *)sqlite3_column_text(sql_stmt, 0));
+ g_array_append_val(*thumb_path, path);
}
SQLITE3_FINALIZE(sql_stmt);
return ret;
}
-int _media_svc_get_thumbnail_path_by_path(sqlite3 *handle, const char *storage_id, const char *path, char *thumbnail_path)
+int _media_svc_get_thumbnail_path_by_path(sqlite3 *handle, const char *path, char *thumbnail_path)
{
int ret = MS_MEDIA_ERR_NONE;
sqlite3_stmt *sql_stmt = NULL;
- char *sql = sqlite3_mprintf("SELECT thumbnail_path FROM '%s' WHERE path='%q'", storage_id, path);
+ char *sql = sqlite3_mprintf("SELECT thumbnail_path FROM '%s' WHERE path='%q'", MEDIA_SVC_DB_TABLE_MEDIA, path);
ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt);
int _media_svc_delete_invalid_items(sqlite3 *handle, const char *storage_id, media_svc_storage_type_e storage_type, uid_t uid)
{
- int idx = 0;
- media_svc_thumbnailpath_s *thumbpath_record = NULL;
- int invalid_count = 0;
int ret = MS_MEDIA_ERR_NONE;
+ GArray *thumb_list = NULL;
- ret = __media_svc_count_invalid_records_with_thumbnail(handle, storage_id, storage_type, &invalid_count);
- media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
-
- media_svc_debug("invalid count: %d", invalid_count);
-
- if (invalid_count > 0) {
- thumbpath_record = (media_svc_thumbnailpath_s *)calloc(invalid_count, sizeof(media_svc_thumbnailpath_s));
- if (thumbpath_record == NULL) {
- media_svc_error("fail to memory allocation");
- return MS_MEDIA_ERR_OUT_OF_MEMORY;
- }
+ thumb_list = g_array_new(FALSE, FALSE, sizeof(char*));
- ret = __media_svc_get_invalid_records_with_thumbnail(handle, storage_id, storage_type, invalid_count, thumbpath_record);
+ /*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);
if (ret != MS_MEDIA_ERR_NONE) {
media_svc_error("error when get thumbnail record");
- SAFE_FREE(thumbpath_record);
+ g_array_free(thumb_list, false);
+ thumb_list = NULL;
return ret;
}
- } else {
- media_svc_debug("There is no item with thumbnail");
}
char *sql = sqlite3_mprintf("DELETE FROM '%s' WHERE validity = 0;", storage_id);
ret = _media_svc_sql_query(sql, uid);
SQLITE3_SAFE_FREE(sql);
if (ret != MS_MEDIA_ERR_NONE) {
- SAFE_FREE(thumbpath_record);
+ while (thumb_list->len != 0) {
+ char *thumb_path = NULL;
+ thumb_path = g_array_index(thumb_list , char*, 0);
+ g_array_remove_index(thumb_list, 0);
+ SAFE_FREE(thumb_path);
+ }
+ g_array_free(thumb_list, false);
+ thumb_list = NULL;
return ret;
}
/*Delete thumbnails*/
- for (idx = 0; idx < invalid_count; idx++) {
- if (STRING_VALID(thumbpath_record[idx].thumbnail_path)) {
- ret = _media_svc_remove_file(thumbpath_record[idx].thumbnail_path);
- if (ret != MS_MEDIA_ERR_NONE)
- media_svc_error("fail to remove thumbnail file.");
- }
+ while (thumb_list->len != 0) {
+ char *thumb_path = NULL;
+ thumb_path = g_array_index(thumb_list , char*, 0);
+ g_array_remove_index(thumb_list, 0);
+
+ ret = _media_svc_remove_file(thumb_path);
+ if (ret != MS_MEDIA_ERR_NONE)
+ media_svc_error("fail to remove thumbnail file.");
+
+ SAFE_FREE(thumb_path);
}
- SAFE_FREE(thumbpath_record);
+ g_array_free(thumb_list, false);
+ thumb_list = NULL;
return MS_MEDIA_ERR_NONE;
}
int _media_svc_delete_invalid_folder_items(sqlite3 *handle, const char *storage_id, const char *folder_path, bool is_recursive, uid_t uid)
{
- int idx = 0;
- media_svc_thumbnailpath_s *thumbpath_record = NULL;
- int invalid_count = 0;
int ret = MS_MEDIA_ERR_NONE;
char folder_uuid[MEDIA_SVC_UUID_SIZE+1] = {0,};
+ GArray *thumb_list = NULL;
char *sql = NULL;
/*get folder uuid from DB*/
ret = _media_svc_get_folder_id_by_foldername(handle, storage_id, folder_path, folder_uuid, uid);
media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
- ret = __media_svc_count_invalid_folder_records_with_thumbnail(handle, storage_id, folder_path, folder_uuid, is_recursive, &invalid_count);
- media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
-
- media_svc_debug("invalid count: %d", invalid_count);
-
- if (invalid_count > 0) {
- thumbpath_record = (media_svc_thumbnailpath_s *)calloc(invalid_count, sizeof(media_svc_thumbnailpath_s));
- if (thumbpath_record == NULL) {
- media_svc_error("fail to memory allocation");
- return MS_MEDIA_ERR_OUT_OF_MEMORY;
- }
+ thumb_list = g_array_new(FALSE, FALSE, sizeof(char*));
- ret = __media_svc_get_invalid_folder_records_with_thumbnail(handle, storage_id, folder_path, folder_uuid, is_recursive, invalid_count, thumbpath_record);
- if (ret != MS_MEDIA_ERR_NONE) {
- media_svc_error("error when get thumbnail record");
- SAFE_FREE(thumbpath_record);
- return ret;
- }
- } else {
- media_svc_debug("There is no item with thumbnail");
+ ret = __media_svc_get_invalid_folder_records_with_thumbnail(handle, folder_path, folder_uuid, is_recursive, &thumb_list);
+ if (ret != MS_MEDIA_ERR_NONE) {
+ media_svc_error("error when get thumbnail record");
+ g_array_free(thumb_list, false);
+ thumb_list = NULL;
+ return ret;
}
if (is_recursive)
ret = _media_svc_sql_query(sql, uid);
SQLITE3_SAFE_FREE(sql);
if (ret != MS_MEDIA_ERR_NONE) {
- SAFE_FREE(thumbpath_record);
+ while (thumb_list->len != 0) {
+ char *thumb_path = NULL;
+ thumb_path = g_array_index(thumb_list , char*, 0);
+ g_array_remove_index(thumb_list, 0);
+ SAFE_FREE(thumb_path);
+ }
+ g_array_free(thumb_list, false);
+ thumb_list = NULL;
+
return ret;
}
/*Delete thumbnails*/
- if (thumbpath_record != NULL) {
- for (idx = 0; idx < invalid_count; idx++) {
- if (STRING_VALID(thumbpath_record[idx].thumbnail_path)) {
- ret = _media_svc_remove_file(thumbpath_record[idx].thumbnail_path);
- if (ret != MS_MEDIA_ERR_NONE)
- media_svc_error("fail to remove thumbnail file.");
- }
- }
+ while (thumb_list->len != 0) {
+ char *thumb_path = NULL;
+ thumb_path = g_array_index(thumb_list , char*, 0);
+ g_array_remove_index(thumb_list, 0);
+
+ ret = _media_svc_remove_file(thumb_path);
+ if (ret != MS_MEDIA_ERR_NONE)
+ media_svc_error("fail to remove thumbnail file.");
- SAFE_FREE(thumbpath_record);
+ SAFE_FREE(thumb_path);
}
+ g_array_free(thumb_list, false);
+ thumb_list = NULL;
+
return MS_MEDIA_ERR_NONE;
}
return ret;
}
-int _media_svc_update_thumbnail_path(const char *storage_id, const char *path, const char *thumb_path, uid_t uid)
+int _media_svc_update_thumbnail_path(const char *path, const char *thumb_path, uid_t uid)
{
int ret = MS_MEDIA_ERR_NONE;
- char *sql = sqlite3_mprintf("UPDATE '%s' SET thumbnail_path=%Q WHERE path= %Q;", storage_id, thumb_path, path);
+ char *sql = sqlite3_mprintf("UPDATE '%s' SET thumbnail_path=%Q WHERE path= %Q;", MEDIA_SVC_DB_TABLE_MEDIA, thumb_path, path);
ret = _media_svc_sql_query(sql, uid);
SQLITE3_SAFE_FREE(sql);
return ret;
}
-int _media_svc_update_item_by_path(const char *storage_id, const char *src_path, media_svc_storage_type_e dest_storage, const char *dest_path,
+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)
{
/* update path, filename, modified_time, folder_uuid, thumbnail_path, */
if (thumb_path != NULL) {
sql = sqlite3_mprintf("UPDATE '%s' 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;",
- storage_id, dest_path, file_name, modified_time, folder_uuid, thumb_path, dest_storage, src_path);
+ MEDIA_SVC_DB_TABLE_MEDIA, dest_path, file_name, modified_time, folder_uuid, thumb_path, dest_storage, src_path);
} else {
sql = sqlite3_mprintf("UPDATE '%s' 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;",
- storage_id, dest_path, file_name, modified_time, folder_uuid, dest_storage, src_path);
+ MEDIA_SVC_DB_TABLE_MEDIA, dest_path, file_name, modified_time, folder_uuid, dest_storage, src_path);
}
if (!stack_query) {
media_svc_error("_media_svc_make_table_query fail.");
goto ERROR;
}
-#if 0
- /*init storage table*/
- ret = _media_svc_init_storage(db_handle, uid);
- if (ret != MS_MEDIA_ERR_NONE) {
- media_svc_error("_media_svc_make_table_query fail.");
- goto ERROR;
- }
-#endif
/*create face table. from tizen 3.0*/
ret = _media_svc_make_table_query(MEDIA_SVC_DB_TABLE_FACE_SCAN_LIST, MEDIA_SVC_DB_LIST_FACE_SCAN_LIST, uid);
if (ret != MS_MEDIA_ERR_NONE) {
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, storage_id, src_path, old_thumb_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);
/*update item*/
if ((media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE) || (media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO))
- ret = _media_svc_update_item_by_path(storage_id, src_path, dest_storage, dest_path, file_name, modified_time, folder_uuid, new_thumb_path, FALSE, uid);
+ 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(storage_id, src_path, dest_storage, dest_path, file_name, modified_time, folder_uuid, NULL, FALSE, uid);
+ 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);
/*update item*/
if ((media_type == MEDIA_SVC_MEDIA_TYPE_IMAGE) || (media_type == MEDIA_SVC_MEDIA_TYPE_VIDEO))
- ret = _media_svc_update_item_by_path(storage_id, src_path, dest_storage, dest_path, file_name, modified_time, folder_uuid, new_thumb_path, TRUE, uid);
+ 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(storage_id, src_path, dest_storage, dest_path, file_name, modified_time, folder_uuid, NULL, TRUE, uid);
+ ret = _media_svc_update_item_by_path(src_path, dest_storage, dest_path, file_name, modified_time, folder_uuid, NULL, TRUE, uid);
SAFE_FREE(file_name);
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(storage_id, src_path, dest_storage, dest_path, file_name, modified_time, folder_uuid, new_thumb_path, TRUE, uid);
+ 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(storage_id, src_path, dest_storage, dest_path, file_name, modified_time, folder_uuid, NULL, TRUE, uid);
+ ret = _media_svc_update_item_by_path(src_path, dest_storage, dest_path, file_name, modified_time, folder_uuid, NULL, TRUE, uid);
SAFE_FREE(file_name);
media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret);
media_svc_retv_if((ret != MS_MEDIA_ERR_NONE), ret);
/*Get thumbnail path to delete*/
- ret = _media_svc_get_thumbnail_path_by_path(db_handle, storage_id, path, thumb_path);
+ ret = _media_svc_get_thumbnail_path_by_path(db_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) {
/* Initialize thumbnail information to remake thumbnail. */
char thumb_path[MEDIA_SVC_PATHNAME_SIZE + 1];
- ret = _media_svc_get_thumbnail_path_by_path(db_handle, storage_id, path, thumb_path);
+ ret = _media_svc_get_thumbnail_path_by_path(db_handle, path, thumb_path);
if (ret != MS_MEDIA_ERR_NONE) {
_media_svc_destroy_content_info(&content_info);
return ret;
media_svc_error("_media_svc_remove_file failed : %s", thumb_path);
}
- ret = _media_svc_update_thumbnail_path(storage_id, path, NULL, uid);
+ ret = _media_svc_update_thumbnail_path(path, NULL, uid);
if (ret != MS_MEDIA_ERR_NONE) {
_media_svc_destroy_content_info(&content_info);
return ret;