Prevent unexpected result when cancel folder scan 87/152887/5 accepted/tizen/unified/20171010.063846 submit/tizen/20171010.021728
authorHaejeong Kim <backto.kim@samsung.com>
Wed, 27 Sep 2017 09:47:18 +0000 (18:47 +0900)
committerHaejeong Kim <backto.kim@samsung.com>
Thu, 28 Sep 2017 23:42:55 +0000 (08:42 +0900)
Change-Id: I45e9c0bfd04b697f2b9fc19c52a5b603490648c8

lib/include/media-util-register.h
lib/media-util-register.c

index 35cb3c8..cbaf921 100755 (executable)
@@ -42,7 +42,7 @@ typedef struct {
        int pid;
        int result;
        int request_type;
-       char *complete_path; /* if the request type is MEDIA_FILES_REGISTER, this value will be NULL. */
+       char *complete_path;
 } media_request_result_s;
 
 typedef void (*scan_complete_cb)(media_request_result_s *, void *);
index 91500e2..2f93eff 100755 (executable)
@@ -97,6 +97,7 @@ gboolean _read_socket(GIOChannel *src, GIOCondition condition, gpointer data)
 
        req_result.pid = recv_msg.pid;
        req_result.result = recv_msg.result;
+
        if (recv_msg.msg_type == MS_MSG_SCANNER_RESULT) {
                req_result.complete_path = strndup(recv_msg.msg, recv_msg.msg_size);
                req_result.request_type = MEDIA_DIRECTORY_SCAN;
@@ -131,9 +132,6 @@ gboolean _read_socket(GIOChannel *src, GIOCondition condition, gpointer data)
        user_data = ((media_callback_data *)data)->user_data;
        sock_path = ((media_callback_data *)data)->sock_path;
 
-       /*call user define function*/
-       user_callback(&req_result, user_data);
-
        if ((recv_msg.msg_type != MS_MSG_SCANNER_COMPLETE) &&
        (recv_msg.msg_type != MS_MSG_SCANNER_PARTIAL) &&
        req_result.complete_path != NULL) {
@@ -145,10 +143,13 @@ gboolean _read_socket(GIOChannel *src, GIOCondition condition, gpointer data)
 
                        for (i = 0; i < list_len; i++) {
                                req_data = g_array_index(req_list, media_scan_data*, i);
-                               if (strcmp(req_data->req_path, req_result.complete_path) == 0) {
+                               if (req_data != NULL && g_strcmp0(req_data->req_path, req_result.complete_path) == 0) {
                                        MSAPI_DBG("FIND REQUEST [%s]", req_data->req_path);
                                        g_array_remove_index(req_list, i);
 
+                                       /*call user define function*/
+                                       req_data->cb_data->user_callback(&req_result, user_data);
+
                                        /*close an IO channel*/
                                        g_io_channel_shutdown(src, FALSE, NULL);
                                        g_io_channel_unref(src);
@@ -169,6 +170,9 @@ gboolean _read_socket(GIOChannel *src, GIOCondition condition, gpointer data)
                }
                g_mutex_unlock(&scan_req_mutex);
                MS_SAFE_FREE(data);
+       } else {
+               /*call user define function. Scanner V2 case only*/
+               user_callback(&req_result, user_data);
        }
 
        MS_SAFE_FREE(req_result.complete_path);
@@ -254,6 +258,7 @@ static int _remove_request(const char * req_path)
                        user_data = ((media_callback_data *)cb_data)->user_data;
 
                        /*call user define function*/
+                       MSAPI_DBG("Call Cancel Callback");
                        user_callback(&req_result, user_data);
 
                        /*close an IO channel*/
@@ -275,13 +280,12 @@ static int _remove_request(const char * req_path)
 
                        break;
                }
+       }
 
-               if (flag == false) {
-                       MSAPI_DBG("Not in scan queue :%s", req_path);
-                       g_mutex_unlock(&scan_req_mutex);
-                       return MS_MEDIA_ERR_INVALID_PARAMETER;
-               }
-
+       if (flag == false) {
+               MSAPI_DBG("Not in scan queue :%s", req_path);
+               g_mutex_unlock(&scan_req_mutex);
+               return MS_MEDIA_ERR_INVALID_PARAMETER;
        }
 
        g_mutex_unlock(&scan_req_mutex);
@@ -333,7 +337,7 @@ static int __media_db_request_update_async(ms_msg_type_e msg_type, const char *s
                return MS_MEDIA_ERR_INVALID_PARAMETER;
        }
 
-       MSAPI_DBG("REQUEST DIRECTORY SCANNING[%s]", request_msg);
+       MSAPI_DBG("REQUEST UPDATE ASYNC [%d][%s]", msg_type, request_msg);
 
        request_msg_size = strlen(request_msg);
        if (request_msg_size >= MAX_MSG_SIZE) {