Improve msc_directory_scan_thread() 50/239950/9
authorhj kim <backto.kim@samsung.com>
Fri, 31 Jul 2020 02:18:38 +0000 (11:18 +0900)
committerhj kim <backto.kim@samsung.com>
Thu, 6 Aug 2020 05:57:12 +0000 (05:57 +0000)
just rearrange codes to manage error cases first

Change-Id: Iadb63c23a2668cac0596aa8da99e55da750720e0

src/scanner-v2/media-scanner-scan-v2.c
src/scanner/media-scanner-scan.c

index d2ca940..74dbdb2 100644 (file)
@@ -986,15 +986,20 @@ gpointer msc_directory_scan_thread(gpointer data)
 
                MS_DBG_WARN("DIRECTORY SCAN START [%.*s][%s][%d]", MAX_MSG_SIZE, scan_data->msg, scan_data->storage_id, scan_data->msg_type);
 
-               g_mutex_lock(&scan_item_mutex);
-               __msc_set_scan_item(&cur_scan_item, scan_data->msg, scan_data->pid);
-               g_mutex_unlock(&scan_item_mutex);
+               if (strlen(scan_data->storage_id) == 0) {
+                       MS_DBG_ERR("storage_id length is 0");
+                       ret = MS_MEDIA_ERR_INVALID_PARAMETER;
+                       goto NEXT;
+               }
 
-               g_directory_scan_processing2 = DIR_SCAN_NON_RECURSIVE;
-               uid = scan_data->uid;
+               if (scan_data->msg_type != MS_MSG_DIRECTORY_SCANNING &&
+                       scan_data->msg_type != MS_MSG_DIRECTORY_SCANNING_NON_RECURSIVE) {
+                       MS_DBG_ERR("Invalid request");
+                       ret = MS_MEDIA_ERR_INVALID_PARAMETER;
+                       goto NEXT;
+               }
 
-               /*connect to media db, if connecting is failed, db updating is stopped*/
-               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;
@@ -1004,23 +1009,15 @@ gpointer msc_directory_scan_thread(gpointer data)
                if (__msc_check_remain_space(uid) != MS_MEDIA_ERR_NONE)
                        goto SCAN_DONE;
 
-               scan_type = scan_data->msg_type;
-               storage_id = g_strdup(scan_data->storage_id);
-
-               MS_DBG("path [%.*s], storage_id [%s], scan_type [%d]", MAX_MSG_SIZE, scan_data->msg, storage_id, scan_type);
+               g_mutex_lock(&scan_item_mutex);
+               __msc_set_scan_item(&cur_scan_item, scan_data->msg, scan_data->pid);
+               g_mutex_unlock(&scan_item_mutex);
 
-               if (strlen(storage_id) == 0) {
-                       MS_DBG_ERR("storage_id length is 0. There is no information of your request [%.*s]", MAX_MSG_SIZE, scan_data->msg);
-                       ret = MS_MEDIA_ERR_INVALID_PARAMETER;
-                       goto NEXT;
-               }
+               g_directory_scan_processing2 = DIR_SCAN_NON_RECURSIVE;
+               uid = scan_data->uid;
 
-               if (scan_type != MS_MSG_DIRECTORY_SCANNING
-                       && scan_type != MS_MSG_DIRECTORY_SCANNING_NON_RECURSIVE) {
-                       MS_DBG_ERR("Invalid request");
-                       ret = MS_MEDIA_ERR_INVALID_PARAMETER;
-                       goto NEXT;
-               }
+               scan_type = scan_data->msg_type;
+               storage_id = g_strdup(scan_data->storage_id);
 
                ms_trim_dir_path(scan_data->msg);
 
index a455736..9e8dcf7 100644 (file)
@@ -271,7 +271,8 @@ gpointer msc_directory_scan_thread(gpointer data)
                        goto NEXT;
                }
 
-               if (scan_data->msg_type != MS_MSG_DIRECTORY_SCANNING && scan_data->msg_type != MS_MSG_DIRECTORY_SCANNING_NON_RECURSIVE) {
+               if (scan_data->msg_type != MS_MSG_DIRECTORY_SCANNING &&
+                       scan_data->msg_type != MS_MSG_DIRECTORY_SCANNING_NON_RECURSIVE) {
                        MS_DBG_ERR("Invalid request");
                        ret = MS_MEDIA_ERR_INVALID_PARAMETER;
                        goto NEXT;