Change GPtrArray to GList to improve readability 48/255648/4
authorMinje Ahn <minje.ahn@samsung.com>
Mon, 22 Mar 2021 05:29:51 +0000 (14:29 +0900)
committerMinje Ahn <minje.ahn@samsung.com>
Mon, 22 Mar 2021 23:53:54 +0000 (08:53 +0900)
Change-Id: I47f5886952853655cf56df66515072789f537d01
Signed-off-by: Minje Ahn <minje.ahn@samsung.com>
packaging/libmedia-service.spec
src/common/media-svc-media.c
src/common/media-svc.c
src/include/common/media-svc-media.h

index 3276801..483f537 100644 (file)
@@ -24,6 +24,7 @@ BuildRequires:  pkgconfig(libtzplatform-config)
 BuildRequires:  pkgconfig(capi-system-info)
 BuildRequires:  pkgconfig(mmutil-magick)
 BuildRequires:  pkgconfig(media-thumbnail)
+
 %if 0%{?gtests:1}
 BuildRequires:  pkgconfig(gmock)
 %endif
index 9effc26..1a5ac5a 100755 (executable)
@@ -458,21 +458,18 @@ int _media_svc_append_query_list(const char *query, uid_t uid)
        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);
 
index 0ca6a5e..3c81eb7 100755 (executable)
@@ -586,46 +586,41 @@ static void __media_svc_noti_all_storage(sqlite3 *handle, uid_t uid)
        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);
 
index 8d8b401..5ade78d 100755 (executable)
@@ -41,6 +41,6 @@ int _media_svc_get_noti_info(sqlite3 *handle, const char *path, media_svc_noti_i
 int _media_svc_update_meta_with_data(media_svc_content_info_s *content_info);
 
 int _media_svc_append_query_list(const char *query, uid_t uid);
-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);
 
 #endif /*_MEDIA_SVC_MEDIA_H_*/