return ret;
}
-int _media_svc_get_media(sqlite3 *handle, const char *sql, GPtrArray **path_list)
+int _media_svc_get_media(sqlite3 *handle, const char *sql, GList **path_list)
{
int ret = MS_MEDIA_ERR_NONE;
sqlite3_stmt *sql_stmt = NULL;
- char *path = NULL;
media_svc_retvm_if(!sql, MS_MEDIA_ERR_INVALID_PARAMETER, "query is NULL");
media_svc_retvm_if(!path_list, MS_MEDIA_ERR_INVALID_PARAMETER, "array is NULL");
ret = _media_svc_sql_prepare_to_step_simple(handle, sql, &sql_stmt);
media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "_media_svc_sql_prepare_to_step_simple() failed [%d]", ret);
- while (sqlite3_step(sql_stmt) == SQLITE_ROW) {
- path = g_strdup((const char *)sqlite3_column_text(sql_stmt, 0));
- g_ptr_array_add(*path_list, path);
- }
+ while (sqlite3_step(sql_stmt) == SQLITE_ROW)
+ *path_list = g_list_append(*path_list, g_strdup((const char *)sqlite3_column_text(sql_stmt, 0)));
SQLITE3_FINALIZE(sql_stmt);
g_ptr_array_free(path_list, TRUE);
}
+static void __media_svc_foreach_update_media(gpointer data, gpointer user_data)
+{
+ media_svc_content_info_s content_info = {0, };
+
+ if (_media_svc_extract_music_metadata_for_update(&content_info, (const char *)data) != MS_MEDIA_ERR_NONE) {
+ media_svc_error("Fail to extract metadata");
+ _media_svc_destroy_content_info(&content_info);
+ return;
+ }
+
+ if (_media_svc_update_meta_with_data(&content_info) != MS_MEDIA_ERR_NONE)
+ media_svc_error("Fail to append item[%s]", content_info.path);
+
+ _media_svc_destroy_content_info(&content_info);
+}
+
int media_svc_update_item_meta(sqlite3 *handle, uid_t uid)
{
int ret = MS_MEDIA_ERR_NONE;
- int i = 0;
char *sql = NULL;
- char *file_path = NULL;
- media_svc_content_info_s content_info;
- GPtrArray *path_list = g_ptr_array_new_with_free_func(g_free);
+ GList *path_list = NULL;
sql = sqlite3_mprintf("SELECT media_path FROM %q WHERE media_type=3 AND validity=1", DB_TABLE_MEDIA);
ret = _media_svc_get_media(handle, sql, &path_list);
- if (ret != MS_MEDIA_ERR_NONE) {
- media_svc_error("Fail to get media list");
- g_ptr_array_free(path_list, TRUE);
- return ret;
- }
-
- for (i = 0; i < path_list->len; i++) {
- file_path = g_ptr_array_index(path_list, i);
-
- memset(&content_info, 0, sizeof(media_svc_content_info_s));
- ret = _media_svc_extract_music_metadata_for_update(&content_info, file_path);
- if (ret != MS_MEDIA_ERR_NONE) {
- media_svc_error("Fail to extract metadata");
- _media_svc_destroy_content_info(&content_info);
- continue;
- }
+ SQLITE3_SAFE_FREE(sql);
+ media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "Fail to get media list");
- ret = _media_svc_update_meta_with_data(&content_info);
- if (ret != MS_MEDIA_ERR_NONE)
- media_svc_error("Fail to append item[%s]", content_info.path);
+ if (path_list) {
+ g_list_foreach(path_list, __media_svc_foreach_update_media, NULL);
+ g_list_free_full(path_list, g_free);
- _media_svc_destroy_content_info(&content_info);
+ ret = _media_svc_list_query_do(MEDIA_SVC_QUERY_SCANNER, uid);
+ media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "_media_svc_list_query_do failed");
}
- g_ptr_array_free(path_list, TRUE);
-
- ret = _media_svc_list_query_do(MEDIA_SVC_QUERY_SCANNER, 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);