send partial message to all request pid, need to check path 18/173318/2 accepted/tizen/unified/20180322.060156 submit/tizen/20180321.071237
authorchen89.chen <chen89.chen@samsung.com>
Tue, 20 Mar 2018 08:07:10 +0000 (16:07 +0800)
committerchen89.chen <chen89.chen@samsung.com>
Tue, 20 Mar 2018 12:57:50 +0000 (20:57 +0800)
request continuously with same pid and request path, cancel request force stop will be sent

commit to db before set scan done, fix timing issue

previously extract blocked path was not deleted, remove extract queue and delete extract block path when usb umount

Change-Id: Icd42b6268919f4195c55bc9dc5a6152cc2a2548f

src/scanner-v2/media-scanner-extract-v2.c
src/scanner-v2/media-scanner-scan-v2.c
src/scanner-v2/media-scanner-socket-v2.c
src/server/media-server-socket.c

index 69e13dd..617ca2d 100755 (executable)
@@ -373,6 +373,7 @@ gboolean msc_storage_extract_thread(void *data)
                if (scan_type != MS_MSG_STORAGE_ALL
                        && scan_type != MS_MSG_STORAGE_PARTIAL) {
                        MS_DBG_ERR("Invalid request[%d]", scan_type);
+                       msc_remove_extract_request(extract_data);
                        ret = MS_MEDIA_ERR_INVALID_PARAMETER;
                        goto NEXT;
                }
@@ -431,12 +432,12 @@ gboolean msc_storage_extract_thread(void *data)
                        /* set vconf key db extract status */
                        __msc_extract_set_db_status(MS_DB_STOPPED);
 
-                       msc_del_extract_blocked_path(update_path);
                        msc_remove_extract_request(extract_data);
                        goto STOP_DISC;
                }
                if (extract_data->result == TRUE) {
                        MS_DBG_WARN("extract_data->result == TRUE, MS_STORAGE_SCAN_COMPLETE");
+                       msc_del_extract_blocked_path(update_path);
                        ms_set_storage_scan_status(handle, extract_data->storage_id, MEDIA_EXTRACT_COMPLETE, uid);
                        __msc_set_storage_extract_status(MS_STORAGE_SCAN_COMPLETE);
 
@@ -573,6 +574,7 @@ int msc_remove_extract_request(const ms_comm_msg_s *recv_msg)
 END_REMOVE_REQUEST:
        g_mutex_unlock(&extract_req_mutex);
        MS_DBG_WARN("exactor_req_mutex is UNLOCKED");
+       msc_del_extract_blocked_path(recv_msg->msg);
 
        return MS_MEDIA_ERR_NONE;
 }
@@ -673,7 +675,7 @@ int msc_set_extract_blocked_path(const char *blocked_path)
        }
 
        g_extract_blocked_path = strdup(blocked_path);
-
+       MS_DBG_ERR("g_extract_blocked_path is set [%s]", g_extract_blocked_path);
        g_mutex_unlock(&extract_blocked_mutex);
 
        MS_DBG_FLEAVE();
@@ -687,13 +689,13 @@ int msc_del_extract_blocked_path(const char* blocked_path)
 
        g_mutex_lock(&extract_blocked_mutex);
        if (blocked_path) {
-               if (g_extract_blocked_path && (0 == strncmp(blocked_path, g_extract_blocked_path, strlen(blocked_path)))) {
-                       MS_DBG_ERR("g_extract_blocked_path is not NULL [%s]", g_extract_blocked_path);
+               if (g_extract_blocked_path && (0 == strncmp(blocked_path, g_extract_blocked_path, strlen(g_extract_blocked_path)))) {
+                       MS_DBG_ERR("g_extract_blocked_path is deleted  [%s]", g_extract_blocked_path);
                        MS_SAFE_FREE(g_extract_blocked_path);
                }
        } else {
                if (g_extract_blocked_path != NULL) {
-                       MS_DBG_ERR("g_extract_blocked_path is not NULL [%s]", g_extract_blocked_path);
+                       MS_DBG_ERR("g_extract_blocked_path is deleted [%s]", g_extract_blocked_path);
                        MS_SAFE_FREE(g_extract_blocked_path);
                }
        }
index 1611a7b..adcd88c 100755 (executable)
@@ -623,6 +623,7 @@ static int __msc_dir_scan_for_storage(void **handle, const char *storage_id, con
 
        scan_function = (scan_type == MS_MSG_STORAGE_ALL) ? ms_scan_item_batch : ms_scan_validate_item;
 
+       ms_bacth_commit_disable(handle, TRUE, TRUE, uid);
        /*start db update. the number of element in the array , db update is complete.*/
        while (dir_array->len != 0) {
                /*check poweroff status*/
@@ -630,7 +631,7 @@ static int __msc_dir_scan_for_storage(void **handle, const char *storage_id, con
                if (ret != MS_MEDIA_ERR_NONE)
                        goto STOP_SCAN;
 
-               ms_bacth_commit_disable(handle, TRUE, TRUE, uid);
+               /*ms_bacth_commit_disable(handle, TRUE, TRUE, uid);*/
                ms_bacth_commit_enable(handle, TRUE, TRUE, MS_NOTI_SWITCH_OFF, pid);
 
                /* get the current path from directory array */
@@ -808,6 +809,8 @@ static int __msc_dir_scan_for_storage(void **handle, const char *storage_id, con
                }
 
                ms_insert_folder_end(handle, uid);
+               /*commit to db before set scan done, fix timing issue storage scan, then folder scan for same folder*/
+               ms_bacth_commit_disable(handle, TRUE, TRUE, uid);
                ms_set_folder_scan_status(handle, storage_id, current_path, MS_DIR_SCAN_DONE, uid);
 
                if (fd != -1) {
@@ -1817,7 +1820,8 @@ int msc_set_cancel_scan_item(const char* cancel_path, int pid)
                MS_DBG_WARN("cancel_path[%s], pid[%d]", cancel_path, pid);
                if ((strcmp(cur_scan_item->path, cancel_path) == 0) && (pid == cur_scan_item->pid))
                        ret = _msc_set_scan_item(&cancel_scan_item, cancel_path, pid);
-
+               else if ((pid == -1) && (strncmp(cur_scan_item->path, cancel_path, strlen(cancel_path)) == 0))
+                       ret = _msc_set_scan_item(&cancel_scan_item, cancel_path, pid);
        } else {
                MS_DBG_ERR("cur_scan_item == NULL || cur_scan_item->path == NULL");
        }
index 0f1fd36..6df8184 100755 (executable)
@@ -257,6 +257,11 @@ int msc_send_result(int result, ms_comm_msg_s *res_data)
 {
        MS_DBG_SLOG("msc_send_result msg_type=%d", res_data->msg_type);
        int res = MS_MEDIA_ERR_NONE;
+
+       if (result == MS_MEDIA_ERR_SCANNER_FORCE_STOP) {
+               MS_DBG_WARN("msc_send_result -701 will not be sent");
+               return res;
+       }
        ms_comm_msg_s send_msg;
        int fd = -1;
        int err = -1;
@@ -297,6 +302,12 @@ int msc_send_result_partial(int result, ms_msg_type_e msg_type, int pid, const c
 #ifdef SUPPORT_PARTIAL_EVENT
        MS_DBG_SLOG("msc_send_result_partial %d,%d,%s", msg_type, pid, msg);
        int res = MS_MEDIA_ERR_NONE;
+
+       /*in case of request continuously with same pid and request path, cancel request force stop will be sent*/
+       if (result == MS_MEDIA_ERR_SCANNER_FORCE_STOP) {
+               MS_DBG_WARN("msc_send_result_partial -701 will not be sent");
+               return res;
+       }
        ms_comm_msg_s send_msg;
        int fd = -1;
        int err = -1;
index 9b93929..843dce7 100755 (executable)
@@ -199,8 +199,11 @@ static int __ms_send_result_to_client(int pid, ms_comm_msg_s *recv_msg)
                        MS_DBG_ERR("length list : %d", len);
                        for (int i = 0; i < len; i++) {
                                data = g_array_index(owner_list, ms_req_owner_data*, i);
-                               MS_DBG_ERR("PARTIAL message:pid %d,path %s", data->pid, data->req_path);
-                               ms_ipc_send_msg_to_client_tcp(data->client_sockfd, recv_msg, NULL);
+                               /*send partial message to all request pid, need to check path*/
+                               if (strcmp(data->req_path, res_path) == 0) {
+                                       MS_DBG_ERR("PARTIAL message:pid %d,path %s", data->pid, data->req_path);
+                                       ms_ipc_send_msg_to_client_tcp(data->client_sockfd, recv_msg, NULL);
+                               }
                        }
                        MS_SAFE_FREE(res_path);
                } else {