4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Yong Yeon Kim <yy9875.kim@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
24 #include "media-util.h"
25 #include "media-server-ipc.h"
26 #include "media-common-utils.h"
27 #include "media-common-external-storage.h"
28 #include "media-common-db-svc.h"
29 #include "media-scanner-dbg-v2.h"
30 #include "media-scanner-common-v2.h"
31 #include "media-scanner-socket-v2.h"
32 #include "media-scanner-scan-v2.h"
33 #include "media-scanner-extract-v2.h"
34 #include "media-scanner-db-manage-v2.h"
36 #define MAX_SCAN_COUNT 300
38 #define DIR_SCAN_NON_SCAN 0
39 #define DIR_SCAN_RECURSIVE 1
40 #define DIR_SCAN_NON_RECURSIVE 2
42 #define RECYCLE_DIR_NAME "$RECYCLE.BIN"
45 GAsyncQueue *storage_queue2;
46 static GAsyncQueue *scan_queue2;
47 static GAsyncQueue *reg_queue2;
48 static GMutex scan_req_mutex2;
49 static GMutex blocked_mutex2;
50 static GMutex storage_scan_mutex2;
51 static GMutex dir_scan_mutex2;
52 static GCond data_cond2; /* Must be initialized somewhere */
53 static GMutex data_mutex2; /* Must be initialized somewhere */
54 static GMutex scan_item_mutex;
56 static char *g_blocked_path2;
58 static s_scan_item* cancel_scan_item = NULL;
59 static s_scan_item* cur_scan_item = NULL;
61 int g_directory_scan_processing2 = DIR_SCAN_NON_SCAN;
62 static char *g_storage_scan_path;
63 static char* g_dir_scan_path;
64 static bool is_scanner_paused = false;
66 static int __msc_check_stop_status(int scan_type, const char *start_path, int pid);
67 static int __msc_get_null_scan_folder_list(sqlite3 *handle, const char *stroage_id, char *path, GPtrArray *dir_array);
68 static int __msc_check_scan_same_path(char *scan_path);
69 static void __msc_set_storage_scan_cur_path(char *scan_path);
70 static void __msc_set_dir_scan_cur_path(char *scan_path);
71 static int __msc_dir_and_storage_scan_same_path(char *start_path);
72 static int __msc_check_memory_status(uid_t uid);
73 static int __msc_check_remain_space(uid_t uid);
74 static void __msc_del_blocked_path(void);
76 void msc_init_scan_thread(void)
78 g_mutex_init(&data_mutex2);
79 g_mutex_init(&blocked_mutex2);
80 g_mutex_init(&scan_req_mutex2);
81 g_mutex_init(&storage_scan_mutex2);
82 g_mutex_init(&dir_scan_mutex2);
83 g_mutex_init(&scan_item_mutex);
85 g_cond_init(&data_cond2);
88 void msc_deinit_scan_thread(void)
90 g_mutex_clear(&data_mutex2);
91 g_mutex_clear(&blocked_mutex2);
92 g_mutex_clear(&scan_req_mutex2);
93 g_mutex_clear(&storage_scan_mutex2);
94 g_mutex_clear(&dir_scan_mutex2);
95 g_mutex_clear(&scan_item_mutex);
97 g_cond_clear(&data_cond2);
100 static void __msc_resume_scan(void)
102 g_mutex_lock(&data_mutex2);
104 if (is_scanner_paused) {
105 is_scanner_paused = false;
106 g_cond_signal(&data_cond2);
107 MS_DBG_WARN("storage scan resumed");
110 g_mutex_unlock(&data_mutex2);
113 static void __msc_pause_scan(void)
115 g_mutex_lock(&data_mutex2);
117 if (!is_scanner_paused) {
118 is_scanner_paused = true;
119 MS_DBG_WARN("storage scan paused");
121 while (is_scanner_paused)
122 g_cond_wait(&data_cond2, &data_mutex2);
125 g_mutex_unlock(&data_mutex2);
128 static int __msc_check_stop_status(int scan_type, const char *start_path, int pid)
130 int ret = MS_MEDIA_ERR_NONE;
132 /*check poweroff status*/
133 if (_msc_is_power_off())
134 return MS_MEDIA_ERR_SCANNER_FORCE_STOP;
136 if (scan_type == MS_MSG_DIRECTORY_SCANNING || scan_type == MS_MSG_DIRECTORY_SCANNING_NON_RECURSIVE) {
137 g_mutex_lock(&scan_req_mutex2);
138 /* check cancel path */
139 //MS_DBG_ERR("__msc_check_stop_status...");
140 if ((cancel_scan_item != NULL) && (cancel_scan_item->path != NULL)) {
141 MS_DBG_SWARN("check blocked storage [%s][%s]", cancel_scan_item->path, start_path);
142 if ((strncmp(cancel_scan_item->path, start_path, strlen(cancel_scan_item->path)) == 0)
143 && (cancel_scan_item->pid == -1 || cancel_scan_item->pid == pid)) {
144 MS_DBG_SWARN("Receive cancel request [%s][%s]. STOP scan!!", cancel_scan_item->path, start_path);
145 unsigned int path_len = strlen(cancel_scan_item->path);
147 if (strlen(start_path) > path_len) {
148 if (start_path[path_len] == '/') {
149 MS_DBG_ERR("start path is same as cancel path");
150 ret = MS_MEDIA_ERR_SCANNER_FORCE_STOP;
152 MS_DBG_ERR("start path is not same as cancel path");
155 ret = MS_MEDIA_ERR_SCANNER_FORCE_STOP;
160 g_mutex_unlock(&scan_req_mutex2);
163 if (scan_type == MS_MSG_STORAGE_ALL || scan_type == MS_MSG_STORAGE_PARTIAL) {
164 g_mutex_lock(&blocked_mutex2);
165 /* check cancel path */
166 if (g_blocked_path2 != NULL) {
167 MS_DBG_SWARN("check blocked storage [%s][%s]", g_blocked_path2, start_path);
168 if (strncmp(start_path, g_blocked_path2, strlen(start_path)) == 0) {
169 MS_DBG_ERR("Receive blocked message[%s][%s]. STOP scan!!",
170 g_blocked_path2, start_path);
171 ret = MS_MEDIA_ERR_SCANNER_FORCE_STOP;
174 MS_SAFE_FREE(g_blocked_path2);
177 g_mutex_unlock(&blocked_mutex2);
183 static int __msc_dir_scan_for_folder(sqlite3 *handle, const char *storage_id, char *start_path, int scan_type, int pid, uid_t uid)
185 GPtrArray *dir_array = NULL;
186 int ret = MS_MEDIA_ERR_NONE;
187 char *new_path = NULL;
188 char *current_path = NULL;
189 char path[MS_FILE_PATH_LEN_MAX] = {0, };
190 bool is_recursive = (scan_type == MS_MSG_DIRECTORY_SCANNING);
191 char *new_start_path = NULL;
197 GError *error = NULL;
200 MS_DBG_SWARN("storage id [%s] start path [%s]", storage_id, start_path);
202 new_start_path = g_strdup(start_path);
204 dir_array = g_ptr_array_new();
205 g_ptr_array_add(dir_array, start_path);
207 if (g_file_test(new_start_path, G_FILE_TEST_IS_DIR)) {
208 if (ms_insert_folder(handle, storage_id, new_start_path, uid) != MS_MEDIA_ERR_NONE)
209 MS_DBG_ERR("insert folder failed");
211 MS_DBG_SWARN("ms_insert_folder insert path[%s]", new_start_path);
213 if (ms_set_folder_validity(handle, storage_id, new_start_path, MS_INVALID, is_recursive, uid) != MS_MEDIA_ERR_NONE)
214 MS_DBG_ERR("set_folder_validity failed [%d] ", scan_type);
217 while (dir_array->len != 0) {
218 ret = __msc_check_stop_status(scan_type, new_start_path, pid);
219 if (ret != MS_MEDIA_ERR_NONE) {
221 ms_change_validity_item_batch(handle, storage_id, new_start_path, 1, 2, uid);
226 ms_batch_commit_disable(uid);
227 ms_batch_commit_enable(false, pid);
229 current_path = g_ptr_array_index(dir_array, 0);
230 g_ptr_array_remove_index(dir_array, 0);
232 __msc_set_dir_scan_cur_path(current_path);
234 ret = ms_check_scan_ignore(current_path, uid);
235 if (ret != MS_MEDIA_ERR_NONE) {
236 MS_DBG_SERR("%s is ignore", current_path);
237 MS_SAFE_FREE(current_path);
238 if (ret == MS_MEDIA_ERR_USB_UNMOUNTED)
241 ret = MS_MEDIA_ERR_NONE;
245 ret = msc_check_db_size(uid, scan_type);
246 if (ret != MS_MEDIA_ERR_NONE) {
247 if (ret == MS_MEDIA_ERR_DB_FULL_FAIL)
248 ret = MS_MEDIA_ERR_NONE;
251 ms_change_validity_item_batch(handle, storage_id, new_start_path, 1, 2, uid);
256 ms_set_folder_scan_status(handle, storage_id, current_path, MS_DIR_SCAN_PROCESSING, uid);
259 dir = g_dir_open(current_path, 0, &error);
261 MS_DBG_ERR("g_dir_open fails [%s]", current_path);
262 MS_SAFE_FREE(current_path);
268 while ((name = g_dir_read_name(dir))) {
270 if (sleep_count % 5 == 0) {
272 usleep(SCAN_SLEEP_TIME);
275 ret = __msc_check_stop_status(scan_type, new_start_path, pid);
276 if (ret != MS_MEDIA_ERR_NONE) {
278 ms_change_validity_item_batch(handle, storage_id, new_start_path, 1, 2, uid);
283 ret = msc_check_db_size(uid, scan_type);
284 if (ret != MS_MEDIA_ERR_NONE) {
285 if (ret == MS_MEDIA_ERR_DB_FULL_FAIL)
286 ret = MS_MEDIA_ERR_NONE;
289 ms_change_validity_item_batch(handle, storage_id, new_start_path, 1, 2, uid);
297 if (strcmp(name, RECYCLE_DIR_NAME) == 0)
300 if (g_snprintf(path, MS_FILE_PATH_LEN_MAX, "%s/%s", current_path, name) >= MS_FILE_PATH_LEN_MAX) {
301 MS_DBG_ERR("g_snprintf failed");
305 if (g_file_test(path, G_FILE_TEST_IS_REGULAR)) {
306 if (!ms_check_support_media_type(path))
309 ret = ms_scan_validate_item(handle, storage_id, path, uid);
310 if (ret != MS_MEDIA_ERR_NONE) {
311 MS_DBG_ERR("failed to update db : %d", ret);
316 if (scan_count >= MAX_SCAN_COUNT) {
319 ret = __msc_check_stop_status(scan_type, new_start_path, pid);
320 if (ret == MS_MEDIA_ERR_NONE) {
321 msc_insert_exactor_request(scan_type, false, storage_id, current_path, pid, uid, MS_ITEM_UPDATE);
324 ms_change_validity_item_batch(handle, storage_id, new_start_path, 1, 2, uid);
330 if (scan_type == MS_MSG_DIRECTORY_SCANNING) {
331 new_path = g_strdup(path);
332 g_ptr_array_add(dir_array, new_path);
334 if (ms_insert_folder(handle, storage_id, new_path, uid) != MS_MEDIA_ERR_NONE)
335 MS_DBG_ERR("insert folder failed");
338 if (ms_insert_folder(handle, storage_id, path, uid) != MS_MEDIA_ERR_NONE) {
339 MS_DBG_ERR("insert folder failed");
345 if (scan_type == MS_MSG_DIRECTORY_SCANNING_NON_RECURSIVE)
346 ms_update_folder_time(handle, storage_id, current_path, uid);
348 ms_set_folder_scan_status(handle, storage_id, current_path, MS_DIR_SCAN_DONE, uid);
350 MS_SAFE_FREE(current_path);
357 __msc_set_dir_scan_cur_path(NULL);
358 usleep(SCAN_SLEEP_TIME);
364 MS_DBG_ERR("stop folder scan...");
365 ms_set_folder_scan_status(handle, storage_id, current_path, MS_DIR_SCAN_STOP, uid);
366 MS_SAFE_FREE(current_path);
374 g_free(new_start_path);
375 __msc_set_dir_scan_cur_path(NULL);
377 g_ptr_array_free(dir_array, TRUE);
379 ms_batch_commit_disable(uid);
381 if (ret != MS_MEDIA_ERR_NONE)
382 MS_DBG_INFO("ret : %d", ret);
387 static int __msc_dir_scan_for_storage(sqlite3 *handle, const char *storage_id, char *start_path, int scan_type, int pid, uid_t uid)
389 GPtrArray *dir_array = NULL;
390 int ret = MS_MEDIA_ERR_NONE;
391 char *new_path = NULL;
392 char *current_path = NULL;
393 char path[MS_FILE_PATH_LEN_MAX] = {0, };
394 int (*scan_function)(sqlite3 *, const char*, const char*, uid_t) = NULL;
395 char *new_start_path = NULL;
401 GError *error = NULL;
404 bool is_missing = false;
405 ms_dir_scan_status_e scan_status = MS_DIR_SCAN_NONE;
407 MS_DBG_SWARN("storage id [%s] start path [%s]", storage_id, start_path);
409 new_start_path = g_strdup(start_path);
411 dir_array = g_ptr_array_new();
412 g_ptr_array_add(dir_array, start_path);
414 if (ms_insert_folder(handle, storage_id, new_start_path, uid) != MS_MEDIA_ERR_NONE)
415 MS_DBG_ERR("insert folder failed");
417 scan_function = (scan_type == MS_MSG_STORAGE_ALL) ? ms_scan_item_batch : ms_scan_validate_item;
419 ms_batch_commit_disable(uid);
421 while (dir_array->len != 0) {
422 ret = __msc_check_stop_status(scan_type, new_start_path, pid);
423 if (ret != MS_MEDIA_ERR_NONE)
426 ms_batch_commit_enable(false, pid);
428 current_path = g_ptr_array_index(dir_array, 0);
429 g_ptr_array_remove_index(dir_array, 0);
431 __msc_set_storage_scan_cur_path(current_path);
433 ret = ms_check_scan_ignore(current_path, uid);
434 if (ret != MS_MEDIA_ERR_NONE) {
435 MS_DBG_SERR("%s is ignore", current_path);
436 MS_SAFE_FREE(current_path);
437 if (ret == MS_MEDIA_ERR_USB_UNMOUNTED)
440 ret = MS_MEDIA_ERR_NONE;
444 ret = msc_check_db_size(uid, scan_type);
445 if (ret != MS_MEDIA_ERR_NONE)
448 ms_get_folder_scan_status(handle, storage_id, current_path, (int *)&scan_status);
450 if (scan_status == MS_DIR_SCAN_PROCESSING && g_directory_scan_processing2 != DIR_SCAN_NON_SCAN) {
452 MS_DBG_SERR("%s is scanning, ignore current path, scan next path !!", current_path);
457 } else if (scan_status == MS_DIR_SCAN_DONE) {
458 if (g_directory_scan_processing2 == DIR_SCAN_NON_RECURSIVE) {
459 MS_DBG_SERR("%s is scan done, ignore current path, get subfolder list!!", current_path);
461 __msc_get_null_scan_folder_list(handle, storage_id, current_path, dir_array);
465 } else if (g_directory_scan_processing2 == DIR_SCAN_RECURSIVE) {
466 MS_DBG_SERR("%s is scan done, ignore current path, scan next path!!", current_path);
473 ms_set_folder_scan_status(handle, storage_id, current_path, MS_DIR_SCAN_PROCESSING, uid);
476 dir = g_dir_open(current_path, 0, &error);
478 MS_DBG_ERR("g_dir_open fails [%s]", current_path);
479 MS_SAFE_FREE(current_path);
485 while ((name = g_dir_read_name(dir))) {
487 if (sleep_count % 5 == 0) {
489 usleep(SCAN_SLEEP_TIME);
492 ret = __msc_check_stop_status(scan_type, new_start_path, pid);
493 if (ret != MS_MEDIA_ERR_NONE)
496 ret = msc_check_db_size(uid, scan_type);
497 if (ret != MS_MEDIA_ERR_NONE)
503 if (strcmp(name, RECYCLE_DIR_NAME) == 0)
506 if (g_snprintf(path, MS_FILE_PATH_LEN_MAX, "%s/%s", current_path, name) >= MS_FILE_PATH_LEN_MAX) {
507 MS_DBG_ERR("g_snprintf failed");
511 if (g_file_test(path, G_FILE_TEST_IS_REGULAR)) {
512 if (!ms_check_support_media_type(path))
515 ret = scan_function(handle, storage_id, path, uid);
516 if (ret != MS_MEDIA_ERR_NONE) {
517 MS_DBG_ERR("failed to update db : %d", scan_type);
521 if (scan_count >= MAX_SCAN_COUNT) {
523 msc_insert_exactor_request(scan_type, false, storage_id, current_path, 0, uid, MS_ITEM_UPDATE);
527 new_path = g_strdup(path);
528 g_ptr_array_add(dir_array, new_path);
530 if (ms_insert_folder(handle, storage_id, new_path, uid) != MS_MEDIA_ERR_NONE)
531 MS_DBG_ERR("insert folder failed");
535 ms_batch_commit_disable(uid);
536 ms_set_folder_scan_status(handle, storage_id, current_path, MS_DIR_SCAN_DONE, uid);
544 MS_SAFE_FREE(current_path);
545 __msc_set_storage_scan_cur_path(NULL);
547 if (dir_array->len == 0 && is_missing) {
550 if (g_directory_scan_processing2 == DIR_SCAN_NON_SCAN) {
551 ret = __msc_get_null_scan_folder_list(handle, storage_id, NULL, dir_array);
553 MS_DBG_WARN("no wait folder scan callback");
555 if (ret != MS_MEDIA_ERR_NONE)
560 ret = __msc_get_null_scan_folder_list(handle, storage_id, NULL, dir_array);
562 if (ret != MS_MEDIA_ERR_NONE)
566 usleep(SCAN_SLEEP_TIME);
569 if (!MS_STRING_VALID(MEDIA_ROOT_PATH_USB)) {
570 MS_DBG_ERR("Fail to get USB path");
574 if (strstr(new_start_path, MEDIA_ROOT_PATH_USB) != NULL) {
575 if (!ms_storage_mount_status(new_start_path)) {
576 MS_DBG_ERR("start path is unmounted");
581 if ((g_directory_scan_processing2 != DIR_SCAN_NON_SCAN)
582 && (__msc_dir_and_storage_scan_same_path(new_start_path) == MS_MEDIA_ERR_NONE))
588 if (current_path != NULL)
589 ms_set_folder_scan_status(handle, storage_id, current_path, MS_DIR_SCAN_STOP, uid);
590 MS_SAFE_FREE(current_path);
598 g_free(new_start_path);
599 __msc_set_storage_scan_cur_path(NULL);
600 g_ptr_array_free(dir_array, TRUE);
602 ms_batch_commit_disable(uid);
604 if (ret != MS_MEDIA_ERR_NONE)
605 MS_DBG_INFO("ret : %d", ret);
610 static int __msc_get_null_scan_folder_list(sqlite3 *handle, const char *stroage_id, char *path, GPtrArray *dir_array)
612 int ret = MS_MEDIA_ERR_NONE;
613 GPtrArray *cur_dir_array = NULL;
615 ret = ms_get_null_scan_folder_list(handle, stroage_id, path, &cur_dir_array);
616 if (ret == MS_MEDIA_ERR_NONE) {
617 MS_DBG_WARN("cur_dir_array->len = [%d]", cur_dir_array->len);
618 g_ptr_array_extend_and_steal(dir_array, cur_dir_array);
624 static int __msc_check_scan_same_path(char *scan_path)
626 int ret = MS_MEDIA_ERR_NONE;
627 unsigned int storage_len, folder_len, min_len;
629 g_mutex_lock(&storage_scan_mutex2);
631 if (NULL == scan_path || NULL == g_storage_scan_path) {
632 g_mutex_unlock(&storage_scan_mutex2);
634 return MS_MEDIA_ERR_INTERNAL;
637 storage_len = strlen(g_storage_scan_path);
638 folder_len = strlen(scan_path);
639 min_len = storage_len > folder_len ? folder_len : storage_len;
641 ret = strncmp(g_storage_scan_path, scan_path, min_len);
643 g_mutex_unlock(&storage_scan_mutex2);
648 static void __msc_set_storage_scan_cur_path(char *scan_path)
650 g_mutex_lock(&storage_scan_mutex2);
652 g_free(g_storage_scan_path);
653 g_storage_scan_path = g_strdup(scan_path);
655 g_mutex_unlock(&storage_scan_mutex2);
658 static int __msc_dir_and_storage_scan_same_path(char *start_path)
660 int ret = MS_MEDIA_ERR_NONE;
661 unsigned int storage_len, folder_len;
663 char *storage_path = NULL;
664 char *remain_path = NULL;
667 if (!MS_STRING_VALID(MEDIA_ROOT_PATH_USB)) {
668 MS_DBG_ERR("Fail to get USB path");
669 return MS_MEDIA_ERR_INTERNAL;
672 remain_path = strstr(start_path+strlen(MEDIA_ROOT_PATH_USB) +1, "/");
673 if (remain_path != NULL)
674 remain_len = strlen(remain_path);
676 storage_path = g_strndup(start_path, strlen(start_path) - remain_len);
678 g_mutex_lock(&dir_scan_mutex2);
680 if (NULL == g_dir_scan_path || NULL == storage_path) {
681 g_free(storage_path);
682 g_mutex_unlock(&dir_scan_mutex2);
684 return MS_MEDIA_ERR_INTERNAL;
687 storage_len = strlen(storage_path);
688 folder_len = strlen(g_dir_scan_path);
690 if (folder_len < storage_len)
693 ret = strncmp(storage_path, g_dir_scan_path, storage_len);
695 g_free(storage_path);
696 g_mutex_unlock(&dir_scan_mutex2);
702 static void __msc_set_dir_scan_cur_path(char *scan_path)
704 g_mutex_lock(&dir_scan_mutex2);
706 g_free(g_dir_scan_path);
707 g_dir_scan_path = g_strdup(scan_path);
709 g_mutex_unlock(&dir_scan_mutex2);
712 static int __msc_db_update(sqlite3 *handle, const char *storage_id, const ms_comm_msg_s * scan_data)
714 int err = MS_MEDIA_ERR_NONE;
715 char *start_path = NULL;
717 if (scan_data->msg_type != MS_MSG_STORAGE_INVALID) {
718 MS_DBG_WARN("INSERT");
719 start_path = g_strdup(scan_data->msg);
720 if (scan_data->msg_type == MS_MSG_DIRECTORY_SCANNING || scan_data->msg_type == MS_MSG_DIRECTORY_SCANNING_NON_RECURSIVE)
721 err = __msc_dir_scan_for_folder(handle, storage_id, start_path, scan_data->msg_type, scan_data->pid, scan_data->uid);
722 else if (scan_data->msg_type == MS_MSG_STORAGE_ALL || scan_data->msg_type == MS_MSG_STORAGE_PARTIAL)
723 err = __msc_dir_scan_for_storage(handle, storage_id, start_path, scan_data->msg_type, scan_data->pid, scan_data->uid);
725 if (err != MS_MEDIA_ERR_NONE)
726 MS_DBG_ERR("error : %d", err);
729 MS_DBG_WARN("INVALID");
730 msc_remove_extract_request(scan_data);
738 static int __msc_set_scan_item(s_scan_item **item, const char* path, int pid)
740 s_scan_item* scan_item = *item;
743 scan_item = g_new0(s_scan_item, 1);
745 g_free(scan_item->path);
747 scan_item->path = g_strdup(path);
748 scan_item->pid = pid;
752 MS_DBG_SWARN("path[%s],pid[%d]", scan_item->path, scan_item->pid);
754 return MS_MEDIA_ERR_NONE;
757 static void __msc_del_cancel_scan_item(void)
759 g_mutex_lock(&scan_item_mutex);
761 if (cancel_scan_item) {
762 g_free(cancel_scan_item->path);
763 g_free(cancel_scan_item);
764 cancel_scan_item = NULL;
767 g_mutex_unlock(&scan_item_mutex);
770 static void __msc_del_cur_scan_item(void)
772 g_mutex_lock(&scan_item_mutex);
775 g_free(cur_scan_item->path);
776 g_free(cur_scan_item);
777 cur_scan_item = NULL;
780 g_mutex_unlock(&scan_item_mutex);
783 gpointer msc_directory_scan_thread(gpointer data)
785 ms_comm_msg_s *scan_data = NULL;
786 int ret = MS_MEDIA_ERR_NONE;
787 sqlite3 *handle = NULL;
788 bool modified = false;
789 ms_dir_scan_status_e scan_status = MS_DIR_SCAN_NONE;
790 ms_noti_type_e noti_type = MS_ITEM_INSERT;
791 char *folder_uuid = NULL;
792 bool is_recursive = true;
795 scan_data = g_async_queue_pop(scan_queue2);
796 ret = MS_MEDIA_ERR_NONE;
798 if (scan_data->pid == POWEROFF) {
799 MS_DBG_ERR("power off");
803 MS_DBG_WARN("DIRECTORY SCAN START [%.*s][%s][%d]", MAX_MSG_SIZE, scan_data->msg, scan_data->storage_id, scan_data->msg_type);
805 if (strlen(scan_data->storage_id) == 0) {
806 MS_DBG_ERR("storage_id length is 0");
807 ret = MS_MEDIA_ERR_INVALID_PARAMETER;
811 if (scan_data->msg_type != MS_MSG_DIRECTORY_SCANNING &&
812 scan_data->msg_type != MS_MSG_DIRECTORY_SCANNING_NON_RECURSIVE) {
813 MS_DBG_ERR("Invalid request");
814 ret = MS_MEDIA_ERR_INVALID_PARAMETER;
818 ret = ms_connect_db(&handle, scan_data->uid);
819 if (ret != MS_MEDIA_ERR_NONE) {
820 MS_DBG_ERR("ms_connect_db failed");
824 /*check remain space*/
825 if (__msc_check_remain_space(scan_data->uid) != MS_MEDIA_ERR_NONE)
828 g_mutex_lock(&scan_item_mutex);
829 __msc_set_scan_item(&cur_scan_item, scan_data->msg, scan_data->pid);
830 g_mutex_unlock(&scan_item_mutex);
832 g_directory_scan_processing2 = DIR_SCAN_NON_RECURSIVE;
834 ms_trim_dir_path(scan_data->msg);
836 if (g_file_test(scan_data->msg, G_FILE_TEST_IS_DIR)) {
837 is_recursive = (scan_data->msg_type == MS_MSG_DIRECTORY_SCANNING);
838 if (ms_check_folder_exist(handle, scan_data->storage_id, scan_data->msg) == MS_MEDIA_ERR_NONE) {
839 noti_type = MS_ITEM_UPDATE;
840 MS_DBG_WARN("[%.*s] already exist", MAX_MSG_SIZE, scan_data->msg);
842 noti_type = MS_ITEM_INSERT;
843 MS_DBG_WARN("[%.*s] new insert path", MAX_MSG_SIZE, scan_data->msg);
847 noti_type = MS_ITEM_DELETE;
848 scan_data->msg_type = MS_MSG_DIRECTORY_SCANNING;
850 ms_get_folder_id(handle, scan_data->storage_id, scan_data->msg, &folder_uuid);
852 MS_DBG_SWARN("[%.*s][%s] delete path", MAX_MSG_SIZE, scan_data->msg, folder_uuid);
855 if (scan_data->msg_type == MS_MSG_DIRECTORY_SCANNING) {
856 MS_DBG_WARN("start recursive dir scan!!");
857 g_directory_scan_processing2 = DIR_SCAN_RECURSIVE;
859 if (__msc_check_scan_same_path(scan_data->msg) == 0) {
860 MS_DBG_WARN("[%.*s] is scanning recursive, waiting...", MAX_MSG_SIZE, scan_data->msg);
861 msc_send_result_partial(ret, MS_MSG_RECURSIVE_START, scan_data->pid, scan_data->msg);
863 while (__msc_check_scan_same_path(scan_data->msg) == 0) {
866 ret = __msc_check_stop_status(scan_data->msg_type, scan_data->msg, scan_data->pid);
867 if (ret != MS_MEDIA_ERR_NONE)
871 MS_DBG_WARN("[%.*s] scan done, wait finished", MAX_MSG_SIZE, scan_data->msg);
876 ms_get_folder_scan_status(handle, scan_data->storage_id, scan_data->msg, (int*)&scan_status);
878 if (scan_status == MS_DIR_SCAN_DONE)
879 ms_set_folder_item_validity(handle, scan_data->storage_id, scan_data->msg, MS_VALID_V2, MS_RECURSIVE, scan_data->uid);
881 ms_set_folder_item_validity(handle, scan_data->storage_id, scan_data->msg, MS_INVALID, MS_RECURSIVE, scan_data->uid);
883 msc_send_result_partial(ret, MS_MSG_RECURSIVE_START, scan_data->pid, scan_data->msg);
885 MS_DBG_WARN("start non recursive dir scan!!");
887 g_directory_scan_processing2 = DIR_SCAN_NON_RECURSIVE;
888 ms_check_folder_modified(handle, scan_data->msg, scan_data->storage_id, &modified);
891 MS_DBG_WARN("check [%.*s] has not been modified !!", MAX_MSG_SIZE, scan_data->msg);
892 ms_get_folder_scan_status(handle, scan_data->storage_id, scan_data->msg, (int*)&scan_status);
893 MS_DBG_WARN("folder scan status = [%d]", scan_status);
895 if (scan_status == MS_DIR_SCAN_DONE) {
896 MS_DBG_WARN("[%.*s] scan done", MAX_MSG_SIZE, scan_data->msg);
898 } else if (scan_status == MS_DIR_SCAN_PROCESSING) {
899 MS_DBG_WARN("[%.*s] scanning, waiting...", MAX_MSG_SIZE, scan_data->msg);
904 ret = __msc_check_stop_status(scan_data->msg_type, scan_data->msg, scan_data->pid);
905 if (ret != MS_MEDIA_ERR_NONE)
909 ms_get_folder_scan_status(handle, scan_data->storage_id, scan_data->msg, (int*)&scan_status);
910 if (scan_status == MS_DIR_SCAN_DONE) {
911 MS_DBG_WARN("[%.*s] [MS_DIR_SCAN_DONE]", MAX_MSG_SIZE, scan_data->msg);
915 if (scan_status == MS_DIR_SCAN_STOP) {
916 MS_DBG_WARN("[%.*s] [MS_DIR_SCAN_STOP]", MAX_MSG_SIZE, scan_data->msg);
922 MS_DBG_WARN("check [%.*s] has been modified !!", MAX_MSG_SIZE, scan_data->msg);
925 ret = ms_set_folder_item_validity(handle, scan_data->storage_id, scan_data->msg, MS_INVALID, MS_NON_RECURSIVE, scan_data->uid);
926 if (ret != MS_MEDIA_ERR_NONE)
927 MS_DBG_ERR("error : %d", ret);
930 ms_batch_commit_enable(false, 0);
932 ret = __msc_db_update(handle, scan_data->storage_id, scan_data);
934 ms_batch_commit_disable(scan_data->uid);
936 MS_DBG_WARN("folder scan done, sent cb event path = [%.*s]", MAX_MSG_SIZE, scan_data->msg);
940 if (ms_delete_invalid_items_in_folder(handle, scan_data->storage_id, scan_data->msg, is_recursive, scan_data->uid) != MS_MEDIA_ERR_NONE)
941 MS_DBG_ERR("deleting invalid items in folder failed");
944 MS_DBG_WARN("storage_id = [%s], dir Path = [%.*s], pid = [%d]", scan_data->storage_id, MAX_MSG_SIZE, scan_data->msg, scan_data->pid);
945 if (ret != MS_MEDIA_ERR_SCANNER_FORCE_STOP) {
947 if (ms_delete_invalid_folder_by_path(handle, scan_data->storage_id, scan_data->msg, scan_data->uid) != MS_MEDIA_ERR_NONE)
948 MS_DBG_ERR("deleting invalid folder failed");
951 if (noti_type == MS_ITEM_DELETE)
952 ms_send_dir_update_noti(scan_data->msg, folder_uuid, noti_type, scan_data->pid);
954 msc_insert_exactor_request(scan_data->msg_type, true, scan_data->storage_id, scan_data->msg, scan_data->pid, scan_data->uid, noti_type);
957 if (_msc_is_power_off())
962 scan_data->msg_type = MS_MSG_SCANNER_COMPLETE;
963 msc_send_result(ret, scan_data);
970 g_directory_scan_processing2 = DIR_SCAN_NON_SCAN;
971 __msc_del_cur_scan_item();
972 __msc_del_cancel_scan_item();
974 MS_DBG_WARN("DIRECTORY SCAN END [%d]", ret);
976 ms_disconnect_db(handle);
977 usleep(SCAN_SLEEP_TIME);
982 ms_disconnect_db(handle);
987 static void __msc_check_pvr_svc(void)
989 if (!ms_is_support_pvr())
992 MS_DBG_ERR("Waiting PVR service");
993 while (!_msc_is_power_off()) {
994 if (g_file_test("/run/pvr_ready", G_FILE_TEST_EXISTS))
1000 MS_DBG_WARN("PVR service is ready");
1003 gpointer msc_storage_scan_thread(gpointer data)
1005 int ret = MS_MEDIA_ERR_NONE;
1006 ms_comm_msg_s *scan_data = NULL;
1007 sqlite3 *handle = NULL;
1008 ms_user_storage_type_e storage_type = MS_USER_STORAGE_INTERNAL;
1011 scan_data = g_async_queue_pop(storage_queue2);
1012 if (scan_data->pid == POWEROFF) {
1013 MS_DBG_ERR("power off");
1017 MS_DBG_WARN("STORAGE SCAN START [%.*s][%s]", MAX_MSG_SIZE, scan_data->msg, scan_data->storage_id);
1019 if (scan_data->msg_type != MS_MSG_STORAGE_ALL &&
1020 scan_data->msg_type != MS_MSG_STORAGE_PARTIAL &&
1021 scan_data->msg_type != MS_MSG_STORAGE_INVALID) {
1022 MS_DBG_ERR("Invalid request[%d]", scan_data->msg_type);
1023 ret = MS_MEDIA_ERR_INVALID_PARAMETER;
1027 __msc_check_pvr_svc();
1029 ret = ms_connect_db(&handle, scan_data->uid);
1030 if (ret != MS_MEDIA_ERR_NONE) {
1031 MS_DBG_ERR("ms_connect_db failed");
1035 ret = ms_user_get_storage_type(scan_data->uid, scan_data->msg, &storage_type);
1036 if (ret != MS_MEDIA_ERR_NONE) {
1037 MS_DBG_ERR("ms_user_get_storage_type failed");
1041 ret = __msc_check_memory_status(scan_data->uid);
1042 if (ret != MS_MEDIA_ERR_NONE) {
1043 ms_set_storage_scan_status(handle, scan_data->storage_id, MEDIA_SCAN_STOP, scan_data->uid);
1044 MS_DBG_ERR("storage_id = [%s]", scan_data->storage_id);
1045 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);
1049 ms_set_storage_scan_status(handle, scan_data->storage_id, MEDIA_SCAN_PROCESSING, scan_data->uid);
1051 ms_set_db_status(MS_DB_UPDATING, storage_type);
1053 if (scan_data->msg_type != MS_MSG_STORAGE_INVALID)
1054 ms_batch_commit_enable(false, 0);
1056 if (scan_data->msg_type == MS_MSG_STORAGE_ALL) {
1057 if (ms_delete_invalid_items(handle, scan_data->storage_id, scan_data->uid) != MS_MEDIA_ERR_NONE)
1058 MS_DBG_ERR("ms_delete_invalid_items fails");
1061 ret = __msc_db_update(handle, scan_data->storage_id, scan_data);
1063 if (scan_data->msg_type != MS_MSG_STORAGE_INVALID)
1064 ms_batch_commit_disable(scan_data->uid);
1066 if (scan_data->msg_type == MS_MSG_STORAGE_PARTIAL && ret == MS_MEDIA_ERR_NONE) {
1067 ms_delete_invalid_folder(scan_data->storage_id, scan_data->uid);
1068 ms_delete_invalid_items(handle, scan_data->storage_id, scan_data->uid);
1071 if (ret == MS_MEDIA_ERR_SCANNER_FORCE_STOP) {
1072 ms_set_storage_scan_status(handle, scan_data->storage_id, MEDIA_SCAN_STOP, scan_data->uid);
1073 ms_set_db_status(MS_DB_STOPPED, storage_type);
1075 ms_set_storage_scan_status(handle, scan_data->storage_id, MEDIA_SCAN_COMPLETE, scan_data->uid);
1076 ms_set_db_status(MS_DB_UPDATED, storage_type);
1079 MS_DBG_WARN("storage_id = [%s]", scan_data->storage_id);
1080 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);
1083 __msc_del_blocked_path();
1085 if (_msc_is_power_off())
1088 ms_disconnect_db(handle);
1092 scan_data->msg_type = MS_MSG_SCANNER_COMPLETE;
1093 msc_send_result(ret, scan_data);
1098 MS_DBG_WARN("STORAGE SCAN END[%d]", ret);
1100 usleep(SCAN_SLEEP_TIME);
1105 ms_disconnect_db(handle);
1110 static int __msc_make_file_list(char *file_path, GPtrArray **path_array, uid_t uid)
1113 char buf[MS_FILE_PATH_LEN_MAX] = {0, };
1116 GPtrArray *_path_array = NULL;
1117 int ret = MS_MEDIA_ERR_NONE;
1119 fp = fopen(file_path, "rt");
1120 MS_DBG_RETVM_IF(!fp, MS_MEDIA_ERR_INTERNAL, "fopen failed");
1122 _path_array = g_ptr_array_new_with_free_func(g_free);
1124 while (fgets(buf, MS_FILE_PATH_LEN_MAX, fp) != NULL) {
1126 length = strlen(buf);
1127 path = g_strndup(buf, length - 1);
1129 /* check valid path */
1130 ret = ms_check_ignore_dir(path, uid);
1131 if (ret != MS_MEDIA_ERR_NONE) {
1132 MS_DBG_SERR("Invalid path : %s", path);
1137 g_ptr_array_add(_path_array, path);
1142 *path_array = _path_array;
1144 return MS_MEDIA_ERR_NONE;
1147 static int __msc_batch_insert(int pid, GPtrArray *path_array, uid_t uid)
1149 int ret = MS_MEDIA_ERR_NONE;
1150 sqlite3 *handle = NULL;
1151 char *insert_path = NULL;
1152 char storage_id[MS_UUID_SIZE] = {0,};
1157 ret = ms_connect_db(&handle, uid);
1158 MS_DBG_RETV_IF(ret != MS_MEDIA_ERR_NONE, MS_MEDIA_ERR_DB_INTERNAL);
1160 ms_batch_commit_enable(true, pid);
1162 for (i = 0; i < path_array->len; i++) {
1163 insert_path = g_ptr_array_index(path_array, i);
1165 memset(storage_id, 0x0, MS_UUID_SIZE);
1166 if (ms_get_storage_id(handle, insert_path, storage_id, uid) != MS_MEDIA_ERR_NONE) {
1167 MS_DBG_ERR("There is no storage id in media db");
1171 ret = ms_insert_item_batch(handle, storage_id, insert_path, uid);
1173 if (_msc_is_power_off()) {
1174 ret = MS_MEDIA_ERR_SCANNER_FORCE_STOP;
1179 /*call for bundle commit*/
1180 ms_batch_commit_disable(uid);
1181 ms_disconnect_db(handle);
1188 gpointer msc_register_thread(gpointer data)
1190 int ret = MS_MEDIA_ERR_NONE;
1191 ms_comm_msg_s *register_data = NULL;
1192 GPtrArray *path_array = NULL;
1195 register_data = g_async_queue_pop(reg_queue2);
1196 if (register_data->pid == POWEROFF) {
1197 MS_DBG_ERR("power off");
1198 g_free(register_data);
1202 if (register_data->msg_type == MS_MSG_BULK_INSERT) {
1203 ret = __msc_make_file_list(register_data->msg, &path_array, register_data->uid);
1204 if (ret == MS_MEDIA_ERR_NONE) {
1205 MS_DBG_SLOG("BULK REGISTER START [%.*s]", MAX_MSG_SIZE, register_data->msg);
1206 ret = __msc_batch_insert(register_data->pid, path_array, register_data->uid);
1207 g_ptr_array_free(path_array, TRUE);
1209 MS_DBG_WARN("BULK REGISTER END [%d]", ret);
1211 MS_DBG_ERR("__msc_make_file_list failed [%d]", ret);
1215 MS_DBG_ERR("invalid message type [%d]", register_data->msg_type);
1216 ret = MS_MEDIA_ERR_INVALID_PARAMETER;
1222 msc_send_result(ret, register_data);
1223 g_free(register_data);
1229 int msc_set_cancel_scan_item(const char* cancel_path, int pid)
1232 MS_DBG_WARN("msc_set_cancel_scan_item begin");
1233 g_mutex_lock(&scan_item_mutex);
1234 if (cancel_path == NULL) {
1235 MS_DBG_ERR("cancel_path invalid...");
1239 if (cur_scan_item != NULL && cur_scan_item->path != NULL) {
1240 MS_DBG_SWARN("cur_scan_item->path[%s], cur_scan_item->pid[%d]", cur_scan_item->path, cur_scan_item->pid);
1241 MS_DBG_SWARN("cancel_path[%s], pid[%d]", cancel_path, pid);
1242 if ((strcmp(cur_scan_item->path, cancel_path) == 0) && (pid == cur_scan_item->pid))
1243 ret = __msc_set_scan_item(&cancel_scan_item, cancel_path, pid);
1244 else if ((pid == -1) && (strncmp(cur_scan_item->path, cancel_path, strlen(cancel_path)) == 0))
1245 ret = __msc_set_scan_item(&cancel_scan_item, cancel_path, pid);
1247 MS_DBG_ERR("cur_scan_item == NULL || cur_scan_item->path == NULL");
1249 g_mutex_unlock(&scan_item_mutex);
1251 MS_DBG_WARN("msc_set_cancel_scan_item end");
1255 void msc_set_blocked_path(const char *blocked_path)
1259 g_mutex_lock(&blocked_mutex2);
1261 if (g_blocked_path2 != NULL) {
1262 MS_DBG_SWARN("g_blocked_path is not NULL [%s]", g_blocked_path2);
1263 g_free(g_blocked_path2);
1266 g_blocked_path2 = g_strdup(blocked_path);
1268 g_mutex_unlock(&blocked_mutex2);
1273 static void __msc_del_blocked_path(void)
1277 g_mutex_lock(&blocked_mutex2);
1279 if (g_blocked_path2 != NULL) {
1280 MS_DBG_SWARN("g_blocked_path is not NULL [%s]", g_blocked_path2);
1281 MS_SAFE_FREE(g_blocked_path2);
1284 g_mutex_unlock(&blocked_mutex2);
1289 static int __msc_check_memory_status(uid_t uid)
1291 int ret = MS_MEDIA_ERR_NONE;
1292 double db_size = 0.0;
1294 /*check remain space*/
1295 ret = __msc_check_remain_space(uid);
1296 MS_DBG_RETV_IF(ret != MS_MEDIA_ERR_NONE, ret);
1299 ms_check_size_mediadb(uid, &db_size);
1300 if (db_size >= MEDIA_DB_SIZE_LIMIT_1) {
1301 MS_DBG_ERR("DB SIZE [%lf] REACH THE FIRST LIMIT [%lf]", db_size, MEDIA_DB_SIZE_LIMIT_1);
1302 return MS_MEDIA_ERR_DB_LIMIT_1;
1305 return MS_MEDIA_ERR_NONE;
1308 static int __msc_check_remain_space(uid_t uid)
1310 int err = MS_MEDIA_ERR_NONE;
1311 double free_space = 0.0;
1312 double db_size = 0.0;
1314 err = ms_get_remain_space(&free_space);
1315 if (err != MS_MEDIA_ERR_NONE) {
1316 MS_DBG_ERR("ms_get_remain_space failed");
1318 if (free_space < MEDIA_DB_SPACE_LIMIT) {
1319 MS_DBG_ERR("NOT ENOUGH SPACE WE DO NOT UPDATE MEDIA DB FREE SPACE [%lf]", free_space);
1321 ms_config_set_int(MS_DB_LIMIT, 0);
1323 return MS_MEDIA_ERR_NOT_ENOUGH_SPACE;
1327 err = ms_check_size_mediadb(uid, &db_size);
1328 if (err != MS_MEDIA_ERR_NONE) {
1329 MS_DBG_ERR("msc_check_dbsize failed");
1331 if (db_size >= MEDIA_DB_SIZE_LIMIT_2) {
1332 MS_DBG_ERR("REACH LIMIT DB SIZE [%lf]", db_size);
1334 MS_DBG_ERR("START REMOVE INVALID DATA");
1335 msc_cleanup_invalid_values(uid);
1336 MS_DBG_ERR("END REMOVE INVALID DATA");
1338 ms_check_size_mediadb(uid, &db_size);
1339 if (db_size >= MEDIA_DB_SIZE_LIMIT_2) {
1341 ms_config_set_int(MS_DB_LIMIT, 0);
1343 MS_DBG_ERR("DB IS FULL. CANNOT UPDATE[%lf]", db_size);
1344 return MS_MEDIA_ERR_DB_FULL_FAIL;
1349 return MS_MEDIA_ERR_NONE;
1352 void msc_init_scanner(void)
1354 if (!scan_queue2) scan_queue2 = g_async_queue_new();
1355 if (!reg_queue2) reg_queue2 = g_async_queue_new();
1356 if (!storage_queue2) storage_queue2 = g_async_queue_new();
1359 void msc_deinit_scanner(void)
1361 if (scan_queue2) g_async_queue_unref(scan_queue2);
1362 if (reg_queue2) g_async_queue_unref(reg_queue2);
1363 if (storage_queue2) g_async_queue_unref(storage_queue2);
1366 int msc_push_scan_request(ms_scan_type_e scan_type, ms_comm_msg_s *recv_msg)
1368 int ret = MS_MEDIA_ERR_NONE;
1370 switch (scan_type) {
1371 case MS_SCAN_STORAGE:
1372 g_async_queue_push(storage_queue2, recv_msg);
1374 case MS_SCAN_DIRECTORY:
1375 g_async_queue_push(scan_queue2, recv_msg);
1377 case MS_SCAN_REGISTER:
1378 g_async_queue_push(reg_queue2, recv_msg);
1381 MS_DBG_ERR("invalid parameter");
1382 ret = MS_MEDIA_ERR_INVALID_PARAMETER;
1389 void msc_send_power_off_request(void)
1391 ms_comm_msg_s *data = NULL;
1394 data = g_new0(ms_comm_msg_s, 1);
1396 data->pid = POWEROFF;
1397 msc_push_scan_request(MS_SCAN_DIRECTORY, data);
1401 data = g_new0(ms_comm_msg_s, 1);
1403 data->pid = POWEROFF;
1404 msc_push_scan_request(MS_SCAN_REGISTER, data);
1407 if (storage_queue2) {
1408 data = g_new0(ms_comm_msg_s, 1);
1410 data->pid = POWEROFF;
1411 msc_push_scan_request(MS_SCAN_STORAGE, data);
1415 void msc_remove_dir_scan_request(ms_comm_msg_s *recv_msg)
1417 char *cancel_path = recv_msg->msg;
1418 int pid = recv_msg->pid;
1420 int len = g_async_queue_length(scan_queue2);
1421 ms_comm_msg_s *msg = NULL;
1422 GAsyncQueue *temp_scan_queue = NULL;
1424 MS_DBG_WARN("scan_req_mutex2 is LOCKED");
1425 g_mutex_lock(&scan_req_mutex2);
1427 if (len <= 0 && g_directory_scan_processing2 == 0) {
1428 MS_DBG_WARN("Request is not stacked[%d]", len);
1429 goto END_REMOVE_REQUEST;
1432 MS_DBG_WARN("len == [%d] pid=[%d], cancel_path[%s]", len, pid, cancel_path);
1434 msc_set_cancel_scan_item(recv_msg->msg, recv_msg->pid);
1437 temp_scan_queue = g_async_queue_new();
1439 MS_DBG_WARN("start update scan_queue2");
1440 for (i = 0; i < len; i++) {
1441 /*create new queue to compare request*/
1442 msg = g_async_queue_pop(scan_queue2);
1443 MS_DBG_WARN("msg->msg[%.*s], msg->pid[%d]", MAX_MSG_SIZE, msg->msg, msg->pid);
1444 if ((strcmp(msg->msg, cancel_path) == 0) && (pid == msg->pid)) {
1445 msg->msg_type = MS_MSG_DIRECTORY_SCANNING_CANCEL;
1446 msc_send_result(MS_MEDIA_ERR_SCANNER_FORCE_STOP, msg);
1449 g_async_queue_push(temp_scan_queue, msg);
1453 len = g_async_queue_length(temp_scan_queue);
1455 for (; j < len; j++) {
1456 msg = g_async_queue_pop(temp_scan_queue);
1457 g_async_queue_push(scan_queue2, msg);
1459 g_async_queue_unref(temp_scan_queue);
1460 MS_DBG_WARN("end update scan_queue2");
1464 msc_set_cancel_extract_item(recv_msg->msg, recv_msg->pid);
1465 msc_remove_folder_extract_request(recv_msg);
1467 g_mutex_unlock(&scan_req_mutex2);
1468 MS_DBG_WARN("scan_req_mutex2 is UNLOCKED");