update scanner v2 06/56706/3
authorMinje Ahn <minje.ahn@samsung.com>
Tue, 12 Jan 2016 07:43:56 +0000 (16:43 +0900)
committerMinje Ahn <minje.ahn@samsung.com>
Mon, 18 Jan 2016 07:51:31 +0000 (16:51 +0900)
Change-Id: I6f789ecaab79756b47e3aac6c502d8c519997e40
Signed-off-by: Minje Ahn <minje.ahn@samsung.com>
16 files changed:
lib/include/media-server-ipc.h
lib/include/media-util-register.h
lib/media-util-register.c
packaging/media-server.spec
src/common/include/media-common-db-svc.h
src/common/include/media-common-types.h
src/common/media-common-db-svc.c
src/mediadb-update.c
src/scanner-v2/include/media-scanner-socket-v2.h
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/scanner/media-scanner-scan.c
src/server/media-server-main.c
src/server/media-server-scanner.c
src/server/media-server-socket.c

index b638f06..6d05b7b 100755 (executable)
@@ -61,6 +61,9 @@ typedef enum{
        MS_MSG_DIRECTORY_SCANNING_CANCEL,       /**< Request cancel directory scan*/
        MS_MSG_STORAGE_SCANNER_COMPLETE,        /**< Storage Scanner complete */
        MS_MSG_DIRECTORY_SCANNER_COMPLETE,      /**< Directory Scanner complete */
+       MS_MSG_SCANNER_PARTIAL,
+       MS_MSG_SCANNER_COMPLETE,
+       MS_MSG_EXTRACTOR_COMPLETE,
        MS_MSG_MAX                                                      /**< Invalid msg type */
 }ms_msg_type_e;
 
index 283e6a5..b15158c 100755 (executable)
@@ -33,6 +33,9 @@ typedef enum
 {
        MEDIA_DIRECTORY_SCAN = 0,
        MEDIA_FILES_REGISTER,
+       MEDIA_REQUEST_SCAN_PARTIAL,
+       MEDIA_REQUEST_SCAN_COMPLETE,
+       MEDIA_REQUEST_EXTRACT_COMPLETE,
 } media_request_type_e;
 
 typedef struct
index 0d12c61..9f55549 100755 (executable)
@@ -191,10 +191,22 @@ gboolean _read_socket(GIOChannel *src, GIOCondition condition, gpointer data)
        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;
-               MSAPI_DBG("complete_path :%d", req_result.complete_path);
+               MSAPI_DBG("complete_path :%s", req_result.complete_path);
        } else if (recv_msg.msg_type == MS_MSG_SCANNER_BULK_RESULT) {
                req_result.complete_path = strndup(recv_msg.msg, recv_msg.msg_size);
                req_result.request_type = MEDIA_FILES_REGISTER;
+       } else if (recv_msg.msg_type == MS_MSG_SCANNER_COMPLETE) {
+               req_result.complete_path = strndup(recv_msg.msg, recv_msg.msg_size);
+               req_result.request_type = MEDIA_REQUEST_SCAN_COMPLETE;
+       } else if (recv_msg.msg_type == MS_MSG_SCANNER_PARTIAL) {
+               req_result.complete_path = strndup(recv_msg.msg, recv_msg.msg_size);
+               req_result.request_type = MEDIA_REQUEST_SCAN_PARTIAL;
+       } else if (recv_msg.msg_type == MS_MSG_EXTRACTOR_COMPLETE) {
+               req_result.complete_path = strndup(recv_msg.msg, recv_msg.msg_size);
+               req_result.request_type = MEDIA_REQUEST_EXTRACT_COMPLETE;
+       } else {
+               MSAPI_DBG("The message is invalid!");
+               return FALSE;
        }
 
        MSAPI_DBG("pid :%d", req_result.pid);
@@ -202,42 +214,40 @@ gboolean _read_socket(GIOChannel *src, GIOCondition condition, gpointer data)
        MSAPI_DBG("request_type :%d", req_result.request_type);
 
 ERROR:
-       if (req_result.complete_path == NULL) {
-               MSAPI_DBG_ERR("complete_path is NULL");
-               return TRUE;
-       }
-        /*NEED MUTEX*/
-        g_mutex_lock(&scan_req_mutex);
-        if (req_list != NULL) {
-               int i = 0;
-               int list_len = req_list->len;
-
-               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) {
-                               MSAPI_DBG("FIND REQUEST [%s]", req_data->req_path);
-                               g_array_remove_index(req_list, i);
-
-                               source = ((media_callback_data *)data)->source;
-                               user_callback = ((media_callback_data *)data)->user_callback;
-                               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);
-
-                               MS_SAFE_FREE(req_result.complete_path);
-
-                               /*close an IO channel*/
-                               g_io_channel_shutdown(src, FALSE, NULL);
-                               g_io_channel_unref(src);
-
-                               g_source_destroy(source);
-                               close(sockfd);
-                               if (sock_path != NULL) {
-                                       MSAPI_DBG("delete path :%s", sock_path);
-                                       unlink(sock_path);
-                                       MS_SAFE_FREE(sock_path);
+       source = ((media_callback_data *)data)->source;
+       user_callback = ((media_callback_data *)data)->user_callback;
+       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) {
+               /*NEED MUTEX*/
+               g_mutex_lock(&scan_req_mutex);
+               if (req_list != NULL) {
+                       int i = 0;
+                       int list_len = req_list->len;
+
+                       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) {
+                                       MSAPI_DBG("FIND REQUEST [%s]", req_data->req_path);
+                                       g_array_remove_index(req_list, i);
+
+                                       /*close an IO channel*/
+                                       g_io_channel_shutdown(src, FALSE, NULL);
+                                       g_io_channel_unref(src);
+
+                                       g_source_destroy(source);
+                                       close(sockfd);
+                                       if (sock_path != NULL) {
+                                               MSAPI_DBG("delete path :%s", sock_path);
+                                               unlink(sock_path);
+                                               MS_SAFE_FREE(sock_path);
+                                       }
                                }
 
                                MSAPI_DBG("REMOVE OK");
@@ -245,10 +255,11 @@ ERROR:
                                break;
                        }
                }
+               g_mutex_unlock(&scan_req_mutex);
+               MS_SAFE_FREE(data);
        }
 
-       g_mutex_unlock(&scan_req_mutex);
-       MS_SAFE_FREE(data);
+       MS_SAFE_FREE(req_result.complete_path);
 
        return TRUE;
 }
index 0b7f883..071c4c1 100755 (executable)
@@ -1,6 +1,6 @@
 Name:       media-server
 Summary:    A server for media content management
-Version:    0.2.66
+Version:    0.2.67
 Release:    0
 Group:      Multimedia/Service
 License:    Apache-2.0
index 4ad9961..161d582 100755 (executable)
@@ -78,13 +78,20 @@ typedef int (*UPDATE_FOLDER_TIME)(void *, const char *, const char *, uid_t, cha
 typedef int (*GET_STORAGE_ID)(void *, const char *, char *, char **);
 typedef int (*GET_STORAGE_SCAN_STATUS)(void *, const char *, int *, char **);
 typedef int (*SET_STORAGE_SCAN_STATUS)(void *, const char *, int, uid_t, char **);
+typedef int (*GET_STORAGE_LIST)(void *, char ***, char ***, int **, int *, char **);
 typedef int (*INSERT_FOLDER)(void*, const char*, const char*, int, uid_t, char **);
 typedef int (*DELETE_INVALID_FOLDER)(void*, const char*, uid_t, char **);
 typedef int (*SET_FOLDER_VALIDITY)(void*, const char*, const char*, int, bool, uid_t, char **);
 typedef int (*INSERT_FOLDER_BEGIN)(void *, int, char**);
 typedef int (*INSERT_FOLDER_END)(void*, uid_t, char**);
 typedef int (*INSERT_ITEM_SCAN)(void*, const char*, const char*, int, uid_t, char **);
-typedef int (*UPDATE_ITEM_EXTRACT)(void*, const char*, int, int, uid_t, const char*, char **);
+typedef int (*UPDATE_ITEM_EXTRACT)(void*, const char*, int, int, uid_t, const char*, int, char **);
+typedef int (*GET_FOLDER_SCAN_STATUS)(void *, const char *, const char *, int *, char **);
+typedef int (*SET_FOLDER_SCAN_STATUS)(void *, const char *, const char *, int, uid_t, char **);
+typedef int (*CHECK_FOLDER_MODIFIED)(void *, const char *, const char *, bool *, char **);
+typedef int (*GET_NULL_SCAN_FOLDER_LIST)(void *, const char *, const char *, char ***, int *, char **);
+typedef int (*CHANGE_VALIDITY_ITEM_BATCH)(void *, const char *, const char *, int, int, uid_t, char **);
+//typedef int (*GET_SCAN_DONE_ITEMS)(void *, const char *, const char *, int, int *, char **);
 
 typedef int (*CHECK_DB)(void*, bool*, uid_t, char **);
 typedef int (*GET_UUID)(void *, char **, char **);
@@ -113,7 +120,7 @@ int ms_connect_db(void ***handle, uid_t uid);
 int ms_disconnect_db(void ***handle);
 int ms_validate_item(void **handle, const char *storage_id, const char *path, uid_t uid);
 int ms_insert_item_batch(void **handle, const char *storage_id, const char *path, uid_t uid);
-int ms_insert_item_pass2(void **handle, const char *storage_id, const char *path, int scan_type, uid_t uid);
+int ms_insert_item_pass2(void **handle, const char *storage_id, int storage_type, const char *path, int scan_type, int burst, uid_t uid);
 int ms_insert_item_immediately(void **handle, const char *storage_id, const char *path, uid_t uid);
 int ms_insert_burst_item(void **handle, const char *storage_id, const char *path, uid_t uid);
 bool ms_delete_all_items(void **handle, const char *storage_id, ms_storage_type_t store_type, uid_t uid);
@@ -128,11 +135,18 @@ int ms_update_folder_time(void **handle, const char *storage_id, char *folder_pa
 int ms_get_storage_id(void **handle, const char *path, char *storage_id);
 int ms_get_storage_scan_status(void **handle, char *storage_id, media_scan_status_e *scan_status);
 int ms_set_storage_scan_status(void **handle, char *storage_id, media_scan_status_e scan_status, uid_t uid);
+int ms_get_storage_list(void **handle, GArray **storage_array);
 int ms_insert_folder(void **handle, const char *storage_id, const char *path, uid_t uid);
 int ms_delete_invalid_folder(void **handle, const char *storage_id, uid_t uid);
 int ms_set_folder_validity(void **handle, const char *storage_id, const char *start_path, int validity, bool is_recursive, uid_t uid);
-int ms_scan_item_batch(void **handle, const char *storage_id, const char *path, uid_t uid);
-int ms_scan_validate_item(void **handle, const char *storage_id, const char *path, uid_t uid);
+int ms_scan_item_batch(void **handle, const char *storage_id, const char *path, uid_t uid, int *insert_count_for_partial, int *set_count_for_partial);
+int ms_scan_validate_item(void **handle, const char *storage_id, const char *path, uid_t uid, int *insert_count_for_partial, int *set_count_for_partial);
+int ms_get_folder_scan_status(void **handle, const char *storage_id, const char *path, int *scan_status);
+int ms_set_folder_scan_status(void **handle, const char *storage_id, const char *path, int scan_status, uid_t uid);
+int ms_check_folder_modified(void **handle, const char *path, const char *storage_id, bool *modified);
+int ms_get_null_scan_folder_list(void **handle, const char *stroage_id, const char *path, GArray **dir_array);
+int ms_change_validity_item_batch(void **handle, const char *storage_id, const char *path, int des_validity, int src_validity, uid_t uid);
+//int ms_get_scan_done_items(void **handle, const char *storage_id, const char *path, int validity, int *count);
 
 int ms_check_db_upgrade(void **handle, bool *need_full_scan, uid_t uid);
 int ms_genarate_uuid(void **handle, char **uuid);
index e1413d2..c9cf386 100755 (executable)
@@ -34,6 +34,8 @@
 
 #define MS_VALIND 1
 #define MS_INVALID 0
+#define MS_VALIND_V2 2
+
 #define MS_RECURSIVE 1
 #define MS_NON_RECURSIVE 0
 
@@ -118,6 +120,18 @@ typedef enum {
        MS_STORAGE_SCAN_COMPLETE,               /**< Complete scanning*/
 }ms_storage_scan_status_e;
 
+/*use for MS_DIR_SCANNER_STATUS */
+typedef enum {
+       MS_DIR_SCAN_NONE                = 0,                    /**< Media Scanner not detect storage yet*/
+       MS_DIR_SCAN_PREPARE                             = 1,                    /**< Media Scanner detect storage but not scanning yet*/
+       MS_DIR_SCAN_PROCESSING                  = 2,                    /**< Media Scanner Start Scanning storage*/
+       MS_DIR_SCAN_STOP                                = 3,                    /**< Stop scanning storage*/
+       MS_DIR_SCAN_DONE                                = 4,                    /**< Scanning Done but need to extract metadata*/
+       MS_DIR_SCAN_META_PROCESSING             = 5,                    /**< Scanning Done and start to extract metadata*/
+       MS_DIR_SCAN_META_STOP                   = 6,                    /**< Stop extract metadata*/
+       MS_DIR_SCAN_COMPLETE                    = 7,                    /**< Complete scanning*/
+}ms_dir_scan_status_e;
+
 typedef enum{
        MEDIA_SCAN_PREPARE              = 0,    /**< Prepare scanning*/
        MEDIA_SCAN_PROCESSING   = 1,    /**< Process scanning*/
index 16583c3..59067a5 100755 (executable)
@@ -70,11 +70,17 @@ enum func_list {
        eGET_STORAGE_ID,
        eGET_STORAGE_SCAN_STATUS,
        eSET_STORAGE_SCAN_STATUS,
+       eGET_STORAGE_LIST,
        eINSERT_FOLDER,
        eDELETE_INVALID_FOLDER,
        eSET_FOLDER_VALIDITY,
        eINSERT_FOLDER_BEGIN,
        eINSERT_FOLDER_END,
+       eGET_FOLDER_SCAN_STATUS,
+       eSET_FOLDER_SCAN_STATUS,
+       eCHECK_FOLDER_MODIFIED,
+       eGET_NULL_SCAN_FOLDER_LIST,
+       eCHANGE_VALIDITY_ITEM_BATCH,
        eCHECK_DB,
        eGET_UUID,
        eGET_MMC_INFO,
@@ -178,11 +184,17 @@ int ms_load_functions(void)
                "get_storage_id",
                "get_storage_scan_status",
                "set_storage_scan_status",
+               "get_storage_list",
                "insert_folder",
                "delete_invalid_folder",
                "set_folder_validity",
                "insert_folder_begin",
                "insert_folder_end",
+               "get_folder_scan_status",
+               "set_folder_scan_status",
+               "check_folder_modified",
+               "get_null_scan_folder_list",
+               "change_validity_item_batch",
                "check_db",
                "get_uuid",
                "get_mmc_info",
@@ -436,7 +448,7 @@ int ms_validate_item(void **handle, const char *storage_id, const char *path, ui
        return res;
 }
 
-int ms_scan_validate_item(void **handle, const char *storage_id, const char *path, uid_t uid)
+int ms_scan_validate_item(void **handle, const char *storage_id, const char *path, uid_t uid, int *insert_count_for_partial, int *set_count_for_partial)
 {
        int lib_index;
        int res = MS_MEDIA_ERR_NONE;
@@ -449,11 +461,12 @@ int ms_scan_validate_item(void **handle, const char *storage_id, const char *pat
                ret = ((CHECK_ITEM_EXIST)func_array[lib_index][eEXIST])(handle[lib_index], storage_id, path, &modified, &err_msg); /*dlopen*/
                if (ret != 0) {
                        MS_SAFE_FREE(err_msg);
-                       ret = ms_scan_item_batch(handle, storage_id, path, uid);
+                       ret = ms_scan_item_batch(handle, storage_id, path, uid, insert_count_for_partial, set_count_for_partial);
                        if (ret != 0) {
                                res = MS_MEDIA_ERR_DB_INSERT_FAIL;
                        } else {
                                insert_count++;
+                               (*insert_count_for_partial)++;
                        }
                } else {
                        if (modified == FALSE) {
@@ -463,6 +476,8 @@ int ms_scan_validate_item(void **handle, const char *storage_id, const char *pat
                                        MS_DBG_ERR("error : %s [%s] %s", g_array_index(so_array, char*, lib_index), err_msg, path);
                                        MS_SAFE_FREE(err_msg);
                                        res = MS_MEDIA_ERR_DB_UPDATE_FAIL;
+                               } else {
+                                       (*set_count_for_partial)++;
                                }
                        } else {
                                /* the file has same name but it is changed, so we have to update DB */
@@ -472,11 +487,12 @@ int ms_scan_validate_item(void **handle, const char *storage_id, const char *pat
                                        MS_SAFE_FREE(err_msg);
                                        res = MS_MEDIA_ERR_DB_DELETE_FAIL;
                                } else {
-                                       ret = ms_scan_item_batch(handle, storage_id, path, uid);
+                                       ret = ms_scan_item_batch(handle, storage_id, path, uid, insert_count_for_partial, set_count_for_partial);
                                        if (ret != 0) {
                                                res = MS_MEDIA_ERR_DB_INSERT_FAIL;
                                        } else {
                                                insert_count++;
+                                               (*insert_count_for_partial)++;
                                        }
                                }
                        }
@@ -529,7 +545,7 @@ int ms_insert_item_batch(void **handle, const char* storage_id, const char *path
        return res;
 }
 
-int ms_scan_item_batch(void **handle, const char* storage_id, const char *path, uid_t uid)
+int ms_scan_item_batch(void **handle, const char* storage_id, const char *path, uid_t uid, int *insert_count_for_partial, int *set_count_for_partial)
 {
        int lib_index;
        int res = MS_MEDIA_ERR_NONE;
@@ -553,18 +569,18 @@ int ms_scan_item_batch(void **handle, const char* storage_id, const char *path,
        return res;
 }
 
-int ms_insert_item_pass2(void **handle, const char* storage_id, const char *path, int scan_type, uid_t uid)
+int ms_insert_item_pass2(void **handle, const char* storage_id, int storage_type, const char *path, int scan_type, int burst, uid_t uid)
 {
        int lib_index;
        int res = MS_MEDIA_ERR_NONE;
        int ret;
        char *err_msg = NULL;
-       ms_storage_type_t storage_type;
+       //ms_storage_type_t storage_type;
 
-       storage_type = ms_get_storage_type_by_full(path, uid);
+       //storage_type = ms_get_storage_type_by_full(path, uid);
 
        for (lib_index = 0; lib_index < lib_num; lib_index++) {
-               ret = ((UPDATE_ITEM_EXTRACT)func_array[lib_index][eUPDATE_EXTRACT])(handle[lib_index], storage_id, storage_type, scan_type, uid, path, &err_msg); /*dlopen*/
+               ret = ((UPDATE_ITEM_EXTRACT)func_array[lib_index][eUPDATE_EXTRACT])(handle[lib_index], storage_id, storage_type, scan_type, uid, path, burst, &err_msg); /*dlopen*/
                if (ret != 0) {
                        MS_DBG_ERR("error : %s [%s] %s", g_array_index(so_array, char*, lib_index), err_msg, path);
                        MS_SAFE_FREE(err_msg);
@@ -893,6 +909,52 @@ int ms_set_storage_scan_status(void **handle, char *storage_id, media_scan_statu
        return res;
 }
 
+int ms_get_storage_list(void **handle, GArray **storage_array)
+{
+       int lib_index;
+       int ret;
+       char *err_msg = NULL;
+
+       char **storage_list = NULL;
+       char **storage_id_list = NULL;
+       int *scan_status = NULL;
+       int count = 0;
+       int i = 0;
+
+       ms_stg_info_s* stg_info = NULL;
+
+       for (lib_index = 0; lib_index < lib_num; lib_index++) {
+               ret = ((GET_STORAGE_LIST)func_array[lib_index][eGET_STORAGE_LIST])(handle[lib_index], &storage_list, &storage_id_list, &scan_status, &count, &err_msg); /*dlopen*/
+               if (ret != 0) {
+                       MS_DBG_ERR("error : %s [%s]", g_array_index(so_array, char*, lib_index), err_msg);
+                       MS_SAFE_FREE(err_msg);
+                       return MS_MEDIA_ERR_INTERNAL;
+               }
+       }
+
+       MS_DBG_ERR("OK");
+
+       *storage_array = g_array_new(FALSE, FALSE, sizeof(ms_stg_info_s*));
+       if (count != 0) {
+               for(i = 0; i < count; i ++) {
+                       stg_info = malloc(sizeof(ms_stg_info_s));
+                       stg_info->stg_path = strdup(storage_list[i]);
+                       stg_info->storage_id = strdup(storage_id_list[i]);
+                       stg_info->scan_status = scan_status[i];
+                       g_array_append_val(*storage_array, stg_info);
+                       MS_SAFE_FREE(storage_list[i]);
+                       MS_SAFE_FREE(storage_id_list[i]);
+                       MS_DBG("%d get path : %s, %s", i, stg_info->stg_path, stg_info->storage_id);
+               }
+       }
+
+       MS_SAFE_FREE(storage_list);
+       MS_SAFE_FREE(storage_id_list);
+       MS_SAFE_FREE(scan_status);
+
+       return MS_MEDIA_ERR_NONE;
+}
+
 int ms_insert_folder(void **handle, const char *storage_id, const char *path, uid_t uid)
 {
        int lib_index;
@@ -1393,3 +1455,149 @@ void ms_update_end(void **handle, uid_t uid)
                }
        }
 }
+
+int ms_get_folder_scan_status(void **handle, const char *storage_id, const char *path, int *scan_status)
+{
+       int lib_index;
+       int res = MS_MEDIA_ERR_NONE;
+       int ret;
+       char *err_msg = NULL;
+       int status = 0;
+
+       //MS_DBG("");
+       for (lib_index = 0; lib_index < lib_num; lib_index++) {
+               ret = ((GET_FOLDER_SCAN_STATUS)func_array[lib_index][eGET_FOLDER_SCAN_STATUS])(handle[lib_index], storage_id, path, &status, &err_msg); /*dlopen*/
+               if (ret != 0) {
+                       MS_DBG_ERR("error : %s [%s]", g_array_index(so_array, char*, lib_index), err_msg);
+                       MS_SAFE_FREE(err_msg);
+                       res = MS_MEDIA_ERR_DB_UPDATE_FAIL;
+               } else {
+                       *scan_status = status;
+               }
+       }
+
+       MS_DBG("OK path = [%s],  scan_status = [%d]", path, *scan_status);
+
+       return res;
+}
+
+int ms_set_folder_scan_status(void **handle, const char *storage_id, const char *path, int scan_status, uid_t uid)
+{
+       int lib_index;
+       int res = MS_MEDIA_ERR_NONE;
+       int ret;
+       char *err_msg = NULL;
+       int status = scan_status;
+
+       //MS_DBG("");
+       for (lib_index = 0; lib_index < lib_num; lib_index++) {
+               ret = ((SET_FOLDER_SCAN_STATUS)func_array[lib_index][eSET_FOLDER_SCAN_STATUS])(handle[lib_index], storage_id, path, status, uid, &err_msg); /*dlopen*/
+               if (ret != 0) {
+                       MS_DBG_ERR("error : %s [%s]", g_array_index(so_array, char*, lib_index), err_msg);
+                       MS_SAFE_FREE(err_msg);
+                       res = MS_MEDIA_ERR_DB_UPDATE_FAIL;
+               }
+       }
+
+       MS_DBG("OK path = [%s],  scan_status = [%d]", path, scan_status);
+
+       return res;
+}
+
+int ms_check_folder_modified(void **handle, const char *path, const char *storage_id, bool *modified)
+{
+       MS_DBG("path = [%s], storage_id = [%s]", path, storage_id);
+
+       int lib_index;
+       int ret;
+       char *err_msg = NULL;
+
+       for (lib_index = 0; lib_index < lib_num; lib_index++) {
+               ret = ((CHECK_FOLDER_MODIFIED)func_array[lib_index][eCHECK_FOLDER_MODIFIED])(handle[lib_index], path, storage_id, modified, &err_msg); /*dlopen*/
+               if (ret != 0) {
+                       MS_DBG_ERR("error : %s [%s]", g_array_index(so_array, char*, lib_index), err_msg);
+                       MS_SAFE_FREE(err_msg);
+                       return MS_MEDIA_ERR_INTERNAL;
+               }
+       }
+
+       return MS_MEDIA_ERR_NONE;
+}
+
+int ms_get_null_scan_folder_list(void **handle, const char *stroage_id, const char *path, GArray **dir_array)
+{
+       //MS_DBG("folder stroage_id: %s", stroage_id);
+
+       int lib_index;
+       int ret;
+       char *err_msg = NULL;
+       char **folder_list = NULL;
+       char *sub_path = NULL;
+       int count = 0;
+       int i = 0;
+
+       for (lib_index = 0; lib_index < lib_num; lib_index++) {
+               ret = ((GET_NULL_SCAN_FOLDER_LIST)func_array[lib_index][eGET_NULL_SCAN_FOLDER_LIST])(handle[lib_index], stroage_id, path, &folder_list, &count, &err_msg); /*dlopen*/
+               if (ret != 0) {
+                       MS_DBG_ERR("error : %s [%s]", g_array_index(so_array, char*, lib_index), err_msg);
+                       MS_SAFE_FREE(err_msg);
+                       return MS_MEDIA_ERR_INTERNAL;
+               }
+       }
+
+       //MS_DBG("GET_NULL_SCAN_FOLDER_LIST OK");
+
+       *dir_array = g_array_new(FALSE, FALSE, sizeof (char*));
+       if (count != 0) {
+               for(i = 0; i < count; i ++) {
+                       sub_path = strdup(folder_list[i]);
+                       g_array_append_val(*dir_array, sub_path);
+                       MS_SAFE_FREE(folder_list[i]);
+               }
+       }
+
+       MS_SAFE_FREE(folder_list);
+
+       return MS_MEDIA_ERR_NONE;
+}
+
+int ms_change_validity_item_batch(void **handle, const char *storage_id, const char *path, int des_validity, int src_validity, uid_t uid)
+{
+       int lib_index;
+       int res = MS_MEDIA_ERR_NONE;
+       int ret;
+       char *err_msg = NULL;
+
+       for (lib_index = 0; lib_index < lib_num; lib_index++) {
+               ret = ((CHANGE_VALIDITY_ITEM_BATCH)func_array[lib_index][eCHANGE_VALIDITY_ITEM_BATCH])(handle[lib_index], storage_id, path, des_validity, src_validity, uid, &err_msg); /*dlopen*/
+               if (ret != 0) {
+                       MS_DBG_ERR("error : %s [%s] %s", g_array_index(so_array, char*, lib_index), err_msg, storage_id);
+                       MS_SAFE_FREE(err_msg);
+                       res = MS_MEDIA_ERR_DB_INSERT_FAIL;
+               }
+       }
+
+       return res;
+}
+
+#if 0
+int ms_get_scan_done_items(void **handle, const char *storage_id, const char *path, int validity, int *count)
+{
+       int lib_index;
+       int res = MS_MEDIA_ERR_NONE;
+       int ret;
+       char *err_msg = NULL;
+
+       for (lib_index = 0; lib_index < lib_num; lib_index++) {
+               ret = ((GET_SCAN_DONE_ITEMS)func_array[lib_index][eGET_SCAN_DONE_ITEMS])(handle[lib_index], storage_id, path, validity, count, &err_msg); /*dlopen*/
+               if (ret != 0) {
+                       MS_DBG_ERR("error : %s [%s] %s", g_array_index(so_array, char*, lib_index), err_msg, storage_id);
+                       MS_SAFE_FREE(err_msg);
+                       res = MS_MEDIA_ERR_DB_INSERT_FAIL;
+               }
+       }
+
+       return res;
+}
+#endif
+
index 92ed785..b4364f2 100755 (executable)
@@ -43,9 +43,10 @@ int (*svc_get_storage_id)            (void * handle, const char *path, char *storage_id, u
 
 void callback(media_request_result_s * result, void *user_data)
 {
-       printf("db updating done\n");
-
-       g_main_loop_quit(mainloop);
+       if (result->result != MEDIA_REQUEST_SCAN_PARTIAL) {
+               printf("db updating done\n");
+               g_main_loop_quit(mainloop);
+       }
 }
 
 void print_help()
index 15434bf..9b68c20 100755 (executable)
@@ -26,9 +26,8 @@
 #include "media-server-ipc.h"
 
 gboolean msc_receive_request(GIOChannel *src, GIOCondition condition, gpointer data);
-
 int msc_send_ready(void);
-
 int msc_send_result(int result, ms_comm_msg_s *scan_data);
+int msc_send_result_partial(int result, ms_msg_type_e msg_type, int pid, char *msg);
 
 #endif /*_MEDIA_SCANNER_SOCKET_V2_H_*/
index 5d4034d..9801911 100755 (executable)
@@ -54,8 +54,9 @@ int stg_extract_status;
 
 GCond extract_data_cond;
 GMutex extract_data_mutex;
-
-
+#define VCONFKEY_PRIVATE_EXTRACTSTATUS "db/private/extractstatus"
+#define LAST_EVENT 1
+#define NORMAL_EVENT 0
 #ifdef FMS_PERF
 extern struct timeval g_mmc_start_time;
 extern struct timeval g_mmc_end_time;
@@ -66,8 +67,7 @@ static int __msc_set_storage_extract_status(ms_storage_scan_status_e status);
 static int __msc_get_storage_extract_status(ms_storage_scan_status_e *status);
 static int __msc_resume_extract();
 static int __msc_pause_extract();
-static int __msc_extract_set_db_status(ms_db_status_type_t status, ms_storage_type_t storage_type);
-static int __msc_extract_set_power_mode(ms_db_status_type_t status);
+static int __msc_extract_set_db_status(ms_db_status_type_t status);
 
 int msc_init_extract_thread()
 {
@@ -160,11 +160,10 @@ gboolean msc_folder_extract_thread(void *data)
                }
 
                /*insert data into media db */
-               ret = ms_insert_item_pass2(handle, extract_data->storage_id, update_path, scan_type, extract_data->uid);
-               msc_del_extract_cancel_path();
+               int end_flag = extract_data->result ? LAST_EVENT : NORMAL_EVENT;
 
-               /*call for bundle commit*/
-               //__msc_bacth_commit_disable(handle, TRUE, TRUE, extract_data->storage_id, ret);
+               ret = ms_insert_item_pass2(handle, extract_data->storage_id, storage_type, update_path, scan_type, end_flag, extract_data->uid);
+               msc_del_extract_cancel_path();
 
 NEXT :
                msc_get_power_status(&power_off_status);
@@ -177,6 +176,7 @@ NEXT :
                malloc_trim(0);
 
                if (extract_data->result) {
+                       extract_data->msg_type = MS_MSG_EXTRACTOR_COMPLETE;
                        msc_send_result(ret, extract_data);
                }
 
@@ -256,8 +256,7 @@ gboolean msc_storage_extract_thread(void *data)
                MS_DBG_ERR("extract storage_id is [%s], path [%s]", extract_data->storage_id, update_path);
 
                ms_set_storage_scan_status(handle, extract_data->storage_id, MEDIA_EXTRACT_PROCESSING, extract_data->uid);
-               storage_type = ms_get_storage_type_by_full(extract_data->msg, extract_data->uid);
-               __msc_extract_set_db_status(MS_DB_UPDATING, storage_type);
+               __msc_extract_set_db_status(MS_DB_UPDATING);
 
                ret = __msc_check_extract_stop_status(extract_data->msg_type, storage_type, update_path);
                if (ret == MS_MEDIA_ERR_SCANNER_FORCE_STOP) {
@@ -265,11 +264,12 @@ gboolean msc_storage_extract_thread(void *data)
                        goto NEXT;
                }
 
-               /*extract meta*/
-               ret = ms_insert_item_pass2(handle, extract_data->storage_id, update_path, scan_type, extract_data->uid);
 
                storage_type = ms_get_storage_type_by_full(extract_data->msg, extract_data->uid);
-               //update_path = strndup(extract_data->msg, extract_data->msg_size);
+
+               /*extract meta*/
+               int end_flag = extract_data->result ? LAST_EVENT : NORMAL_EVENT;
+               ret = ms_insert_item_pass2(handle, extract_data->storage_id, storage_type, update_path, scan_type, end_flag, extract_data->uid);
 
                msc_del_extract_blocked_path();
 
@@ -280,15 +280,14 @@ gboolean msc_storage_extract_thread(void *data)
                if (ret == MS_MEDIA_ERR_SCANNER_FORCE_STOP) {
                        ms_set_storage_scan_status(handle, extract_data->storage_id, MEDIA_EXTRACT_STOP, extract_data->uid);
                        __msc_set_storage_extract_status(MS_STORAGE_SCAN_META_STOP);
-                       /*set vconf key mmc loading for indicator */
-                       __msc_extract_set_db_status(MS_DB_STOPPED, storage_type);
+                       /* set vconf key db extract status */
+                       __msc_extract_set_db_status(MS_DB_STOPPED);
                } else if (extract_data->result == TRUE) {
                        MS_DBG_ERR("extract_data->result == TRUE, MS_STORAGE_SCAN_COMPLETE");
                        ms_set_storage_scan_status(handle, extract_data->storage_id, MEDIA_EXTRACT_COMPLETE, extract_data->uid);
                        __msc_set_storage_extract_status(MS_STORAGE_SCAN_COMPLETE);
-                       ms_delete_invalid_items(handle, extract_data->storage_id, storage_type, extract_data->uid);
-                       /*set vconf key mmc loading for indicator */
-                       __msc_extract_set_db_status(MS_DB_UPDATED, storage_type);
+                       /* set vconf key db extract status */
+                       __msc_extract_set_db_status(MS_DB_UPDATED);
                }
 
 #if 0
@@ -361,6 +360,7 @@ NEXT:
                malloc_trim(0);
 
                if (extract_data->result) {
+                       extract_data->msg_type = MS_MSG_EXTRACTOR_COMPLETE;
                        msc_send_result(ret, extract_data);
                }
 
@@ -421,7 +421,7 @@ int msc_remove_extract_request(const ms_comm_msg_s *recv_msg)
        MS_DBG_WARN("exactor_req_mutex is LOCKED");
        g_mutex_lock(&extract_req_mutex);
 
-       if (len == 0) {
+       if (len <= 0) {
                MS_DBG_ERR("Request is not stacked");
                goto END_REMOVE_REQUEST;
        }
@@ -437,8 +437,15 @@ int msc_remove_extract_request(const ms_comm_msg_s *recv_msg)
                        g_async_queue_push(temp_queue, GINT_TO_POINTER(msg));
                }
        }
-       g_async_queue_unref(storage_extract_queue);
-       storage_extract_queue = temp_queue;
+       len = g_async_queue_length(temp_queue);
+       int j=0;
+       for (; j <len; j++) {
+               msg = g_async_queue_pop(temp_queue);
+               if (msg) {
+                       g_async_queue_push(storage_extract_queue, GINT_TO_POINTER(msg));
+               }
+       }
+       g_async_queue_unref (temp_queue);
 
 END_REMOVE_REQUEST:
        g_mutex_unlock(&extract_req_mutex);
@@ -616,77 +623,14 @@ static int __msc_pause_extract()
        return MS_MEDIA_ERR_NONE;
 }
 
-static int __msc_extract_set_db_status(ms_db_status_type_t status, ms_storage_type_t storage_type)
+static int __msc_extract_set_db_status(ms_db_status_type_t status)
 {
        int res = MS_MEDIA_ERR_NONE;
-       int err = 0;
-
-       if (status == MS_DB_UPDATING) {
-               if (!ms_config_set_int(VCONFKEY_FILEMANAGER_DB_STATUS, VCONFKEY_FILEMANAGER_DB_UPDATING)) {
-                       res = MS_MEDIA_ERR_VCONF_SET_FAIL;
-                       MS_DBG_ERR("ms_config_set_int failed");
-               }
-
-               if (storage_type == MS_STORAGE_EXTERNAL) {
-                       if (!ms_config_set_int(VCONFKEY_FILEMANAGER_MMC_STATUS, VCONFKEY_FILEMANAGER_MMC_LOADING)) {
-                               res = MS_MEDIA_ERR_VCONF_SET_FAIL;
-                               MS_DBG_ERR("ms_config_set_int failed");
-                       }
-               }
-       } else if (status == MS_DB_UPDATED) {
-               if (!ms_config_set_int(VCONFKEY_FILEMANAGER_DB_STATUS, VCONFKEY_FILEMANAGER_DB_UPDATED)) {
-                       res = MS_MEDIA_ERR_VCONF_SET_FAIL;
-                       MS_DBG_ERR("ms_config_set_int failed");
-               }
-
-               if (storage_type == MS_STORAGE_EXTERNAL) {
-                       if (!ms_config_set_int(VCONFKEY_FILEMANAGER_MMC_STATUS, VCONFKEY_FILEMANAGER_MMC_LOADED)) {
-                               res = MS_MEDIA_ERR_VCONF_SET_FAIL;
-                               MS_DBG_ERR("ms_config_set_int failed");
-                       }
-               }
-       } else {
-               if (!ms_config_set_int(VCONFKEY_FILEMANAGER_DB_STATUS, VCONFKEY_FILEMANAGER_DB_UPDATED)) {
-                       res = MS_MEDIA_ERR_VCONF_SET_FAIL;
-                       MS_DBG_ERR("ms_config_set_int failed");
-               }
-
-               if (storage_type == MS_STORAGE_EXTERNAL) {
-                       if (!ms_config_set_int(VCONFKEY_FILEMANAGER_MMC_STATUS, VCONFKEY_FILEMANAGER_MMC_LOADED)) {
-                               res = MS_MEDIA_ERR_VCONF_SET_FAIL;
-                               MS_DBG_ERR("ms_config_set_int failed");
-                       }
-               }
-       }
-
-       err = __msc_extract_set_power_mode(status);
-       if (err != MS_MEDIA_ERR_NONE) {
-               MS_DBG_ERR("__msc_tv_set_power_mode fail");
-               res = err;
-       }
-
-       return res;
-}
-
-static int __msc_extract_set_power_mode(ms_db_status_type_t status)
-{
-       int res = MS_MEDIA_ERR_NONE;
-       int err;
+       //int err = 0;
 
-       switch (status) {
-       case MS_DB_UPDATING:
-               err = pm_lock_state(LCD_OFF, STAY_CUR_STATE, 0);
-               if (err != 0)
-                       res = MS_MEDIA_ERR_INTERNAL;
-               break;
-       case MS_DB_UPDATED:
-               err = pm_unlock_state(LCD_OFF, STAY_CUR_STATE);
-               if (err != 0)
-                       res = MS_MEDIA_ERR_INTERNAL;
-               break;
-       default:
-               MS_DBG_ERR("Unacceptable type : %d", status);
-               break;
+       if (!ms_config_set_int(VCONFKEY_PRIVATE_EXTRACTSTATUS, status)) {
+               res = MS_MEDIA_ERR_VCONF_SET_FAIL;
+               MS_DBG_ERR("ms_config_set_int failed");
        }
 
        return res;
index dd474c7..27d89d6 100755 (executable)
 #include "media-scanner-extract-v2.h"
 #define MAX_SCAN_COUNT 300
 
+#define DIR_SCAN_NON_SCAN         0
+#define DIR_SCAN_RECURSIVE        1
+#define DIR_SCAN_NON_RECURSIVE 2
+
 GAsyncQueue *storage_queue2;
 GAsyncQueue *scan_queue2;
 GAsyncQueue *reg_queue2;
 GMutex scan_req_mutex2;
 GMutex blocked_mutex2;
+GMutex storage_scan_mutex2;
+GMutex dir_scan_mutex2;
+
 char *g_cancel_path2;
 char *g_blocked_path2;
-bool g_directory_scan_processing2;
 
-int stg_scan_status2;
+int insert_count_for_partial = 0;
+int set_count_for_partial = 0;
+int g_directory_scan_processing2 = DIR_SCAN_NON_SCAN;
+char *g_storage_scan_path;
+char* g_dir_scan_path;
+
+typedef int (*DIR_SCAN_CB)();
+DIR_SCAN_CB g_dir_scan_cb;
 
 #ifdef FMS_PERF
 extern struct timeval g_mmc_start_time;
@@ -75,19 +88,50 @@ static int __msc_pop_register_request(GArray *register_array, ms_comm_msg_s **re
 static int __msc_clear_file_list(GArray *path_array);
 static int __msc_check_scan_ignore(char * path);
 static bool __msc_is_valid_path(const char *path, uid_t uid);
-static void __msc_check_dir_path(char *dir_path);
+static void __msc_trim_dir_path(char *dir_path);
 static void __msc_insert_register_request(GArray *register_array, ms_comm_msg_s *insert_data);
 static void __msc_bacth_commit_enable(void* handle, bool ins_status, bool valid_status, bool noti_enable, int pid);
 static void __msc_bacth_commit_disable(void* handle, bool ins_status, bool valid_status, const char *path, int result, uid_t uid);
-static int __msc_set_storage_scan_status(ms_storage_scan_status_e status);
-static int __msc_get_storage_scan_status(ms_storage_scan_status_e *status);
-static int __msc_dir_scan(void **handle, const char *storage_id, const char*start_path, ms_storage_type_t storage_type, int scan_type, uid_t uid);
+static int __msc_dir_scan_for_folder(void **handle, const char *storage_id, const char*start_path, ms_storage_type_t storage_type, int scan_type, int pid, uid_t uid);
+static int __msc_dir_scan_for_storage(void **handle, const char *storage_id, const char*start_path, ms_storage_type_t storage_type, int scan_type, int pid, uid_t uid);
 static bool __msc_storage_mount_status(const char* start_path);
 static char* __msc_get_path(uid_t uid);
 
+static int __msc_get_null_scan_folder_list(void **handle, const char *stroage_id, char *path, GArray *dir_array);
+static int __msc_dir_scan_cb();
+static int __msc_check_scan_same_path(char *scan_path);
+static int __msc_set_storage_scan_cur_path(char *scan_path);
+static int __msc_set_dir_scan_cur_path(char *scan_path);
+static int __msc_dir_and_storage_scan_same_path(char *start_path);
+
+static int __msc_set_dir_scan_cb(DIR_SCAN_CB cb)
+{
+       g_dir_scan_cb = cb;
+
+       return MS_MEDIA_ERR_NONE;
+}
+
+static int __msc_call_dir_scan_cb()
+{
+       if (g_dir_scan_cb != NULL)
+       {
+               g_dir_scan_cb();
+
+               return MS_MEDIA_ERR_NONE;
+       }
+
+       return MS_MEDIA_ERR_INTERNAL;
+}
+
+static int __msc_remove_dir_scan_cb()
+{
+       g_dir_scan_cb = NULL;
+
+       return MS_MEDIA_ERR_NONE;
+}
+
 static char* __msc_get_path(uid_t uid)
 {
-       int result_size = 0;
        char *result_passwd = NULL;
        struct group *grpinfo = NULL;
        if (uid == getuid()) {
@@ -115,7 +159,6 @@ static char* __msc_get_path(uid_t uid)
                        MS_DBG_ERR("UID [%d] does not belong to 'users' group!", uid);
                        return NULL;
                }
-               result_size = strlen(userinfo->pw_dir) + strlen(MEDIA_CONTENT_PATH) + 2;
 
                snprintf(passwd_str, sizeof(passwd_str), "%s/%s", userinfo->pw_dir, MEDIA_CONTENT_PATH);
                result_passwd = g_strdup(passwd_str);
@@ -287,6 +330,10 @@ int msc_init_scan_thread()
 {
        g_mutex_init(&data_mutex2);
        g_mutex_init(&blocked_mutex2);
+       g_mutex_init(&scan_req_mutex2);
+       g_mutex_init(&storage_scan_mutex2);
+
+       g_mutex_init(&dir_scan_mutex2);
 
        g_cond_init(&data_cond2);
 
@@ -297,6 +344,10 @@ int msc_deinit_scan_thread()
 {
        g_mutex_clear(&data_mutex2);
        g_mutex_clear(&blocked_mutex2);
+       g_mutex_clear(&scan_req_mutex2);
+       g_mutex_clear(&storage_scan_mutex2);
+
+       g_mutex_clear(&dir_scan_mutex2);
 
        g_cond_clear(&data_cond2);
 
@@ -313,19 +364,18 @@ static int __msc_resume_scan()
 
        return MS_MEDIA_ERR_NONE;
 }
+
 static int __msc_pause_scan()
 {
        g_mutex_lock(&data_mutex2);
 
-       while (g_directory_scan_processing2)
-               g_cond_wait(&data_cond2, &data_mutex2);
+       g_cond_wait(&data_cond2, &data_mutex2);
 
        g_mutex_unlock(&data_mutex2);
 
        return MS_MEDIA_ERR_NONE;
 }
 
-
 static int __msc_check_stop_status(int scan_type, ms_storage_type_t storage_type, const char *start_path)
 {
        int ret = MS_MEDIA_ERR_NONE;
@@ -367,12 +417,6 @@ static int __msc_check_stop_status(int scan_type, ms_storage_type_t storage_type
        }
 
        if (scan_type == MS_MSG_STORAGE_ALL || scan_type == MS_MSG_STORAGE_PARTIAL) {
-               if (g_directory_scan_processing2 == true) {
-                       MS_DBG_ERR("Now directory scanning is start. So, storage scannig is stopped.");
-                       __msc_pause_scan();
-                       MS_DBG_ERR("Now directory scanning is end. So, storage scannig is resumed.");
-               }
-
                g_mutex_lock(&blocked_mutex2);
                /* check cancel path */
                if (g_blocked_path2 != NULL) {
@@ -392,7 +436,7 @@ static int __msc_check_stop_status(int scan_type, ms_storage_type_t storage_type
        return ret;
 }
 
-static void __msc_check_dir_path(char *dir_path)
+static void __msc_trim_dir_path(char *dir_path)
 {
        /* need implementation */
        /* if dir_path is not NULL terminated, this function will occure crash */
@@ -402,36 +446,27 @@ static void __msc_check_dir_path(char *dir_path)
                dir_path[len -1] = '\0';
 }
 
-struct linux_dirent {
-       ino64_t                 d_ino;   /* 64-bit inode number */
-       off64_t                 d_off;   /* 64-bit offset to next structure */
-       unsigned short  d_reclen; /* Size of this dirent */
-       unsigned char   d_type;  /* File type */
-       char                            d_name[]; /* Filename (null-terminated) */
-};
-
 #define BUF_SIZE 1024
 
-static int __msc_dir_scan(void **handle, const char *storage_id, const char*start_path, ms_storage_type_t storage_type, int scan_type, uid_t uid)
+static int __msc_dir_scan_for_folder(void **handle, const char *storage_id, const char*start_path, ms_storage_type_t storage_type, int scan_type, int pid, uid_t uid)
 {
        GArray *dir_array = NULL;
        int ret = MS_MEDIA_ERR_NONE;
        char *new_path = NULL;
        char *current_path = NULL;
        char path[MS_FILE_PATH_LEN_MAX] = {0, };
-       int (*scan_function)(void **, const char*, const char*, uid_t) = NULL;
        bool is_recursive = true;
        char *new_start_path = NULL;
 
-       int fd = -1;
-       int nread = 0;
-       char buf[BUF_SIZE] = {0, };
-       struct linux_dirent *d;
-       int bpos = 0;
+       DIR *dp = NULL;
+       struct dirent entry;
+       struct dirent *result = NULL;
        int scan_count = 0;
-
        const char *trash = "$RECYCLE.BIN";
 
+       insert_count_for_partial = 0;
+       set_count_for_partial = 0;
+
        MS_DBG_ERR("storage id [%s] start path [%s]", storage_id, start_path);
 
        /* make new array for storing directory */
@@ -449,20 +484,18 @@ static int __msc_dir_scan(void **handle, const char *storage_id, const char*star
                return MS_MEDIA_ERR_OUT_OF_MEMORY;
        }
 
-       MS_DBG_ERR("new start path [%s]", new_start_path);
+       //MS_DBG_ERR("new start path [%s]", new_start_path);
        g_array_append_val(dir_array, start_path);
+       ms_insert_folder_end(handle, uid);
        if (ms_insert_folder(handle, storage_id, new_start_path, uid) != MS_MEDIA_ERR_NONE) {
                MS_DBG_ERR("insert folder failed");
        }
 
-       scan_function = (scan_type == MS_MSG_STORAGE_ALL) ? ms_scan_item_batch : ms_scan_validate_item;
        is_recursive = (scan_type == MS_MSG_DIRECTORY_SCANNING_NON_RECURSIVE) ? false : true;
 
        /* folder validity set 0 under the start_path in folder table*/
-       if (scan_type == MS_MSG_DIRECTORY_SCANNING_NON_RECURSIVE || scan_type == MS_MSG_DIRECTORY_SCANNING) {
-               if (ms_set_folder_validity(handle, storage_id, new_start_path, MS_INVALID, is_recursive, uid) != MS_MEDIA_ERR_NONE) {
-                       MS_DBG_ERR("set_folder_validity failed [%d] ", scan_type);
-               }
+       if (ms_set_folder_validity(handle, storage_id, new_start_path, MS_INVALID, is_recursive, uid) != MS_MEDIA_ERR_NONE) {
+               MS_DBG_ERR("set_folder_validity failed [%d] ", scan_type);
        }
 
        /*start db update. the number of element in the array , db update is complete.*/
@@ -470,12 +503,17 @@ static int __msc_dir_scan(void **handle, const char *storage_id, const char*star
                /*check poweroff status*/
                ret = __msc_check_stop_status(scan_type, storage_type, new_start_path);
                if (ret != MS_MEDIA_ERR_NONE) {
+                       if (is_recursive == true) {
+                               ms_change_validity_item_batch(handle, storage_id, new_start_path, 1, 2, uid);
+                       }
                        goto STOP_SCAN;
                }
                /* get the current path from directory array */
                current_path = g_array_index(dir_array , char*, 0);
                g_array_remove_index(dir_array, 0);
 
+               __msc_set_dir_scan_cur_path(current_path);
+
                ret = __msc_check_scan_ignore(current_path);
                if (ret != MS_MEDIA_ERR_NONE) {
                        MS_DBG_ERR("%s is ignore", current_path);
@@ -490,75 +528,61 @@ static int __msc_dir_scan(void **handle, const char *storage_id, const char*star
                }
 
                ms_insert_folder_start(handle);
+               ms_set_folder_scan_status(handle, storage_id, current_path, MS_DIR_SCAN_PROCESSING, uid);
 
-               fd = open(current_path, O_RDONLY | O_DIRECTORY);
-               if (fd == -1) {
-                       MS_DBG_STRERROR("open fails");
-                       continue;
-               }
-
-               for ( ; ; ) {
-                       nread = syscall(SYS_getdents64, fd, buf, BUF_SIZE);
-
-                       if (nread == -1) {
-                               MS_DBG_STRERROR("getdents");
-                               break;
-                       }
-
-                       /*check poweroff status*/
-                       ret = __msc_check_stop_status(scan_type, storage_type, new_start_path);
-                       if (ret != MS_MEDIA_ERR_NONE) {
-                               goto STOP_SCAN;
-                       }
-
-                       if (nread == 0)
-                               break;
-
-                       for (bpos = 0; bpos < nread;) {
+               dp = opendir(current_path);
+               if (dp != NULL) {
+                       while (!readdir_r(dp, &entry, &result)) {
                                /*check poweroff status*/
                                ret = __msc_check_stop_status(scan_type, storage_type, new_start_path);
                                if (ret != MS_MEDIA_ERR_NONE) {
+                                       if (is_recursive == true) {
+                                               ms_change_validity_item_batch(handle, storage_id, new_start_path, 1, 2, uid);
+                                       }
                                        goto STOP_SCAN;
                                }
 
-                               d = (struct linux_dirent *) (buf + bpos);
-
-                               if (d->d_name[0] == '.') {
-                                       bpos += d->d_reclen;
-                                       continue;
-                               }
+                               if (result == NULL)
+                                       break;
 
-                               if (strcmp(d->d_name, trash) == 0) {
-                                       MS_DBG_ERR("trash directory");
-                                       bpos += d->d_reclen;
+                               if (entry.d_name[0] == '.' ||strcmp(entry.d_name, trash) == 0)
                                        continue;
-                               }
 
-                               if (ms_strappend(path, sizeof(path), "%s/%s", current_path, d->d_name) != MS_MEDIA_ERR_NONE) {
+                               if (ms_strappend(path, sizeof(path), "%s/%s", current_path, entry.d_name) != MS_MEDIA_ERR_NONE) {
                                        MS_DBG_ERR("ms_strappend failed");
-                                       bpos += d->d_reclen;
                                        continue;
                                }
 
-                               if (d->d_type == DT_REG) {
-                                       MS_DBG_ERR("INSERT DT_REG");
+                               if (entry.d_type & DT_REG) {
                                        /* insert into media DB */
-                                       if (scan_function(handle, storage_id, path, uid) != MS_MEDIA_ERR_NONE) {
+                                       if (ms_scan_validate_item(handle,storage_id, path, uid, &insert_count_for_partial, &set_count_for_partial) != MS_MEDIA_ERR_NONE) {
                                                MS_DBG_ERR("failed to update db : %d\n", scan_type);
-                                               bpos += d->d_reclen;
                                                continue;
                                        } else {
                                                ++scan_count;
-                                               //MSC_DBG_ERR("insert count %d", nScanCount);
-                                               if (scan_count/MAX_SCAN_COUNT > 0) {
+                                               //MS_DBG_ERR("insert count %d", nScanCount);
+                                               if (scan_count >= MAX_SCAN_COUNT) {
                                                        scan_count = 0;
-                                                       MS_DBG_ERR("storage_id = [%s]", storage_id);
+                                                       //MS_DBG_ERR("storage_id = [%s]", storage_id);
                                                        msc_insert_exactor_request(scan_type, FALSE, storage_id, current_path, 0, uid);
                                                }
+
+                                               if (insert_count_for_partial >= MAX_SCAN_COUNT) {
+                                                       if (pid != 0) {
+                                                               msc_send_result_partial(ret, MS_MSG_SCANNER_PARTIAL, pid, (char*)start_path);
+                                                       }
+                                                       insert_count_for_partial = 0;
+                                               }
+
+                                               if (set_count_for_partial >= MAX_SCAN_COUNT) {
+                                                       if (pid != 0) {
+                                                               msc_send_result_partial(ret, MS_MSG_SCANNER_PARTIAL, pid, (char*)start_path);
+                                                       }
+                                                       set_count_for_partial = 0;
+                                               }
                                        }
-                               } else if (d->d_type == DT_DIR) {
-                                       MS_DBG_ERR("INSERT DT_DIR");
-                                       if (scan_type != MS_MSG_DIRECTORY_SCANNING_NON_RECURSIVE) {
+                               }else if (entry.d_type & DT_DIR) {
+                                       if  (scan_type != MS_MSG_DIRECTORY_SCANNING_NON_RECURSIVE) {
                                                /* this request is recursive scanning */
                                                /* add new directory to dir_array */
                                                new_path = strdup(path);
@@ -572,47 +596,254 @@ static int __msc_dir_scan(void **handle, const char *storage_id, const char*star
                                                /* don't add new directory to dir_array */
                                                if (ms_insert_folder(handle, storage_id, path, uid) != MS_MEDIA_ERR_NONE) {
                                                        MS_DBG_ERR("insert folder failed");
-                                                       bpos += d->d_reclen;
                                                        continue;
                                                }
                                        }
                                }
-
-                               bpos += d->d_reclen;
                        }
+                       /*update modifiec type for the internal storage*/
+                       if (scan_type == MS_MSG_DIRECTORY_SCANNING_NON_RECURSIVE && storage_type == MS_STORAGE_INTERNAL)
+                               ms_update_folder_time(handle, INTERNAL_STORAGE_ID, current_path, uid);
+               } else {
+                       MS_DBG_ERR("%s folder opendir fails", current_path);
+                       ms_set_folder_scan_status(handle, storage_id, current_path, MS_DIR_SCAN_STOP, uid);
                }
 
                ms_insert_folder_end(handle, uid);
-//             msc_insert_exactor_request(scan_type, FALSE, storage_id, current_path, 0);
-//             scan_count = 0;
+               ms_set_folder_scan_status(handle, storage_id, current_path, MS_DIR_SCAN_DONE, uid);
 
-               if (fd != -1) {
-                       close(fd);
-                       fd = -1;
-               }
+               if (dp) closedir(dp);
+               dp = NULL;
 
                MS_SAFE_FREE(current_path);
+               __msc_set_dir_scan_cur_path(NULL);
        }
 
-       /*remove invalid folder in folder table.*/
-       if (scan_type == MS_MSG_STORAGE_ALL || scan_type == MS_MSG_STORAGE_PARTIAL) {
-               if (__msc_storage_mount_status(new_start_path)) {
-                       if (ms_delete_invalid_folder(handle, storage_id, uid) != MS_MEDIA_ERR_NONE) {
-                               MS_DBG_ERR("delete invalid folder failed");
-                               ret = MS_MEDIA_ERR_DB_DELETE_FAIL;
+STOP_SCAN:
+       if (dp) closedir(dp);
+       MS_SAFE_FREE(new_start_path);
+       __msc_set_dir_scan_cur_path(NULL);
+
+       __msc_clear_file_list(dir_array);
+
+       if (ret != MS_MEDIA_ERR_NONE) MS_DBG_INFO("ret : %d", ret);
+
+       return ret;
+}
+
+static int __msc_dir_scan_for_storage(void **handle, const char *storage_id, const char*start_path, ms_storage_type_t storage_type, int scan_type, int pid, uid_t uid)
+{
+       GArray *dir_array = NULL;
+       int ret = MS_MEDIA_ERR_NONE;
+       char *new_path = NULL;
+       char *current_path = NULL;
+       char path[MS_FILE_PATH_LEN_MAX] = { 0 };
+       int (*scan_function)(void **, const char*, const char*, uid_t, int *, int *) = NULL;
+       char *new_start_path = NULL;
+
+       DIR *dp = NULL;
+       struct dirent entry;
+       struct dirent *result = NULL;
+       int scan_count = 0;
+       const char *trash = "$RECYCLE.BIN";
+
+       bool is_missing = false;
+       ms_dir_scan_status_e scan_status = MS_DIR_SCAN_NONE;
+
+       MS_DBG_ERR("storage id [%s] start path [%s]", storage_id, start_path);
+
+       /* make new array for storing directory */
+       dir_array = g_array_new (FALSE, FALSE, sizeof (char*));
+
+       if (dir_array == NULL) {
+               MS_DBG_ERR("g_array_new failed");
+               return MS_MEDIA_ERR_OUT_OF_MEMORY;
+       }
+       /* add first direcotiry to directory array */
+       new_start_path = strdup(start_path);
+       if (new_start_path == NULL) {
+               MS_DBG_ERR("strdup failed");
+               return MS_MEDIA_ERR_OUT_OF_MEMORY;
+       }
+
+       g_array_append_val (dir_array, start_path);
+       ms_insert_folder_end(handle, uid);
+       if (ms_insert_folder(handle, storage_id, new_start_path, uid) != MS_MEDIA_ERR_NONE) {
+               MS_DBG_ERR("insert folder failed");
+       }
+
+       scan_function = (scan_type == MS_MSG_STORAGE_ALL) ? ms_scan_item_batch : ms_scan_validate_item;
+
+       /*start db update. the number of element in the array , db update is complete.*/
+       while (dir_array->len != 0) {
+               /*check poweroff status*/
+               ret = __msc_check_stop_status(scan_type, storage_type, new_start_path);
+               if (ret != MS_MEDIA_ERR_NONE) {
+                       goto STOP_SCAN;
+               }
+               /* get the current path from directory array */
+               current_path = g_array_index(dir_array , char*, 0);
+               g_array_remove_index (dir_array, 0);
+
+               __msc_set_storage_scan_cur_path(current_path);
+
+               ret = __msc_check_scan_ignore(current_path);
+               if (ret != MS_MEDIA_ERR_NONE) {
+                       MS_DBG_ERR("%s is ignore", current_path);
+                       MS_SAFE_FREE(current_path);
+                       if (ret == MS_MEDIA_ERR_USB_UNMOUNTED) {
+                               goto STOP_SCAN;
+                       } else {
+                               ret = MS_MEDIA_ERR_NONE;
+                       }
+
+                       continue;
+               }
+
+               ms_get_folder_scan_status(handle, storage_id, current_path, (int*)&scan_status);
+
+               if (scan_status == MS_DIR_SCAN_PROCESSING && g_directory_scan_processing2 != DIR_SCAN_NON_SCAN) {
+
+                       MS_DBG_ERR("%s is scanning, ignore current path, scan next path !!", current_path);
+
+                       is_missing = true;
+                       goto NEXT_SCAN;
+
+               } else if (scan_status == MS_DIR_SCAN_DONE) {
+                       if (g_directory_scan_processing2 == DIR_SCAN_NON_RECURSIVE) {
+                               MS_DBG_ERR("%s is scan done, ignore current path, get subfolder list!!", current_path);
+
+                               __msc_get_null_scan_folder_list(handle, storage_id, current_path, dir_array);
+
+                               continue;
+
+                       } else if (g_directory_scan_processing2 == DIR_SCAN_RECURSIVE) {
+                               MS_DBG_ERR("%s is scan done, ignore current path, scan next path!!", current_path);
+
+                               is_missing = true;
+                               goto NEXT_SCAN;
+                       }
+               }
+
+               ms_insert_folder_start(handle);
+               ms_set_folder_scan_status(handle, storage_id, current_path, MS_DIR_SCAN_PROCESSING, uid);
+
+               dp = opendir(current_path);
+               if (dp != NULL) {
+                       while (!readdir_r(dp, &entry, &result)) {
+                               /*check poweroff status*/
+                               ret = __msc_check_stop_status(scan_type, storage_type, new_start_path);
+                               if (ret != MS_MEDIA_ERR_NONE) {
+                                       goto STOP_SCAN;
+                               }
+
+                               if (result == NULL)
+                                       break;
+
+                               if (entry.d_name[0] == '.' ||strcmp(entry.d_name, trash) == 0)
+                                       continue;
+
+                               if (ms_strappend(path, sizeof(path), "%s/%s", current_path, entry.d_name) != MS_MEDIA_ERR_NONE) {
+                                       MS_DBG_ERR("ms_strappend failed");
+                                       continue;
+                               }
+
+                               if (entry.d_type & DT_REG) {
+                                       /* insert into media DB */
+                                       if (scan_function(handle,storage_id, path, uid, &insert_count_for_partial, &set_count_for_partial) != MS_MEDIA_ERR_NONE) {
+                                               MS_DBG_ERR("failed to update db : %d\n", scan_type);
+                                               continue;
+                                       } else {
+                                               ++scan_count;
+                                               //MS_DBG_ERR("insert count %d", nScanCount);
+                                               if (scan_count >= MAX_SCAN_COUNT) {
+                                                       scan_count = 0;
+                                                       //MS_DBG_ERR("storage_id = [%s]", storage_id);
+                                                       msc_insert_exactor_request(scan_type, FALSE, storage_id, current_path, 0, uid);
+                                               }
+                                       }
+
+                               }else if (entry.d_type & DT_DIR) {
+                                       /* this request is recursive scanning */
+                                       /* add new directory to dir_array */
+                                       new_path = strdup(path);
+                                       g_array_append_val (dir_array, new_path);
+
+                                       if (ms_insert_folder(handle, storage_id, new_path, uid) != MS_MEDIA_ERR_NONE) {
+                                               MS_DBG_ERR("insert folder failed");
+                                       }
+                               }
                        }
                } else {
-                       MS_DBG_ERR("start path is unmounted");
+                       MS_DBG_ERR("%s folder opendir fails", current_path);
+                       ms_set_folder_scan_status(handle, storage_id, current_path, MS_DIR_SCAN_STOP, uid);
+               }
+
+               ms_insert_folder_end(handle, uid);
+               ms_set_folder_scan_status(handle, storage_id, current_path, MS_DIR_SCAN_DONE, uid);
+
+               if (dp) closedir(dp);
+               dp = NULL;
+
+NEXT_SCAN:
+               MS_SAFE_FREE(current_path);
+               __msc_set_storage_scan_cur_path(NULL);
+
+               if (dir_array->len == 0 && is_missing) {
+                       is_missing = false;
+
+                       if (g_directory_scan_processing2 == DIR_SCAN_NON_SCAN) {
+                               ret = __msc_get_null_scan_folder_list(handle, storage_id, NULL, dir_array);
+
+                               MS_DBG_ERR("no wait folder scan callback");
+
+                               if (ret != MS_MEDIA_ERR_NONE) {
+                                       break;
+                               }
+                       } else {
+                               __msc_set_dir_scan_cb(__msc_dir_scan_cb);
+
+                               __msc_pause_scan();
+
+                               MS_DBG_ERR("wait folder scan callback");
+
+                               __msc_remove_dir_scan_cb();
+
+                               ret = __msc_get_null_scan_folder_list(handle, storage_id, NULL, dir_array);
+
+                               if (ret != MS_MEDIA_ERR_NONE) {
+                                       break;
+                               }
+                       }
                }
        }
-STOP_SCAN:
-       if (fd != -1) {
-               close(fd);
-               fd = -1;
+
+       /*remove invalid folder in folder table.*/
+       if (__msc_storage_mount_status(new_start_path)) {
+               if((g_directory_scan_processing2 != DIR_SCAN_NON_SCAN)
+                       && (__msc_dir_and_storage_scan_same_path(new_start_path) == MS_MEDIA_ERR_NONE)) {
+                       __msc_set_dir_scan_cb(__msc_dir_scan_cb);
+                       MS_DBG_ERR("storage scan pause...\n");
+                       __msc_pause_scan();
+
+                       MS_DBG_ERR("wait folder scan callback");
+
+                       __msc_remove_dir_scan_cb();
+               }
+               if (ms_delete_invalid_folder(handle, storage_id, uid) != MS_MEDIA_ERR_NONE) {
+                       MS_DBG_ERR("delete invalid folder failed");
+                       ret = MS_MEDIA_ERR_DB_DELETE_FAIL;
+               }
+       } else {
+               MS_DBG_ERR("start path is unmounted");
        }
 
-       MS_SAFE_FREE(new_start_path);
+STOP_SCAN:
+       if (dp) closedir(dp);
+       dp = NULL;
 
+       MS_SAFE_FREE(new_start_path);
+       __msc_set_storage_scan_cur_path(NULL);
        __msc_clear_file_list(dir_array);
 
        if (ret != MS_MEDIA_ERR_NONE) MS_DBG_INFO("ret : %d", ret);
@@ -620,6 +851,144 @@ STOP_SCAN:
        return ret;
 }
 
+int __msc_get_null_scan_folder_list(void **handle, const char *stroage_id, char *path, GArray *dir_array)
+{
+       int ret = MS_MEDIA_ERR_NONE;
+       char *new_path = NULL;
+       char *current_path = NULL;
+       GArray *cur_dir_array = NULL;
+
+       ret = ms_get_null_scan_folder_list(handle, stroage_id, path, &cur_dir_array);
+
+       if (ret == MS_MEDIA_ERR_NONE) {
+               MS_DBG_ERR("cur_dir_array->len = [%d]", cur_dir_array->len);
+               while (cur_dir_array->len != 0) {
+                       current_path = g_array_index(cur_dir_array , char*, 0);
+                       g_array_remove_index (cur_dir_array, 0);
+                       MS_DBG("current_path = [%s]", current_path);
+
+                       new_path = strdup(current_path);
+                       g_array_append_val (dir_array, new_path);
+                       MS_SAFE_FREE(current_path);
+               }
+       }
+
+       __msc_clear_file_list(cur_dir_array);
+
+       return ret;
+}
+
+int __msc_check_scan_same_path(char *scan_path)
+{
+       int ret = MS_MEDIA_ERR_NONE;
+       unsigned int storage_len, folder_len, min_len;
+
+       g_mutex_lock(&storage_scan_mutex2);
+
+       if (NULL == scan_path || NULL == g_storage_scan_path)
+       {
+               g_mutex_unlock(&storage_scan_mutex2);
+
+               return MS_MEDIA_ERR_INTERNAL;
+       }
+
+       storage_len = strlen(g_storage_scan_path);
+       folder_len = strlen(scan_path);
+       min_len = storage_len > folder_len ? folder_len : storage_len;
+
+       ret = strncmp(g_storage_scan_path, scan_path, min_len);
+
+       g_mutex_unlock(&storage_scan_mutex2);
+
+       return abs(ret);
+}
+
+int __msc_set_storage_scan_cur_path(char *scan_path)
+{
+       int ret = MS_MEDIA_ERR_NONE;
+
+       g_mutex_lock(&storage_scan_mutex2);
+
+       if (NULL == scan_path)
+       {
+               MS_SAFE_FREE(g_storage_scan_path);
+       }
+       else
+       {
+               MS_SAFE_FREE(g_storage_scan_path);
+               g_storage_scan_path = strdup(scan_path);
+       }
+
+       g_mutex_unlock(&storage_scan_mutex2);
+
+       return ret;
+}
+
+static int __msc_dir_and_storage_scan_same_path(char *start_path)
+{
+       int ret = MS_MEDIA_ERR_NONE;
+       unsigned int storage_len, folder_len;
+
+       char *storage_path = NULL;
+       char *remain_path = NULL;
+       int remain_len = 0;
+
+       remain_path = strstr(start_path+strlen(MEDIA_ROOT_PATH_USB) +1, "/");
+       if (remain_path != NULL)
+               remain_len = strlen(remain_path);
+
+       storage_path = strndup(start_path, strlen(start_path) - remain_len);
+
+       g_mutex_lock(&dir_scan_mutex2);
+
+       if (NULL == g_dir_scan_path || NULL == storage_path)
+       {
+               MS_SAFE_FREE(storage_path);
+               g_mutex_unlock(&dir_scan_mutex2);
+
+               return MS_MEDIA_ERR_INTERNAL;
+       }
+
+       storage_len = strlen(storage_path);
+       folder_len = strlen(g_dir_scan_path);
+
+       if(folder_len < storage_len)
+       {
+               ret = -1;
+       }
+       else
+       {
+               ret = strncmp(storage_path, g_dir_scan_path, storage_len);
+       }
+
+       MS_SAFE_FREE(storage_path);
+       g_mutex_unlock(&dir_scan_mutex2);
+
+       return abs(ret);
+}
+
+
+int __msc_set_dir_scan_cur_path(char *scan_path)
+{
+       int ret = MS_MEDIA_ERR_NONE;
+
+       g_mutex_lock(&dir_scan_mutex2);
+
+       if (NULL == scan_path)
+       {
+               MS_SAFE_FREE(g_dir_scan_path);
+       }
+       else
+       {
+               MS_SAFE_FREE(g_dir_scan_path);
+               g_dir_scan_path = strdup(scan_path);
+       }
+
+       g_mutex_unlock(&dir_scan_mutex2);
+
+       return ret;
+}
+
 static int __msc_db_update(void **handle, const char *storage_id, const ms_comm_msg_s * scan_data)
 {
        int scan_type;
@@ -634,14 +1003,21 @@ static int __msc_db_update(void **handle, const char *storage_id, const ms_comm_
        if (scan_type != MS_MSG_STORAGE_INVALID) {
                MS_DBG_ERR("INSERT");
                start_path = strndup(scan_data->msg, scan_data->msg_size);
-               scan_type = scan_data->msg_type;
+               if (scan_type == MS_MSG_DIRECTORY_SCANNING || scan_type == MS_MSG_DIRECTORY_SCANNING_NON_RECURSIVE)
+               {
+                       err = __msc_dir_scan_for_folder(handle, storage_id, start_path, storage_type, scan_type, scan_data->pid, scan_data->uid);
+               }
+               else if (scan_type == MS_MSG_STORAGE_ALL || scan_type == MS_MSG_STORAGE_PARTIAL)
+               {
+                       err = __msc_dir_scan_for_storage(handle, storage_id, start_path, storage_type, scan_type, scan_data->pid, scan_data->uid);
+               }
 
-               err = __msc_dir_scan(handle, storage_id, start_path, storage_type, scan_type, scan_data->uid);
                if (err != MS_MEDIA_ERR_NONE) {
                        MS_DBG_ERR("error : %d", err);
                }
        } else if (scan_type == MS_MSG_STORAGE_INVALID) {
                MS_DBG_ERR("INVALID");
+#if 1
                /*In this case, update just validation record*/
                /*update just valid type*/
                err = ms_validaty_change_all_items(handle, storage_id, storage_type, false, scan_data->uid);
@@ -653,6 +1029,7 @@ static int __msc_db_update(void **handle, const char *storage_id, const ms_comm_
                if (ms_set_folder_validity(handle, storage_id, scan_data->msg, MS_INVALID, TRUE, scan_data->uid) != MS_MEDIA_ERR_NONE) {
                        MS_DBG_ERR("set_folder_validity failed");
                }
+#endif
                msc_remove_extract_request(scan_data);
        }
 
@@ -667,15 +1044,39 @@ static int __msc_pop_new_request(ms_comm_msg_s **scan_data)
        return MS_MEDIA_ERR_NONE;
 }
 
+static bool __msc_check_folder_path(const char *folder_path)
+{
+       DIR *dp = NULL;
+
+       dp = opendir(folder_path);
+       if (dp == NULL) {
+               MS_DBG_ERR("Deleted folder path");
+               return false;
+       }
+       closedir(dp);
+
+       return true;
+}
+
 gboolean msc_directory_scan_thread(void *data)
 {
        ms_comm_msg_s *scan_data = NULL;
        int err;
-       int ret;
+       int ret = MS_MEDIA_ERR_NONE;
        void **handle = NULL;
        int scan_type;
-       char *noti_path = NULL;
        char *storage_id = NULL;
+       bool modified = FALSE;
+       int index = 0;
+       ms_storage_type_t storage_type = MS_STORAGE_INTERNAL;
+       ms_dir_scan_status_e scan_status = MS_DIR_SCAN_NONE;
+       ms_noti_type_e noti_type = MS_ITEM_INSERT;
+       int before_count = 0;
+       int after_count = 0;
+       int delete_count = 0;
+       int delete_folder_count = 0;
+       char *folder_uuid = NULL;
+       bool is_recursive = true;
        bool power_off_status = FALSE;
 
        while (1) {
@@ -688,7 +1089,7 @@ gboolean msc_directory_scan_thread(void *data)
 
                MS_DBG_ERR("DIRECTORY SCAN START [%s, %d]", scan_data->msg, scan_data->msg_type);
 
-               g_directory_scan_processing2 = true;
+               g_directory_scan_processing2 = DIR_SCAN_NON_RECURSIVE;
 
                /*connect to media db, if conneting is failed, db updating is stopped*/
                err = ms_connect_db(&handle, scan_data->uid);
@@ -696,6 +1097,8 @@ gboolean msc_directory_scan_thread(void *data)
                        continue;
 
                scan_type = scan_data->msg_type;
+               storage_type = ms_get_storage_type_by_full(scan_data->msg, scan_data->uid);
+               ms_reset_insert_count();
 
                storage_id = strdup(scan_data->storage_id);
                if (storage_id == NULL) {
@@ -719,14 +1122,135 @@ gboolean msc_directory_scan_thread(void *data)
                        goto NEXT;
                }
 
-               __msc_check_dir_path(scan_data->msg);
+               __msc_trim_dir_path(scan_data->msg);
+
+               if (__msc_check_folder_path(scan_data->msg)) {
+                       is_recursive = (scan_type == MS_MSG_DIRECTORY_SCANNING_NON_RECURSIVE) ? false : true;
+
+                       if (ms_check_folder_exist(handle, storage_id, scan_data->msg) == MS_MEDIA_ERR_NONE) {
+                               /*already exist in media DB*/
+                               noti_type = MS_ITEM_UPDATE;
+                               MS_DBG_ERR("[%s] already exist", scan_data->msg);
+                       } else {
+                               noti_type = MS_ITEM_INSERT;
+                               MS_DBG_ERR("[%s] new insert path", scan_data->msg);
+                       }
+               } else {
+                       /*directory is deleted*/
+                       is_recursive = true;
+                       noti_type = MS_ITEM_DELETE;
+                       scan_type = MS_MSG_DIRECTORY_SCANNING;
+                       scan_data->msg_type = MS_MSG_DIRECTORY_SCANNING;
+
+                       /*get the UUID of deleted folder*/
+                       ms_get_folder_id(handle, storage_id, scan_data->msg, &folder_uuid);
+
+                       MS_DBG_ERR("[%s][%s] delete path", scan_data->msg, folder_uuid);
+               }
+
+               ms_check_subfolder_count(handle, storage_id, scan_data->msg, &before_count);
+               MS_DBG_ERR("BEFORE COUNT[%d]", before_count);
 
-               /*change validity before scanning*/
                if (scan_type == MS_MSG_DIRECTORY_SCANNING) {
-                       err = ms_set_folder_item_validity(handle, storage_id, scan_data->msg, MS_INVALID, MS_RECURSIVE, scan_data->uid);
+
+                       MS_DBG_ERR("start recursive dir scan!!");
+
+                       g_directory_scan_processing2 = DIR_SCAN_RECURSIVE;
+                       err = __msc_check_scan_same_path(scan_data->msg);
+
+                       if (MS_MEDIA_ERR_NONE == err) {
+                               MS_DBG_ERR("[%s] is scanning recursive, waiting...", scan_data->msg);
+
+                               while (1) {
+                                       sleep(1);
+
+                                       ret = __msc_check_stop_status(scan_type, storage_type, scan_data->msg);
+                                       if (ret != MS_MEDIA_ERR_NONE) {
+                                               goto NEXT;
+                                       }
+
+                                       if ((++index) % 3 == 0)
+                                       {
+                                               msc_send_result_partial(ret, MS_MSG_SCANNER_PARTIAL, scan_data->pid, scan_data->msg);
+                                       }
+
+                                       err = __msc_check_scan_same_path(scan_data->msg);
+                                       if (err != MS_MEDIA_ERR_NONE) {
+                                               break;
+                                       }
+                               }
+
+                               index = 0;
+                               MS_DBG_ERR("[%s] scan done, wait finished", scan_data->msg);
+                               goto SCAN_DONE;
+
+                       } else {
+                               ms_get_folder_scan_status(handle, storage_id, scan_data->msg, (int*)&scan_status);
+
+                               if (scan_status == MS_DIR_SCAN_DONE) {
+                                       ms_set_folder_item_validity(handle, storage_id, scan_data->msg, MS_VALIND_V2, MS_RECURSIVE, scan_data->uid);
+                               } else {
+                                       ms_set_folder_item_validity(handle, storage_id, scan_data->msg, MS_INVALID, MS_RECURSIVE, scan_data->uid);
+                               }
+                       }
                } else {
+                       MS_DBG_ERR("start non recursive dir scan!!");
+
+                       g_directory_scan_processing2 = DIR_SCAN_NON_RECURSIVE;
+                       ms_check_folder_modified(handle, scan_data->msg, storage_id, &modified);
+
+                       if (modified == FALSE) {
+                               MS_DBG_ERR("check [%s] has not been modified !!", scan_data->msg);
+                               ms_get_folder_scan_status(handle, storage_id, scan_data->msg, (int*)&scan_status);
+                               MS_DBG_ERR("folder scan status = [%d]", scan_status);
+
+                               if (scan_status == MS_DIR_SCAN_DONE) {
+                                       /* do nothing */
+                                       MS_DBG_ERR("[%s] scan done", scan_data->msg);
+                                       err = ms_set_folder_item_validity(handle, storage_id, scan_data->msg, MS_VALIND, MS_NON_RECURSIVE, scan_data->uid);
+                                       goto SCAN_DONE;
+                               } else if (scan_status == MS_DIR_SCAN_PROCESSING) {
+                                       MS_DBG_ERR("[%s] scanning, waiting...", scan_data->msg);
+
+                                       while (1) {
+                                               sleep(1);
+
+                                               ret = __msc_check_stop_status(scan_type, storage_type, scan_data->msg);
+                                               if (ret != MS_MEDIA_ERR_NONE) {
+                                                       goto NEXT;
+                                               }
+
+                                               if ((++index) % 3 == 0)
+                                               {
+                                                       msc_send_result_partial(ret, MS_MSG_SCANNER_PARTIAL, scan_data->pid, scan_data->msg);
+                                               }
+
+                                               ms_get_folder_scan_status(handle, storage_id, scan_data->msg, (int*)&scan_status);
+                                               if (scan_status == MS_DIR_SCAN_DONE) {
+                                                       break;
+                                               }
+                                       }
+
+                                       index = 0;
+                                       MS_DBG_ERR("[%s] scan done, wait finished", scan_data->msg);
+                                       goto SCAN_DONE;
+                               }else {
+                                       err = ms_set_folder_item_validity(handle, storage_id, scan_data->msg, MS_INVALID, MS_NON_RECURSIVE, scan_data->uid);
+                               }
+                       } else {
+                               MS_DBG_ERR("check [%s] has been modified !!", scan_data->msg);
+                               err = ms_set_folder_item_validity(handle, storage_id, scan_data->msg, MS_INVALID, MS_NON_RECURSIVE, scan_data->uid);
+#if 0
+                               ms_get_folder_scan_status(handle, storage_id, scan_data->msg, &scan_status);
+                               MS_DBG_ERR("folder scan status = [%d]", scan_status);
+
+                               if (scan_status == MS_DIR_SCAN_PROCESSING) {
+                                       MS_DBG_ERR("[%s] scanning, notify storage scan to stop scan %s !!", scan_data->msg, scan_data->msg);
 
-                       err = ms_set_folder_item_validity(handle, storage_id, scan_data->msg, MS_INVALID, MS_NON_RECURSIVE, scan_data->uid);
+                                       //add notify storage scan to stop scan
+                               }
+#endif
+                       }
                }
 
                if (err != MS_MEDIA_ERR_NONE)
@@ -742,34 +1266,53 @@ gboolean msc_directory_scan_thread(void *data)
                /*call for bundle commit*/
                __msc_bacth_commit_disable(handle, TRUE, TRUE, scan_data->msg, ret, scan_data->uid);
 
-               MS_DBG_ERR("storage_id = [%s], scan_data->storage_id = [%s]", storage_id, scan_data->storage_id);
-               msc_insert_exactor_request(scan_type, TRUE, scan_data->storage_id, scan_data->msg, scan_data->pid, scan_data->uid);
+               MS_DBG_ERR("folder scan done, sent cb event path = [%s]", scan_data->msg);
+               __msc_call_dir_scan_cb();
 
-               if (ret == MS_MEDIA_ERR_NONE) {
-                       MS_DBG_INFO("working normally");
-                       int count = 0;
-                       bool is_recursive = true;
-                       int insert_count = ms_get_insert_count();
+               ms_check_subfolder_count(handle, storage_id, scan_data->msg, &after_count);
+               MS_DBG_ERR("BEFORE COUNT[%d]", before_count);
+
+               if (ms_count_delete_items_in_folder(handle, storage_id, scan_data->msg, &delete_count) != MS_MEDIA_ERR_NONE) {
+                       MS_DBG_ERR("counting invalid items failed");
+               }
+
+               if (ms_delete_invalid_items_in_folder(handle, storage_id, scan_data->msg, is_recursive, scan_data->uid)  != MS_MEDIA_ERR_NONE) {
+                       MS_DBG_ERR("deleting invalid items in folder failed");
+               }
 
-                       noti_path = strndup(scan_data->msg, scan_data->msg_size);
+               /*remove invalid folder in folder table.*/
+               //if(ms_delete_invalid_folder_by_path(handle, storage_id, scan_data->msg, &delete_folder_count) != MS_MEDIA_ERR_NONE) {
+               //      MS_DBG_ERR("deleting invalid folder failed");
+               //}
 
-                       ms_count_delete_items_in_folder(handle, storage_id, noti_path, &count);
+               MS_DBG_SLOG("delete folder count %d", delete_folder_count);
 
-                       MS_DBG_ERR("delete count %d", count);
-                       MS_DBG_ERR("insert count %d", insert_count);
+               if (ret != MS_MEDIA_ERR_SCANNER_FORCE_STOP) {
+                       MS_DBG_INFO("working normally");
 
-                       if (scan_type == MS_MSG_DIRECTORY_SCANNING_NON_RECURSIVE)
-                               is_recursive = false;
+                       if (noti_type != MS_ITEM_UPDATE) {
+                               ms_send_dir_update_noti(handle, storage_id, scan_data->msg, folder_uuid, noti_type, scan_data->pid);
+                       } else {
+                               int insert_count = ms_get_insert_count();
+                               int delete_count = ms_get_delete_count();
 
-                       ms_delete_invalid_items_in_folder(handle, storage_id, scan_data->msg, is_recursive, scan_data->uid);
+                               MS_DBG_SLOG("delete count %d", delete_count);
+                               MS_DBG_SLOG("insert count %d", insert_count);
 
-                       if (!(count == 0 && insert_count == 0)) {
-                               ms_send_dir_update_noti(handle, storage_id, noti_path, NULL, MS_ITEM_UPDATE, scan_data->pid);
+                               if (!(delete_count == 0 && insert_count == 0)
+                                       || !(before_count == after_count)
+                                       || delete_folder_count != 0) {
+                                       ms_send_dir_update_noti(handle, storage_id, scan_data->msg, folder_uuid, noti_type, scan_data->pid);
+                               }
                        }
-                       MS_SAFE_FREE(noti_path);
                }
 
                ms_reset_insert_count();
+               ms_reset_delete_count();
+
+SCAN_DONE:
+               MS_DBG_ERR("storage_id = [%s], dir Path = [%s]", storage_id, scan_data->msg);
+               msc_insert_exactor_request(scan_data->msg_type, TRUE, scan_data->storage_id, scan_data->msg, scan_data->pid, scan_data->uid);
 
                msc_get_power_status(&power_off_status);
                if (power_off_status) {
@@ -777,29 +1320,22 @@ gboolean msc_directory_scan_thread(void *data)
                        goto _POWEROFF;
                }
 
+
 NEXT:
                /*Active flush */
                malloc_trim(0);
 
-//             msc_send_result(ret, scan_data);
+               scan_data->msg_type = MS_MSG_SCANNER_COMPLETE;
+               msc_send_result(ret, scan_data);
 
                MS_SAFE_FREE(scan_data);
                MS_SAFE_FREE(storage_id);
+               MS_SAFE_FREE(folder_uuid);
 
-               g_directory_scan_processing2 = false;
+               g_directory_scan_processing2 = DIR_SCAN_NON_SCAN;
 
                MS_DBG_ERR("DIRECTORY SCAN END [%d]", ret);
 
-               ms_storage_scan_status_e storage_scan_status = MS_STORAGE_SCAN_NONE;
-               ret = __msc_get_storage_scan_status(&storage_scan_status);
-               if (ret == MS_MEDIA_ERR_NONE) {
-                       /*get storage list and scan status from media db*/
-                       if (storage_scan_status != MS_STORAGE_SCAN_DONE) {
-                               __msc_resume_scan();
-                               MS_DBG_ERR("RESUME OK");
-                       }
-               }
-
                /*disconnect form media db*/
                if (handle) ms_disconnect_db(&handle);
        }                       /*thread while*/
@@ -892,7 +1428,7 @@ static int __msc_compare_with_db(void **handle, const char *storage_id, const ch
                /* get the current path from directory array */
                current_path = g_array_index(read_dir_array , char*, 0);
                g_array_remove_index(read_dir_array, 0);
-//             MSC_DBG_ERR("%s", current_path);
+//             MS_DBG_ERR("%s", current_path);
 
                if (__msc_check_scan_ignore(current_path) != MS_MEDIA_ERR_NONE) {
                        MS_DBG_ERR("%s is ignore", current_path);
@@ -939,7 +1475,7 @@ static int __msc_compare_with_db(void **handle, const char *storage_id, const ch
        return ret;
 }
 
-static int _msc_db_update_partial(void **handle, const char *storage_id, ms_storage_type_t storage_type, GArray *dir_array, uid_t uid)
+static int _msc_db_update_partial(void **handle, const char *storage_id, ms_storage_type_t storage_type, GArray *dir_array, int pid, uid_t uid)
 {
        unsigned int i;
        int err = MS_MEDIA_ERR_NONE;
@@ -962,7 +1498,7 @@ static int _msc_db_update_partial(void **handle, const char *storage_id, ms_stor
                        }
                }
 
-               __msc_dir_scan(handle, storage_id, update_path, storage_type, MS_MSG_DIRECTORY_SCANNING_NON_RECURSIVE, uid);
+               __msc_dir_scan_for_folder(handle, storage_id, update_path, storage_type, MS_MSG_DIRECTORY_SCANNING_NON_RECURSIVE, pid, uid);
        }
 
        /*delete all node*/
@@ -979,6 +1515,11 @@ static int _msc_db_update_partial(void **handle, const char *storage_id, ms_stor
        return MS_MEDIA_ERR_NONE;
 }
 
+int __msc_dir_scan_cb()
+{
+       return __msc_resume_scan();
+}
+
 gboolean msc_storage_scan_thread(void *data)
 {
        ms_comm_msg_s *scan_data = NULL;
@@ -993,14 +1534,12 @@ gboolean msc_storage_scan_thread(void *data)
        bool power_off_status = FALSE;
 
        while (1) {
-               __msc_set_storage_scan_status(MS_STORAGE_SCAN_PREPARE);
                scan_data = g_async_queue_pop(storage_queue2);
                if (scan_data->pid == POWEROFF) {
                        MS_DBG_ERR("power off");
                        goto _POWEROFF;
                }
 
-               __msc_set_storage_scan_status(MS_STORAGE_SCAN_PROCESSING);
                MS_DBG_ERR("STORAGE SCAN START [%s]", scan_data->msg);
 
                scan_type = scan_data->msg_type;
@@ -1025,7 +1564,7 @@ gboolean msc_storage_scan_thread(void *data)
                /*start db updating */
                __msc_set_db_status(MS_DB_UPDATING, storage_type);
 
-               valid_status = (scan_type == MS_MSG_STORAGE_PARTIAL) ? TRUE : FALSE;
+               valid_status = (scan_type == MS_MSG_STORAGE_PARTIAL || MS_MSG_STORAGE_ALL == scan_type) ? TRUE : FALSE;
 
                if (scan_type != MS_MSG_STORAGE_INVALID)
                        __msc_bacth_commit_enable(handle, TRUE, valid_status, MS_NOTI_SWITCH_OFF, 0);
@@ -1042,7 +1581,7 @@ gboolean msc_storage_scan_thread(void *data)
 
                        if (dir_array->len != 0) {
                                MS_DBG_INFO("DB UPDATING IS NEEDED");
-                               ret = _msc_db_update_partial(handle, scan_data->storage_id, storage_type, dir_array, scan_data->uid);
+                               ret = _msc_db_update_partial(handle, scan_data->storage_id, storage_type, dir_array, scan_data->pid, scan_data->uid);
                        } else {
                                MS_DBG_INFO("THERE IS NO UPDATE");
                        }
@@ -1066,27 +1605,8 @@ gboolean msc_storage_scan_thread(void *data)
                        __msc_bacth_commit_disable(handle, TRUE, valid_status, scan_data->msg, ret, scan_data->uid);
                }
 
-               MS_DBG_ERR("scan_data->storage_id = [%s]", scan_data->storage_id);
-
-               msc_insert_exactor_request(scan_type, TRUE, scan_data->storage_id, scan_data->msg, scan_data->pid, scan_data->uid);
-
-               MS_DBG_ERR("PAUSE");
-               __msc_pause_scan();
-               MS_DBG_ERR("RESUME");
-               /* move to msc_tv_storage_extract_thread */
-               if (0) {
-                       int del_count = 0;
-
-                       /*check delete count*/
-                       MS_DBG_INFO("update path : %s", update_path);
-
-                       ms_count_delete_items_in_folder(handle, scan_data->storage_id, update_path, &del_count);
-
-                       /*if there is no delete content, do not call delete API*/
-                       if (del_count != 0) {
-                               MS_DBG_ERR("storage thread delete count [%d]", del_count);
-                               ms_delete_invalid_items(handle, scan_data->storage_id, storage_type, scan_data->uid);
-                       }
+               if (scan_type == MS_MSG_STORAGE_PARTIAL && ret == MS_MEDIA_ERR_NONE) {
+                       ms_delete_invalid_items(handle, scan_data->storage_id, storage_type, scan_data->uid);
                }
 
                /* send notification */
@@ -1094,16 +1614,17 @@ gboolean msc_storage_scan_thread(void *data)
 
                if (ret == MS_MEDIA_ERR_SCANNER_FORCE_STOP) {
                        ms_set_storage_scan_status(handle, scan_data->storage_id, MEDIA_SCAN_STOP, scan_data->uid);
-                       __msc_set_storage_scan_status(MS_STORAGE_SCAN_STOP);
                        /*set vconf key mmc loading for indicator */
                        __msc_set_db_status(MS_DB_STOPPED, storage_type);
                } else {
                        ms_set_storage_scan_status(handle, scan_data->storage_id, MEDIA_SCAN_COMPLETE, scan_data->uid);
-                       __msc_set_storage_scan_status(MS_STORAGE_SCAN_DONE);
                        /*set vconf key mmc loading for indicator */
                        __msc_set_db_status(MS_DB_UPDATED, storage_type);
                }
 
+               MS_DBG_ERR("storage_id = [%s]", scan_data->storage_id);
+               msc_insert_exactor_request(scan_type, TRUE, scan_data->storage_id, scan_data->msg, scan_data->pid, scan_data->uid);
+
 NEXT:
 
                MS_SAFE_FREE(update_path);
@@ -1120,7 +1641,8 @@ NEXT:
                /*Active flush */
                malloc_trim(0);
 
-//             msc_send_result(ret, scan_data);
+               scan_data->msg_type = MS_MSG_SCANNER_COMPLETE;
+               msc_send_result(ret, scan_data);
 
                MS_SAFE_FREE(scan_data);
 
@@ -1563,36 +2085,6 @@ int msc_del_cancel_path()
        return MS_MEDIA_ERR_NONE;
 }
 
-static int __msc_set_storage_scan_status(ms_storage_scan_status_e status)
-{
-       int res = MS_MEDIA_ERR_NONE;
-#if 0
-       if (!ms_config_set_int(MS_SCANNER_STATUS, status)) {
-               res = MS_MEDIA_ERR_VCONF_SET_FAIL;
-               MSC_DBG_ERR("ms_config_set_int failed");
-       }
-#else
-       stg_scan_status2 = status;
-#endif
-       return res;
-}
-
-static int __msc_get_storage_scan_status(ms_storage_scan_status_e *status)
-{
-       int res = MS_MEDIA_ERR_NONE;
-
-#if 0
-       if (!ms_config_get_int(MS_SCANNER_STATUS, status)) {
-               res = MS_MEDIA_ERR_VCONF_SET_FAIL;
-               MSC_DBG_ERR("ms_config_get_int failed");
-       }
-#else
-       *status = stg_scan_status2;
-#endif
-
-       return res;
-}
-
 static bool __msc_storage_mount_status(const char* start_path)
 {
        bool ret = false;
@@ -1606,7 +2098,7 @@ static bool __msc_storage_mount_status(const char* start_path)
                return FALSE;
        }
 
-       remain_path = strstr(start_path  +strlen(MEDIA_ROOT_PATH_EXTERNAL) + 1, "/");
+       remain_path = strstr(start_path strlen(MEDIA_ROOT_PATH_EXTERNAL) + 1, "/");
        if (remain_path != NULL)
                remain_len = strlen(remain_path);
 
index da0bb07..a2c6cb2 100755 (executable)
@@ -223,7 +223,12 @@ int msc_send_result(int result, ms_comm_msg_s *res_data)
 
        /* send result message */
        memset(&send_msg, 0x0, sizeof(ms_comm_msg_s));
-       send_msg.msg_type = MS_MSG_SCANNER_BULK_RESULT;
+       if(res_data->msg_type == MS_MSG_SCANNER_COMPLETE)
+               send_msg.msg_type = MS_MSG_SCANNER_COMPLETE;
+       else if(res_data->msg_type == MS_MSG_EXTRACTOR_COMPLETE)
+               send_msg.msg_type = MS_MSG_EXTRACTOR_COMPLETE;
+       else
+               send_msg.msg_type = MS_MSG_SCANNER_BULK_RESULT;
        send_msg.pid = res_data->pid;
        send_msg.result = result;
        send_msg.msg_size = res_data->msg_size;
@@ -241,3 +246,38 @@ int msc_send_result(int result, ms_comm_msg_s *res_data)
        return res;
 }
 
+int msc_send_result_partial(int result, ms_msg_type_e msg_type, int pid, char *msg)
+{
+       MS_DBG_SLOG("msc_send_result msg_type=%d", msg_type);
+       int res = MS_MEDIA_ERR_NONE;
+       ms_comm_msg_s send_msg;
+       int fd = -1;
+       int err = -1;
+
+       fd = open(MS_SCANNER_FIFO_PATH_RES, O_WRONLY);
+       if (fd < 0) {
+               MS_DBG_STRERROR("fifo open failed");
+               return MS_MEDIA_ERR_FILE_OPEN_FAIL;
+       }
+
+       /* send result message */
+       memset(&send_msg, 0x0, sizeof(ms_comm_msg_s));
+       send_msg.msg_type = MS_MSG_SCANNER_PARTIAL;
+       send_msg.pid = pid;
+       send_msg.result = result;
+       send_msg.msg_size = strlen(msg);
+       strncpy(send_msg.msg, msg, send_msg.msg_size);
+
+       /* send ready message */
+       err = write(fd, &send_msg, sizeof(send_msg));
+       if (err < 0) {
+               MS_DBG_STRERROR("fifo write failed");
+               res = MS_MEDIA_ERR_FILE_READ_FAIL;
+       }
+
+       close(fd);
+
+       return res;
+}
+
+
index 99d1831..642fc04 100755 (executable)
@@ -87,7 +87,6 @@ static char* __msc_get_path(uid_t uid);
 
 static char* __msc_get_path(uid_t uid)
 {
-       int result_size = 0;
        char *result_passwd = NULL;
        struct group *grpinfo = NULL;
        if (uid == getuid()) {
@@ -115,7 +114,6 @@ static char* __msc_get_path(uid_t uid)
                        MS_DBG_ERR("UID [%d] does not belong to 'users' group!", uid);
                        return NULL;
                }
-               result_size = strlen(userinfo->pw_dir) + strlen(MEDIA_CONTENT_PATH) + 2;
 
                snprintf(passwd_str, sizeof(passwd_str), "%s/%s", userinfo->pw_dir, MEDIA_CONTENT_PATH);
                result_passwd = g_strdup(passwd_str);
index 0657512..1fffd02 100755 (executable)
@@ -26,6 +26,8 @@
 #include <errno.h>
 #include <malloc.h>
 #include <vconf.h>
+#include <grp.h>
+#include <pwd.h>
 
 #include "media-util.h"
 #include "media-common-utils.h"
@@ -56,6 +58,43 @@ static int __ms_check_usb_status(void);
 
 static char *priv_lang = NULL;
 
+static char* __ms_get_path(uid_t uid)
+{
+       char *result_passwd = NULL;
+       struct group *grpinfo = NULL;
+       if (uid == getuid()) {
+               grpinfo = getgrnam("users");
+               if (grpinfo == NULL) {
+                       MS_DBG_ERR("getgrnam(users) returns NULL !");
+                       return NULL;
+               }
+               if (MS_STRING_VALID(MEDIA_ROOT_PATH_INTERNAL))
+                       result_passwd = strndup(MEDIA_ROOT_PATH_INTERNAL, strlen(MEDIA_ROOT_PATH_INTERNAL));
+       } else {
+               char passwd_str[MAX_FILEPATH_LEN] = {0, };
+               struct passwd *userinfo = getpwuid(uid);
+               if (userinfo == NULL) {
+                       MS_DBG_ERR("getpwuid(%d) returns NULL !", uid);
+                       return NULL;
+               }
+               grpinfo = getgrnam("users");
+               if (grpinfo == NULL) {
+                       MS_DBG_ERR("getgrnam(users) returns NULL !");
+                       return NULL;
+               }
+               // Compare git_t type and not group name
+               if (grpinfo->gr_gid != userinfo->pw_gid) {
+                       MS_DBG_ERR("UID [%d] does not belong to 'users' group!", uid);
+                       return NULL;
+               }
+
+               snprintf(passwd_str, sizeof(passwd_str), "%s/%s", userinfo->pw_dir, MEDIA_CONTENT_PATH);
+               result_passwd = g_strdup(passwd_str);
+       }
+
+       return result_passwd;
+}
+
 void _power_off_cb(ms_power_info_s *power_info, void* data)
 {
        MS_DBG_ERR("POWER OFF");
@@ -359,7 +398,7 @@ static void __ms_check_mediadb(void)
        uid_t uid = 0;
 
        ms_sys_get_uid(&uid);
-       ms_send_storage_scan_request(MEDIA_ROOT_PATH_INTERNAL, INTERNAL_STORAGE_ID, MS_SCAN_PART, uid);
+       ms_send_storage_scan_request(__ms_get_path(uid), INTERNAL_STORAGE_ID, MS_SCAN_PART, uid);
 
        /* update external storage */
        __ms_check_mmc_status();
index 4848c2e..d546ca0 100755 (executable)
@@ -39,7 +39,7 @@
 #include <tzplatform_config.h>
 
 #define MS_NO_REMAIN_TASK 0
-
+#define VCONFKEY_PRIVATE_EXTRACTSTATUS "db/private/extractstatus"
 #define MEDIA_SERVER_PATH tzplatform_mkpath(TZ_SYS_BIN, "media-scanner")
 #define MEDIA_SERVER_PATH_V2 tzplatform_mkpath(TZ_SYS_BIN, "media-scanner-v2")
 
@@ -76,6 +76,13 @@ ms_db_status_type_t ms_check_scanning_status(void)
                }
        }
 
+       if (ms_config_get_int(VCONFKEY_PRIVATE_EXTRACTSTATUS, &status)) {
+               MS_DBG("extract status %d", status);
+               if (status == MS_DB_UPDATING) {
+                       return MS_DB_UPDATING;
+               }
+       }
+
        return MS_DB_UPDATED;
 }
 
index 903254c..4eeea72 100755 (executable)
@@ -46,7 +46,6 @@ GAsyncQueue* ret_queue;
 GArray *owner_list;
 GMutex scanner_mutex;
 gint cur_running_task;
-
 extern bool power_off;
 
 typedef struct ms_req_owner_data {
@@ -707,7 +706,11 @@ gboolean ms_receive_message_from_scanner(GIOChannel *src, GIOCondition condition
        msg_type = recv_msg.msg_type;
        pid = recv_msg.pid;
        if ((msg_type == MS_MSG_SCANNER_RESULT) ||
-               (msg_type == MS_MSG_SCANNER_BULK_RESULT)) {
+               (msg_type == MS_MSG_SCANNER_BULK_RESULT) ||
+               (msg_type == MS_MSG_SCANNER_COMPLETE) ||
+               (msg_type == MS_MSG_SCANNER_PARTIAL)||
+               (msg_type == MS_MSG_EXTRACTOR_COMPLETE)||
+               (msg_type == MS_MSG_DIRECTORY_SCANNING_CANCEL)) {
                MS_DBG_WARN("DB UPDATING IS DONE[%d]", msg_type);
 
                if (pid != 0) {