Use GPtrArray instead of GArray 84/240384/1
authorMinje Ahn <minje.ahn@samsung.com>
Thu, 6 Aug 2020 03:40:38 +0000 (12:40 +0900)
committerMinje Ahn <minje.ahn@samsung.com>
Thu, 6 Aug 2020 03:40:38 +0000 (12:40 +0900)
Change-Id: I65b727380726ff3e86318a6682272628b840a55f
Signed-off-by: Minje Ahn <minje.ahn@samsung.com>
src/scanner-v2/media-scanner-scan-v2.c

index fe271fe..3c18d69 100644 (file)
@@ -87,8 +87,7 @@ struct linux_dirent {
 #define BUF_SIZE 1024
 
 static int __msc_check_stop_status(int scan_type, const char *start_path, int pid);
-static void __msc_clear_file_list(GArray *path_array);
-static int __msc_get_null_scan_folder_list(sqlite3 *handle, const char *stroage_id, char *path, GArray *dir_array);
+static int __msc_get_null_scan_folder_list(sqlite3 *handle, const char *stroage_id, char *path, GPtrArray *dir_array);
 static int __msc_dir_scan_cb(void);
 static int __msc_check_scan_same_path(char *scan_path);
 static void __msc_set_storage_scan_cur_path(char *scan_path);
@@ -226,7 +225,7 @@ END:
 
 static int __msc_dir_scan_for_folder(sqlite3 *handle, const char *storage_id, char *start_path, int scan_type, int pid, uid_t uid)
 {
-       GArray *dir_array = NULL;
+       GPtrArray *dir_array = NULL;
        int ret = MS_MEDIA_ERR_NONE;
        char *new_path = NULL;
        char *current_path = NULL;
@@ -245,21 +244,13 @@ static int __msc_dir_scan_for_folder(sqlite3 *handle, const char *storage_id, ch
 
        MS_DBG_SWARN("storage id [%s] start path [%s]", storage_id, start_path);
 
-       /* make new array for storing directory */
-       dir_array = g_array_new(FALSE, FALSE, sizeof(char *));
-
-       /* add first direcotiry to directory array */
        new_start_path = g_strdup(start_path);
 
-       //MS_DBG_ERR("new start path [%s]", new_start_path);
-       g_array_append_val(dir_array, start_path);
+       dir_array = g_ptr_array_new();
+       g_ptr_array_add(dir_array, start_path);
 
        is_recursive = (scan_type == MS_MSG_DIRECTORY_SCANNING_NON_RECURSIVE) ? false : true;
 
-       /* fix timing issue, folder uuid of start path mismatch in folder and media table*/
-       /*if (ms_set_folder_validity(handle, storage_id, new_start_path, MS_INVALID, is_recursive, uid) != MS_MEDIA_ERR_NONE)
-               MS_DBG_ERR("set_folder_validity failed [%d] ", scan_type);*/
-
        if (g_file_test(new_start_path, G_FILE_TEST_IS_DIR)) {
                if (ms_insert_folder(handle, storage_id, new_start_path, uid) != MS_MEDIA_ERR_NONE)
                        MS_DBG_ERR("insert folder failed");
@@ -284,8 +275,8 @@ static int __msc_dir_scan_for_folder(sqlite3 *handle, const char *storage_id, ch
                ms_batch_commit_disable(uid);
                ms_batch_commit_enable(false, pid);
                /* get the current path from directory array */
-               current_path = g_array_index(dir_array , char*, 0);
-               g_array_remove_index(dir_array, 0);
+               current_path = g_ptr_array_index(dir_array , 0);
+               g_ptr_array_remove_index(dir_array, 0);
 
                __msc_set_dir_scan_cur_path(current_path);
 
@@ -438,7 +429,7 @@ static int __msc_dir_scan_for_folder(sqlite3 *handle, const char *storage_id, ch
                                                /* this request is recursive scanning */
                                                /* add new directory to dir_array */
                                                new_path = g_strdup(path);
-                                               g_array_append_val(dir_array, new_path);
+                                               g_ptr_array_add(dir_array, new_path);
 
                                                if (ms_insert_folder(handle, storage_id, new_path, uid) != MS_MEDIA_ERR_NONE)
                                                        MS_DBG_ERR("insert folder failed");
@@ -488,7 +479,7 @@ END_SCAN:
        g_free(new_start_path);
        __msc_set_dir_scan_cur_path(NULL);
 
-       __msc_clear_file_list(dir_array);
+       g_ptr_array_free(dir_array, TRUE);
 
        ms_batch_commit_disable(uid);
 
@@ -499,7 +490,7 @@ END_SCAN:
 
 static int __msc_dir_scan_for_storage(sqlite3 *handle, const char *storage_id, char *start_path, int scan_type, int pid, uid_t uid)
 {
-       GArray *dir_array = NULL;
+       GPtrArray *dir_array = NULL;
        int ret = MS_MEDIA_ERR_NONE;
        char *new_path = NULL;
        char *current_path = NULL;
@@ -520,13 +511,11 @@ static int __msc_dir_scan_for_storage(sqlite3 *handle, const char *storage_id, c
 
        MS_DBG_SWARN("storage id [%s] start path [%s]", storage_id, start_path);
 
-       /* make new array for storing directory */
-       dir_array = g_array_new(FALSE, FALSE, sizeof(char*));
-
-       /* add first directory to directory array */
        new_start_path = g_strdup(start_path);
 
-       g_array_append_val(dir_array, start_path);
+       dir_array = g_ptr_array_new();
+       g_ptr_array_add(dir_array, start_path);
+
        if (ms_insert_folder(handle, storage_id, new_start_path, uid) != MS_MEDIA_ERR_NONE)
                MS_DBG_ERR("insert folder failed");
 
@@ -544,8 +533,8 @@ static int __msc_dir_scan_for_storage(sqlite3 *handle, const char *storage_id, c
                ms_batch_commit_enable(false, pid);
 
                /* get the current path from directory array */
-               current_path = g_array_index(dir_array , char*, 0);
-               g_array_remove_index(dir_array, 0);
+               current_path = g_ptr_array_index(dir_array, 0);
+               g_ptr_array_remove_index(dir_array, 0);
 
                __msc_set_storage_scan_cur_path(current_path);
 
@@ -693,7 +682,7 @@ static int __msc_dir_scan_for_storage(sqlite3 *handle, const char *storage_id, c
                                        /* this request is recursive scanning */
                                        /* add new directory to dir_array */
                                        new_path = g_strdup(path);
-                                       g_array_append_val(dir_array, new_path);
+                                       g_ptr_array_add(dir_array, new_path);
 
                                        if (ms_insert_folder(handle, storage_id, new_path, uid) != MS_MEDIA_ERR_NONE)
                                                MS_DBG_ERR("insert folder failed");
@@ -789,7 +778,7 @@ EXIT:
 
        g_free(new_start_path);
        __msc_set_storage_scan_cur_path(NULL);
-       __msc_clear_file_list(dir_array);
+       g_ptr_array_free(dir_array, TRUE);
 
        ms_batch_commit_disable(uid);
 
@@ -798,10 +787,9 @@ EXIT:
        return ret;
 }
 
-static int __msc_get_null_scan_folder_list(sqlite3 *handle, const char *stroage_id, char *path, GArray *dir_array)
+static int __msc_get_null_scan_folder_list(sqlite3 *handle, const char *stroage_id, char *path, GPtrArray *dir_array)
 {
        int ret = MS_MEDIA_ERR_NONE;
-       char *new_path = NULL;
        char *current_path = NULL;
        GArray *cur_dir_array = NULL;
 
@@ -810,17 +798,15 @@ static int __msc_get_null_scan_folder_list(sqlite3 *handle, const char *stroage_
        if (ret == MS_MEDIA_ERR_NONE) {
                MS_DBG_WARN("cur_dir_array->len = [%d]", cur_dir_array->len);
                while (cur_dir_array->len != 0) {
-                       current_path = g_array_index(cur_dir_array , char*, 0);
+                       current_path = g_array_index(cur_dir_array , char *, 0);
                        g_array_remove_index(cur_dir_array, 0);
                        MS_DBG_SLOG("current_path = [%s]", current_path);
 
-                       new_path = g_strdup(current_path);
-                       g_array_append_val(dir_array, new_path);
-                       g_free(current_path);
+                       g_ptr_array_add(dir_array, current_path);
                }
        }
 
-       __msc_clear_file_list(cur_dir_array);
+       g_array_free(cur_dir_array, FALSE);
 
        return ret;
 }
@@ -1380,20 +1366,6 @@ _POWEROFF:
        return NULL;
 }
 
-static void __msc_clear_file_list(GArray *path_array)
-{
-       if (path_array) {
-               while (path_array->len != 0) {
-                       char *data = NULL;
-                       data = g_array_index(path_array , char*, 0);
-                       g_array_remove_index(path_array, 0);
-                       g_free(data);
-               }
-               g_array_free(path_array, FALSE);
-               path_array = NULL;
-       }
-}
-
 static int __msc_make_file_list(char *file_path, GPtrArray **path_array, uid_t uid)
 {
        FILE *fp = NULL;