Change to use the value of scan_data directly 10/240910/3
authorMinje Ahn <minje.ahn@samsung.com>
Wed, 12 Aug 2020 23:07:06 +0000 (08:07 +0900)
committerMinje Ahn <minje.ahn@samsung.com>
Wed, 12 Aug 2020 23:18:31 +0000 (08:18 +0900)
Change-Id: I2108eedff4d13dbe2645a2c4828a39bf9b54395d
Signed-off-by: Minje Ahn <minje.ahn@samsung.com>
src/scanner-v2/media-scanner-scan-v2.c

index 3fcb3b9..c524dc8 100644 (file)
@@ -788,14 +788,11 @@ gpointer msc_directory_scan_thread(gpointer data)
        int err;
        int ret = MS_MEDIA_ERR_NONE;
        sqlite3 *handle = NULL;
-       int scan_type;
-       char *storage_id = NULL;
        bool modified = false;
        ms_dir_scan_status_e scan_status = MS_DIR_SCAN_NONE;
        ms_noti_type_e noti_type = MS_ITEM_INSERT;
        char *folder_uuid = NULL;
        bool is_recursive = true;
-       uid_t uid = MEDIA_DEFAULT_UID;
 
        while (1) {
                scan_data = g_async_queue_pop(scan_queue2);
@@ -828,7 +825,7 @@ gpointer msc_directory_scan_thread(gpointer data)
                }
 
                /*check remain space*/
-               if (__msc_check_remain_space(uid) != MS_MEDIA_ERR_NONE)
+               if (__msc_check_remain_space(scan_data->uid) != MS_MEDIA_ERR_NONE)
                        goto SCAN_DONE;
 
                g_mutex_lock(&scan_item_mutex);
@@ -836,16 +833,12 @@ gpointer msc_directory_scan_thread(gpointer data)
                g_mutex_unlock(&scan_item_mutex);
 
                g_directory_scan_processing2 = DIR_SCAN_NON_RECURSIVE;
-               uid = scan_data->uid;
-
-               scan_type = scan_data->msg_type;
-               storage_id = g_strdup(scan_data->storage_id);
 
                ms_trim_dir_path(scan_data->msg);
 
                if (g_file_test(scan_data->msg, G_FILE_TEST_IS_DIR)) {
-                       is_recursive = (scan_type == MS_MSG_DIRECTORY_SCANNING_NON_RECURSIVE) ? false : true;
-                       if (ms_check_folder_exist(handle, storage_id, scan_data->msg) == MS_MEDIA_ERR_NONE) {
+                       is_recursive = (scan_data->msg_type == MS_MSG_DIRECTORY_SCANNING_NON_RECURSIVE) ? false : true;
+                       if (ms_check_folder_exist(handle, scan_data->storage_id, scan_data->msg) == MS_MEDIA_ERR_NONE) {
                                /*already exist in media DB*/
                                noti_type = MS_ITEM_UPDATE;
                                MS_DBG_WARN("[%.*s] already exist", MAX_MSG_SIZE, scan_data->msg);
@@ -857,16 +850,15 @@ gpointer msc_directory_scan_thread(gpointer data)
                        /*directory is deleted*/
                        is_recursive = true;
                        noti_type = MS_ITEM_DELETE;
-                       scan_type = MS_MSG_DIRECTORY_SCANNING;
                        scan_data->msg_type = MS_MSG_DIRECTORY_SCANNING;
 
                        /*get the UUID of deleted folder*/
-                       ms_get_folder_id(handle, storage_id, scan_data->msg, &folder_uuid);
+                       ms_get_folder_id(handle, scan_data->storage_id, scan_data->msg, &folder_uuid);
 
                        MS_DBG_SWARN("[%.*s][%s] delete path", MAX_MSG_SIZE, scan_data->msg, folder_uuid);
                }
 
-               if (scan_type == MS_MSG_DIRECTORY_SCANNING) {
+               if (scan_data->msg_type == MS_MSG_DIRECTORY_SCANNING) {
 
                        MS_DBG_WARN("start recursive dir scan!!");
 
@@ -879,7 +871,7 @@ gpointer msc_directory_scan_thread(gpointer data)
                                while (1) {
                                        sleep(1);
 
-                                       ret = __msc_check_stop_status(scan_type, scan_data->msg, scan_data->pid);
+                                       ret = __msc_check_stop_status(scan_data->msg_type, scan_data->msg, scan_data->pid);
                                        if (ret != MS_MEDIA_ERR_NONE)
                                                goto NEXT;
 
@@ -893,12 +885,12 @@ gpointer msc_directory_scan_thread(gpointer data)
                                goto SCAN_DONE;
 
                        } else {
-                               ms_get_folder_scan_status(handle, storage_id, scan_data->msg, (int*)&scan_status);
+                               ms_get_folder_scan_status(handle, scan_data->storage_id, scan_data->msg, (int*)&scan_status);
 
                                if (scan_status == MS_DIR_SCAN_DONE)
-                                       ms_set_folder_item_validity(handle, storage_id, scan_data->msg, MS_VALID_V2, MS_RECURSIVE, uid);
+                                       ms_set_folder_item_validity(handle, scan_data->storage_id, scan_data->msg, MS_VALID_V2, MS_RECURSIVE, scan_data->uid);
                                else
-                                       ms_set_folder_item_validity(handle, storage_id, scan_data->msg, MS_INVALID, MS_RECURSIVE, uid);
+                                       ms_set_folder_item_validity(handle, scan_data->storage_id, scan_data->msg, MS_INVALID, MS_RECURSIVE, scan_data->uid);
 
                                msc_send_result_partial(ret, MS_MSG_RECURSIVE_START, scan_data->pid, scan_data->msg);
                        }
@@ -906,18 +898,15 @@ gpointer msc_directory_scan_thread(gpointer data)
                        MS_DBG_WARN("start non recursive dir scan!!");
 
                        g_directory_scan_processing2 = DIR_SCAN_NON_RECURSIVE;
-                       ms_check_folder_modified(handle, scan_data->msg, storage_id, &modified);
+                       ms_check_folder_modified(handle, scan_data->msg, scan_data->storage_id, &modified);
 
                        if (!modified) {
                                MS_DBG_WARN("check [%.*s] has not been modified !!", MAX_MSG_SIZE, scan_data->msg);
-                               ms_get_folder_scan_status(handle, storage_id, scan_data->msg, (int*)&scan_status);
+                               ms_get_folder_scan_status(handle, scan_data->storage_id, scan_data->msg, (int*)&scan_status);
                                MS_DBG_WARN("folder scan status = [%d]", scan_status);
 
                                if (scan_status == MS_DIR_SCAN_DONE) {
-                                       /* do nothing */
                                        MS_DBG_WARN("[%.*s] scan done", MAX_MSG_SIZE, scan_data->msg);
-                                       /*fix timing issue, deleted items scanned by storage scan is set validity 1 again*/
-                                       /*err = ms_set_folder_item_validity(handle, storage_id, scan_data->msg, MS_VALID, MS_NON_RECURSIVE, uid);*/
                                        goto SCAN_DONE;
                                } else if (scan_status == MS_DIR_SCAN_PROCESSING) {
                                        MS_DBG_WARN("[%.*s] scanning, waiting...", MAX_MSG_SIZE, scan_data->msg);
@@ -925,12 +914,12 @@ gpointer msc_directory_scan_thread(gpointer data)
                                        while (1) {
                                                sleep(1);
 
-                                               ret = __msc_check_stop_status(scan_type, scan_data->msg, scan_data->pid);
+                                               ret = __msc_check_stop_status(scan_data->msg_type, scan_data->msg, scan_data->pid);
                                                if (ret != MS_MEDIA_ERR_NONE)
                                                        goto NEXT;
 
 
-                                               ms_get_folder_scan_status(handle, storage_id, scan_data->msg, (int*)&scan_status);
+                                               ms_get_folder_scan_status(handle, scan_data->storage_id, scan_data->msg, (int*)&scan_status);
                                                if ((scan_status == MS_DIR_SCAN_DONE) || (scan_status == MS_DIR_SCAN_STOP)) {
                                                        MS_DBG_WARN("[%.*s] scan status [%d]!!!", MAX_MSG_SIZE, scan_data->msg, scan_status);
                                                        break;
@@ -942,14 +931,14 @@ gpointer msc_directory_scan_thread(gpointer data)
                                                goto SCAN_DONE;
                                        } else {
                                                MS_DBG_WARN("set folder item invalid");
-                                               err = ms_set_folder_item_validity(handle, storage_id, scan_data->msg, MS_INVALID, MS_NON_RECURSIVE, uid);
+                                               err = ms_set_folder_item_validity(handle, scan_data->storage_id, scan_data->msg, MS_INVALID, MS_NON_RECURSIVE, scan_data->uid);
                                        }
                                } else {
-                                       err = ms_set_folder_item_validity(handle, storage_id, scan_data->msg, MS_INVALID, MS_NON_RECURSIVE, uid);
+                                       err = ms_set_folder_item_validity(handle, scan_data->storage_id, scan_data->msg, MS_INVALID, MS_NON_RECURSIVE, scan_data->uid);
                                }
                        } else {
                                MS_DBG_WARN("check [%.*s] has been modified !!", MAX_MSG_SIZE, scan_data->msg);
-                               err = ms_set_folder_item_validity(handle, storage_id, scan_data->msg, MS_INVALID, MS_NON_RECURSIVE, uid);
+                               err = ms_set_folder_item_validity(handle, scan_data->storage_id, scan_data->msg, MS_INVALID, MS_NON_RECURSIVE, scan_data->uid);
                        }
                }
 
@@ -960,32 +949,30 @@ gpointer msc_directory_scan_thread(gpointer data)
                ms_batch_commit_enable(false, 0);
 
                /*insert data into media db */
-               ret = __msc_db_update(handle, storage_id, scan_data);
+               ret = __msc_db_update(handle, scan_data->storage_id, scan_data);
 
                /*call for bundle commit*/
-               ms_batch_commit_disable(uid);
+               ms_batch_commit_disable(scan_data->uid);
 
                MS_DBG_WARN("folder scan done, sent cb event path = [%.*s]", MAX_MSG_SIZE, scan_data->msg);
 
                __msc_resume_scan();
 
-               /*revert to 3.0,folder scan should only delete invalid in folder instead of delete invalid in storage*/
-               if (ms_delete_invalid_items_in_folder(handle, storage_id, scan_data->msg, is_recursive, uid) != MS_MEDIA_ERR_NONE)
+               if (ms_delete_invalid_items_in_folder(handle, scan_data->storage_id, scan_data->msg, is_recursive, scan_data->uid) != MS_MEDIA_ERR_NONE)
                        MS_DBG_ERR("deleting invalid items in folder failed");
 
 SCAN_DONE:
-               MS_DBG_WARN("storage_id = [%s], dir Path = [%.*s], pid = [%d]", storage_id, MAX_MSG_SIZE, scan_data->msg, scan_data->pid);
+               MS_DBG_WARN("storage_id = [%s], dir Path = [%.*s], pid = [%d]", scan_data->storage_id, MAX_MSG_SIZE, scan_data->msg, scan_data->pid);
                if (ret != MS_MEDIA_ERR_SCANNER_FORCE_STOP) {
-                       /*remove invalid folder in folder table.*/
                        if (is_recursive == true) {
-                               if (ms_delete_invalid_folder_by_path(handle, storage_id, scan_data->msg, uid) != MS_MEDIA_ERR_NONE) {
+                               if (ms_delete_invalid_folder_by_path(handle, scan_data->storage_id, scan_data->msg, scan_data->uid) != MS_MEDIA_ERR_NONE) {
                                        MS_DBG_ERR("deleting invalid folder failed");
                                }
                        }
                        if (noti_type == MS_ITEM_DELETE) {
                                ms_send_dir_update_noti(scan_data->msg, folder_uuid, noti_type, scan_data->pid);
                        }
-                       msc_insert_exactor_request(scan_data->msg_type, true, scan_data->storage_id, scan_data->msg, scan_data->pid, uid, noti_type);
+                       msc_insert_exactor_request(scan_data->msg_type, true, scan_data->storage_id, scan_data->msg, scan_data->pid, scan_data->uid, noti_type);
                }
 
                if (_msc_is_power_off())
@@ -1000,8 +987,6 @@ NEXT:
 
                g_free(scan_data);
                scan_data = NULL;
-               g_free(storage_id);
-               storage_id = NULL;
                g_free(folder_uuid);
                folder_uuid = NULL;
 
@@ -1045,8 +1030,6 @@ gpointer msc_storage_scan_thread(gpointer data)
        int ret = MS_MEDIA_ERR_NONE;
        sqlite3 *handle = NULL;
        ms_user_storage_type_e storage_type = MS_USER_STORAGE_INTERNAL;
-       int scan_type;
-       uid_t uid = MEDIA_DEFAULT_UID;
 
        while (1) {
                scan_data = g_async_queue_pop(storage_queue2);
@@ -1057,71 +1040,68 @@ gpointer msc_storage_scan_thread(gpointer data)
 
                MS_DBG_WARN("STORAGE SCAN START [%.*s]", MAX_MSG_SIZE, scan_data->msg);
 
-               scan_type = scan_data->msg_type;
-               if (scan_type != MS_MSG_STORAGE_ALL
-                       && scan_type != MS_MSG_STORAGE_PARTIAL
-                       && scan_type != MS_MSG_STORAGE_INVALID) {
-                       MS_DBG_ERR("Invalid request[%d]", scan_type);
+               if (scan_data->msg_type != MS_MSG_STORAGE_ALL &&
+                       scan_data->msg_type != MS_MSG_STORAGE_PARTIAL &&
+                       scan_data->msg_type != MS_MSG_STORAGE_INVALID) {
+                       MS_DBG_ERR("Invalid request[%d]", scan_data->msg_type);
                        ret = MS_MEDIA_ERR_INVALID_PARAMETER;
                        goto NEXT;
                }
 
                __msc_check_pvr_svc();
 
-               uid = scan_data->uid;
-
-               ret = ms_connect_db(&handle, uid);
+               ret = ms_connect_db(&handle, scan_data->uid);
                if (ret != MS_MEDIA_ERR_NONE) {
                        MS_DBG_ERR("ms_connect_db failed");
                        goto NEXT;
                }
 
-               ret = ms_user_get_storage_type(uid, scan_data->msg, &storage_type);
+               ret = ms_user_get_storage_type(scan_data->uid, scan_data->msg, &storage_type);
                if (ret != MS_MEDIA_ERR_NONE) {
                        MS_DBG_ERR("ms_user_get_storage_type failed");
                        goto NEXT;
                }
 
-               ret = __msc_check_memory_status(uid);
+               ret = __msc_check_memory_status(scan_data->uid);
                if (ret != MS_MEDIA_ERR_NONE) {
-                       ms_set_storage_scan_status(handle, scan_data->storage_id, MEDIA_SCAN_STOP, uid);
+                       ms_set_storage_scan_status(handle, scan_data->storage_id, MEDIA_SCAN_STOP, scan_data->uid);
                        MS_DBG_ERR("storage_id = [%s]", scan_data->storage_id);
-                       msc_insert_exactor_request(scan_type, true, scan_data->storage_id, scan_data->msg, scan_data->pid, uid, MS_ITEM_UPDATE);
+                       msc_insert_exactor_request(scan_data->msg_type, true, scan_data->storage_id, scan_data->msg, scan_data->pid, scan_data->uid, MS_ITEM_UPDATE);
                        goto NEXT;
                }
 
-               ms_set_storage_scan_status(handle, scan_data->storage_id, MEDIA_SCAN_PROCESSING, uid);
+               ms_set_storage_scan_status(handle, scan_data->storage_id, MEDIA_SCAN_PROCESSING, scan_data->uid);
 
                ms_set_db_status(MS_DB_UPDATING, storage_type);
 
-               if (scan_type != MS_MSG_STORAGE_INVALID)
+               if (scan_data->msg_type != MS_MSG_STORAGE_INVALID)
                        ms_batch_commit_enable(false, 0);
 
-               if (scan_type == MS_MSG_STORAGE_ALL) {
-                       if (ms_delete_invalid_items(handle, scan_data->storage_id, uid) != MS_MEDIA_ERR_NONE)
+               if (scan_data->msg_type == MS_MSG_STORAGE_ALL) {
+                       if (ms_delete_invalid_items(handle, scan_data->storage_id, scan_data->uid) != MS_MEDIA_ERR_NONE)
                                MS_DBG_ERR("ms_delete_invalid_items fails");
                }
 
                ret = __msc_db_update(handle, scan_data->storage_id, scan_data);
 
-               if (scan_type != MS_MSG_STORAGE_INVALID)
-                       ms_batch_commit_disable(uid);
+               if (scan_data->msg_type != MS_MSG_STORAGE_INVALID)
+                       ms_batch_commit_disable(scan_data->uid);
 
-               if (scan_type == MS_MSG_STORAGE_PARTIAL && ret == MS_MEDIA_ERR_NONE) {
-                       ms_delete_invalid_folder(scan_data->storage_id, uid);
-                       ms_delete_invalid_items(handle, scan_data->storage_id, uid);
+               if (scan_data->msg_type == MS_MSG_STORAGE_PARTIAL && ret == MS_MEDIA_ERR_NONE) {
+                       ms_delete_invalid_folder(scan_data->storage_id, scan_data->uid);
+                       ms_delete_invalid_items(handle, scan_data->storage_id, scan_data->uid);
                }
 
                if (ret == MS_MEDIA_ERR_SCANNER_FORCE_STOP) {
-                       ms_set_storage_scan_status(handle, scan_data->storage_id, MEDIA_SCAN_STOP, uid);
+                       ms_set_storage_scan_status(handle, scan_data->storage_id, MEDIA_SCAN_STOP, scan_data->uid);
                        ms_set_db_status(MS_DB_STOPPED, storage_type);
                } else {
-                       ms_set_storage_scan_status(handle, scan_data->storage_id, MEDIA_SCAN_COMPLETE, uid);
+                       ms_set_storage_scan_status(handle, scan_data->storage_id, MEDIA_SCAN_COMPLETE, scan_data->uid);
                        ms_set_db_status(MS_DB_UPDATED, storage_type);
                }
 
                MS_DBG_WARN("storage_id = [%s]", scan_data->storage_id);
-               msc_insert_exactor_request(scan_type, true, scan_data->storage_id, scan_data->msg, scan_data->pid, uid, MS_ITEM_UPDATE);
+               msc_insert_exactor_request(scan_data->msg_type, true, scan_data->storage_id, scan_data->msg, scan_data->pid, scan_data->uid, MS_ITEM_UPDATE);
 
 NEXT:
                __msc_del_blocked_path();