From 57c856a3af34b9a79e769af5bfed622c34369532 Mon Sep 17 00:00:00 2001 From: Minje Ahn Date: Wed, 4 Sep 2019 17:33:16 +0900 Subject: Change GArray to GPtrArray Change-Id: Ibf280ac4790f0606a37b80a16ddc13a59c7cd53a Signed-off-by: Minje Ahn --- src/common/media-svc-storage.c | 47 +++++++++------------------------- src/common/media-svc.c | 14 +++++----- src/include/common/media-svc-storage.h | 2 +- 3 files changed, 19 insertions(+), 44 deletions(-) diff --git a/src/common/media-svc-storage.c b/src/common/media-svc-storage.c index a39ea02..50cc443 100755 --- a/src/common/media-svc-storage.c +++ b/src/common/media-svc-storage.c @@ -150,70 +150,47 @@ int _media_svc_delete_invalid_storage(sqlite3 *handle, uid_t uid) int ret = MS_MEDIA_ERR_NONE; char *sql = NULL; char *storage_id = NULL; - char *thumb_path = NULL; sqlite3_stmt *sql_stmt = NULL; - GArray *storage_list = NULL; + GPtrArray *storage_list = NULL; + int i = 0; sql = sqlite3_mprintf("SELECT storage_id FROM '%q' WHERE validity=0;", MEDIA_SVC_DB_TABLE_STORAGE); ret = _media_svc_sql_prepare_to_step_simple(handle, sql, &sql_stmt); media_svc_retv_if(ret != MS_MEDIA_ERR_NONE, ret); - storage_list = g_array_new(false, false, sizeof(char *)); + storage_list = g_ptr_array_new_with_free_func(g_free); while (sqlite3_step(sql_stmt) == SQLITE_ROW) { storage_id = g_strdup((const char *)sqlite3_column_text(sql_stmt, 0)); if (storage_id != NULL) - g_array_append_val(storage_list, storage_id); - - storage_id = NULL; + g_ptr_array_add(storage_list, storage_id); } SQLITE3_FINALIZE(sql_stmt); - while ((storage_list != NULL) && (storage_list->len > 0)) { - storage_id = g_array_index(storage_list, char *, 0); - storage_list = g_array_remove_index(storage_list, 0); + for (i = 0; i < storage_list->len; i++) { + storage_id = g_ptr_array_index(storage_list, i); ret = __media_svc_delete_thumbnail(handle, storage_id); - if (ret != MS_MEDIA_ERR_NONE) { + if (ret != MS_MEDIA_ERR_NONE) media_svc_error("Fail to remove thumbnail"); - goto ERROR; - } /* remove media before drop table (for clear playlist, and tag table)*/ sql = sqlite3_mprintf("DELETE FROM '%q';DROP TABLE '%q';", storage_id, storage_id); ret = _media_svc_sql_query_direct(sql, uid); SQLITE3_SAFE_FREE(sql); - if (ret != MS_MEDIA_ERR_NONE) { + if (ret != MS_MEDIA_ERR_NONE) media_svc_error("Fail to drop table[%s]", storage_id); - goto ERROR; - } - - SAFE_FREE(storage_id); } /* Update storage, folder table */ sql = sqlite3_mprintf("DELETE FROM %q WHERE validity=0;DELETE FROM %q WHERE validity=0;", MEDIA_SVC_DB_TABLE_STORAGE, MEDIA_SVC_DB_TABLE_FOLDER); - ret = _media_svc_sql_query_direct(sql, uid); SQLITE3_SAFE_FREE(sql); - if (ret != MS_MEDIA_ERR_NONE) { + if (ret != MS_MEDIA_ERR_NONE) media_svc_error("Fail to update storage table"); - goto ERROR; - } - -ERROR: - SAFE_FREE(storage_id); - SAFE_FREE(thumb_path); - - while ((storage_list != NULL) && (storage_list->len > 0)) { - storage_id = g_array_index(storage_list, char *, 0); - storage_list = g_array_remove_index(storage_list, 0); - SAFE_FREE(storage_id); - } - g_array_free(storage_list, false); - storage_list = NULL; + g_ptr_array_free(storage_list, TRUE); return ret; } @@ -282,7 +259,7 @@ int _media_svc_get_storage_uuid(sqlite3 *handle, const char *path, char *storage return ret; } -int _media_svc_get_storage_path(sqlite3 *handle, GArray **storage_path) +int _media_svc_get_storage_path(sqlite3 *handle, GPtrArray **storage_path) { int ret = MS_MEDIA_ERR_NONE; sqlite3_stmt *sql_stmt = NULL; @@ -298,7 +275,7 @@ int _media_svc_get_storage_path(sqlite3 *handle, GArray **storage_path) while (sqlite3_step(sql_stmt) == SQLITE_ROW) { root_path = g_strdup((const char *)sqlite3_column_text(sql_stmt, 0)); - g_array_append_val(*storage_path, root_path); + g_ptr_array_add(*storage_path, root_path); } SQLITE3_FINALIZE(sql_stmt); diff --git a/src/common/media-svc.c b/src/common/media-svc.c index 7f6d928..2ef0f23 100755 --- a/src/common/media-svc.c +++ b/src/common/media-svc.c @@ -672,7 +672,8 @@ static void __media_svc_noti_all_storage(sqlite3 *handle, uid_t uid) { int ret = MS_MEDIA_ERR_NONE; char *root_path = NULL; - GArray *path_list = NULL; + GPtrArray *path_list = NULL; + int i = 0; ms_user_get_internal_root_path(uid, &root_path); ret = _media_svc_publish_dir_noti(MS_MEDIA_ITEM_UPDATE, root_path, NULL, 0); @@ -681,21 +682,18 @@ static void __media_svc_noti_all_storage(sqlite3 *handle, uid_t uid) SAFE_FREE(root_path); - path_list = g_array_new(FALSE, FALSE, sizeof(char *)); + path_list = g_ptr_array_new_with_free_func(g_free); _media_svc_get_storage_path(handle, &path_list); - while (path_list->len != 0) { - root_path = g_array_index(path_list , char *, 0); - g_array_remove_index(path_list, 0); + for (i = 0; i < path_list->len; i++) { + root_path = g_ptr_array_index(path_list, i); ret = _media_svc_publish_dir_noti(MS_MEDIA_ITEM_UPDATE, root_path, NULL, 0); if (ret != MS_MEDIA_ERR_NONE) media_svc_error("Fail to send noti"); - - SAFE_FREE(root_path); } - g_array_free(path_list, false); + g_ptr_array_free(path_list, TRUE); } int media_svc_update_item_meta(sqlite3 *handle, uid_t uid) diff --git a/src/include/common/media-svc-storage.h b/src/include/common/media-svc-storage.h index ccc482b..48f47a2 100755 --- a/src/include/common/media-svc-storage.h +++ b/src/include/common/media-svc-storage.h @@ -30,6 +30,6 @@ int _media_svc_update_storage_path(sqlite3 *handle, const char *storage_id, cons int _media_svc_delete_invalid_storage(sqlite3 *handle, uid_t uid); int _media_svc_update_storage_validity(const char *storage_id, int validity, uid_t uid); int _media_svc_get_storage_uuid(sqlite3 *handle, const char *path, char *storage_id, uid_t uid); -int _media_svc_get_storage_path(sqlite3 *handle, GArray **storage_path); +int _media_svc_get_storage_path(sqlite3 *handle, GPtrArray **storage_path); #endif /*_MEDIA_SVC_STORAGE_H_*/ -- cgit v1.2.3