sql = sqlite3_mprintf("pragma user_version = %d;", LATEST_DB_VERSION);
ret = _media_svc_sql_query(sql, uid);
+ SQLITE3_SAFE_FREE(sql);
if (ret != MS_MEDIA_ERR_NONE) {
media_svc_error("user_version update fail.");
goto ERROR;
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;
- }
+ SQLITE3_SAFE_FREE(sql);
+ media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "Fail to get media list");
- 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;
- }
+ if (path_list) {
+ g_list_foreach(path_list, __media_svc_foreach_update_media, NULL);
+ g_list_free_full(path_list, g_free);
- 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);
-
- _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);