From be510ab4031494613ff9c77971bcc79e66e8f3fa Mon Sep 17 00:00:00 2001 From: "josh.merlin" Date: Fri, 27 Sep 2024 10:36:54 +0800 Subject: [PATCH] Close directory first to avoid errors in unmounting Change-Id: I788b1436392ec3916fe02eaa30c48932ec5c3332 --- src/scanner-v2/media-scanner-scan-v2.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/scanner-v2/media-scanner-scan-v2.c b/src/scanner-v2/media-scanner-scan-v2.c index 51869dc..e07782a 100644 --- a/src/scanner-v2/media-scanner-scan-v2.c +++ b/src/scanner-v2/media-scanner-scan-v2.c @@ -188,6 +188,8 @@ static int __msc_dir_scan_for_folder(sqlite3 *handle, const char *storage_id, ch bool is_recursive = (msg_type == MS_MSG_DIRECTORY_SCANNING); char *new_start_path = NULL; + bool is_stop_scan = false; + int scan_count = 0; int sleep_count = 0; @@ -356,9 +358,7 @@ static int __msc_dir_scan_for_folder(sqlite3 *handle, const char *storage_id, ch goto END_SCAN; STOP_SCAN: - MS_DBG_ERR("stop folder scan..."); - ms_set_folder_scan_status(storage_id, current_path, MS_DIR_SCAN_STOP, uid); - MS_SAFE_FREE(current_path); + is_stop_scan = true; END_SCAN: if (dir) { @@ -366,6 +366,12 @@ END_SCAN: dir = NULL; } + if(is_stop_scan) { + MS_DBG_ERR("stop folder scan..."); + ms_set_folder_scan_status(storage_id, current_path, MS_DIR_SCAN_STOP, uid); + MS_SAFE_FREE(current_path); + } + g_free(new_start_path); __msc_set_dir_scan_cur_path(NULL); @@ -391,6 +397,8 @@ static int __msc_dir_scan_for_storage(sqlite3 *handle, const char *storage_id, c int (*scan_function)(sqlite3 *, const char*, const char*, uid_t) = NULL; char *new_start_path = NULL; + bool is_stop_scan = false; + int scan_count = 0; int sleep_count = 0; @@ -578,9 +586,7 @@ NEXT_SCAN: goto END_SCAN; STOP_SCAN: - if (current_path != NULL) - ms_set_folder_scan_status(storage_id, current_path, MS_DIR_SCAN_STOP, uid); - MS_SAFE_FREE(current_path); + is_stop_scan = true; END_SCAN: if (dir) { @@ -588,6 +594,12 @@ END_SCAN: dir = NULL; } + if(is_stop_scan) { + if (current_path != NULL) + ms_set_folder_scan_status(storage_id, current_path, MS_DIR_SCAN_STOP, uid); + MS_SAFE_FREE(current_path); + } + g_free(new_start_path); __msc_set_storage_scan_cur_path(NULL); g_ptr_array_free(dir_array, TRUE); -- 2.7.4