Use GQueue instead of GPtrArray in scanner v1 91/242691/3
authorMinje Ahn <minje.ahn@samsung.com>
Mon, 31 Aug 2020 00:45:48 +0000 (09:45 +0900)
committerhj kim <backto.kim@samsung.com>
Mon, 31 Aug 2020 02:09:21 +0000 (11:09 +0900)
Change-Id: I2c5fdf15d6e88fa5995ca98e6ea8d4db5df1dd0e
Signed-off-by: Minje Ahn <minje.ahn@samsung.com>
src/scanner/media-scanner-scan.c

index 779c04c..37f65e4 100644 (file)
@@ -52,20 +52,17 @@ static int __msc_dir_scan(sqlite3 *handle, const char *storage_id, char *start_p
        GDir *dir = NULL;
        GError *error = NULL;
        const char *name;
-       GPtrArray *dir_array = NULL;
+       GQueue *dir_queue = NULL;
        char *current_path = NULL;
        char *path = NULL;
        int (*scan_function)(sqlite3 *, const char*, const char*, uid_t) = NULL;
 
-       dir_array = g_ptr_array_new();
-       g_ptr_array_add(dir_array, start_path);
+       dir_queue = g_queue_new();
+       g_queue_push_tail(dir_queue, start_path);
 
        scan_function = (check_exists == false) ? ms_insert_item_batch : ms_validate_item;
 
-       while (dir_array->len != 0) {
-               current_path = g_ptr_array_index(dir_array, 0);
-               g_ptr_array_remove_index(dir_array, 0);
-
+       while ((current_path = g_queue_pop_head(dir_queue))) {
                if (__msc_is_power_off()) {
                        ret = MS_MEDIA_ERR_SCANNER_FORCE_STOP;
                        MS_SAFE_FREE(current_path);
@@ -122,7 +119,7 @@ static int __msc_dir_scan(sqlite3 *handle, const char *storage_id, char *start_p
                                MS_SAFE_FREE(path);
                        } else {
                                if (is_recursive) {
-                                       g_ptr_array_add(dir_array, path);
+                                       g_queue_push_tail(dir_queue, path);
                                } else {
                                        ret = ms_insert_folder(handle, storage_id, path, uid);
                                        if (ret != MS_MEDIA_ERR_NONE)
@@ -138,7 +135,7 @@ static int __msc_dir_scan(sqlite3 *handle, const char *storage_id, char *start_p
                        g_dir_close(dir);
        }
 
-       g_ptr_array_free(dir_array, TRUE);
+       g_queue_free_full(dir_queue, g_free);
 
        return ret;
 }