Remove __msc_clear_file_list 88/213488/5
authorMinje Ahn <minje.ahn@samsung.com>
Thu, 5 Sep 2019 23:29:40 +0000 (08:29 +0900)
committerMinje Ahn <minje.ahn@samsung.com>
Fri, 6 Sep 2019 06:37:15 +0000 (15:37 +0900)
Change-Id: I96067196dddbcea596c67d0cced80fe4eb72f76c
Signed-off-by: Minje Ahn <minje.ahn@samsung.com>
src/scanner/media-scanner-scan.c

index d6930b0..07305d2 100755 (executable)
@@ -36,8 +36,6 @@ GAsyncQueue *scan_queue;
 GAsyncQueue *reg_queue;
 GMutex scan_req_mutex;
 
-static void __msc_clear_file_list(GPtrArray *path_array);
-
 static bool __msc_is_stop_needed()
 {
        if (power_off) {
@@ -70,14 +68,15 @@ static int __msc_dir_scan(sqlite3 *handle, const char *storage_id, char *start_p
        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);
+
                if (__msc_is_stop_needed()) {
                        ret = MS_MEDIA_ERR_SCANNER_FORCE_STOP;
-                       goto STOP_SCAN;
+                       MS_SAFE_FREE(current_path);
+                       continue;
                }
 
-               current_path = g_ptr_array_index(dir_array, 0);
-               g_ptr_array_remove_index(dir_array, 0);
-
                if (ms_check_scan_ignore(current_path, uid) != MS_MEDIA_ERR_NONE) {
                        MS_DBG_ERR("%s is ignore", current_path);
                        MS_SAFE_FREE(current_path);
@@ -99,7 +98,7 @@ static int __msc_dir_scan(sqlite3 *handle, const char *storage_id, char *start_p
                while ((name = g_dir_read_name(dir))) {
                        if (__msc_is_stop_needed()) {
                                ret = MS_MEDIA_ERR_SCANNER_FORCE_STOP;
-                               goto STOP_SCAN;
+                               break;
                        }
 
                        if (name[0] == '.')
@@ -138,21 +137,11 @@ static int __msc_dir_scan(sqlite3 *handle, const char *storage_id, char *start_p
 
                MS_SAFE_FREE(current_path);
 
-               if (dir) {
+               if (dir)
                        g_dir_close(dir);
-                       dir = NULL;
-               }
        }
 
-STOP_SCAN:
-       if (dir) {
-               g_dir_close(dir);
-               dir = NULL;
-       }
-
-       MS_SAFE_FREE(current_path);
-
-       __msc_clear_file_list(dir_array);
+       g_ptr_array_free(dir_array, TRUE);
 
        return ret;
 }
@@ -448,37 +437,26 @@ _POWEROFF:
        return FALSE;
 }
 
-static void __msc_clear_file_list(GPtrArray *path_array)
-{
-       if (!path_array)
-               return;
-
-       g_ptr_array_free(path_array, TRUE);
-}
-
 static int __msc_make_file_list(char *file_path, GPtrArray **path_array, uid_t uid)
 {
        FILE *fp = NULL;
        char buf[MS_FILE_PATH_LEN_MAX] = {0,};
        char *path = NULL;
        int length;
+       GPtrArray *_path_array = NULL;
        int ret = MS_MEDIA_ERR_NONE;
 
        /* load the file list from file */
        fp = fopen(file_path, "rt");
-       if (fp == NULL) {
-               MS_DBG_STRERROR("fopen failed");
-               ret = MS_MEDIA_ERR_FILE_OPEN_FAIL;
-               goto FREE_RESOURCE;
-       }
+       MS_DBG_RETVM_IF(!fp, MS_MEDIA_ERR_FILE_OPEN_FAIL, "fopen failed");
 
        memset(buf, 0x0, MS_FILE_PATH_LEN_MAX);
        /* This is an array for storing the path of insert datas*/
-       *path_array = g_ptr_array_new_with_free_func(g_free);
-       if (*path_array == NULL) {
+       _path_array = g_ptr_array_new_with_free_func(g_free);
+       if (!_path_array) {
                MS_DBG_ERR("g_array_new failed");
-               ret = MS_MEDIA_ERR_OUT_OF_MEMORY;
-               goto FREE_RESOURCE;
+               fclose(fp);
+               return MS_MEDIA_ERR_OUT_OF_MEMORY;
        }
 
        /* read registering file path from stored file */
@@ -494,22 +472,15 @@ static int __msc_make_file_list(char *file_path, GPtrArray **path_array, uid_t u
                        continue;
                }
                /* insert getted path to the list */
-               g_ptr_array_add(*path_array, path);
+               g_ptr_array_add(_path_array, path);
 
        }
 
        if (fp) fclose(fp);
-       fp = NULL;
 
-       return MS_MEDIA_ERR_NONE;
-
-FREE_RESOURCE:
-       __msc_clear_file_list(*path_array);
-
-       if (fp) fclose(fp);
-       fp = NULL;
+       *path_array = _path_array;
 
-       return ret;
+       return MS_MEDIA_ERR_NONE;
 }
 
 static int __msc_batch_insert(int pid, GPtrArray *path_array, uid_t uid)
@@ -576,7 +547,7 @@ gboolean msc_register_thread(void *data)
 
                MS_DBG_SLOG("BULK REGISTER START [%.*s]", MAX_MSG_SIZE, register_data->msg);
                ret = __msc_batch_insert(register_data->pid, path_array, register_data->uid);
-               __msc_clear_file_list(path_array);
+               g_ptr_array_free(path_array, TRUE);
 
 NEXT:
                /*Active flush */