send result when db connect fail && send update notification after extract done 27/159127/3
authorchen89.chen <chen89.chen@samsung.com>
Tue, 7 Nov 2017 06:41:32 +0000 (14:41 +0800)
committerhj kim <backto.kim@samsung.com>
Tue, 7 Nov 2017 06:46:55 +0000 (06:46 +0000)
Change-Id: I3f08d7acd395173d941caeaa28ecc5d139d35c8b

lib/media-util-db.c
src/scanner-v2/media-scanner-extract-v2.c
src/scanner-v2/media-scanner-scan-v2.c
src/scanner-v2/media-scanner-socket-v2.c

index 74767e9..26ccb23 100755 (executable)
@@ -75,13 +75,14 @@ static int __media_db_connect_db_with_handle(sqlite3 **db_handle, uid_t uid, boo
        else
                ret = db_util_open_with_options(db_path, db_handle, SQLITE_OPEN_READONLY, NULL);
 
-       MS_SAFE_FREE(db_path);
 
        if (SQLITE_OK != ret) {
-               MSAPI_DBG_ERR("error when db open [%s]", db_path);
+               MSAPI_DBG_ERR("error when db open path[%s],ret[%d]", db_path, ret);
+               MS_SAFE_FREE(db_path);
                *db_handle = NULL;
                return MS_MEDIA_ERR_DB_CONNECT_FAIL;
        }
+       MS_SAFE_FREE(db_path);
 
        if (*db_handle == NULL) {
                MSAPI_DBG_ERR("*db_handle is NULL");
@@ -350,7 +351,7 @@ EXEC_RETRY:
        ret = sqlite3_exec(db_handle, sql_str, NULL, NULL, &zErrMsg);
 
        if (SQLITE_OK != ret) {
-               MSAPI_ERR_SLOG("Query[%s] Error[%s]", sql_str, zErrMsg);
+               MSAPI_ERR_SLOG("Error[%s],Query[%s]", zErrMsg, sql_str);
                MS_SQL_SAFE_FREE(zErrMsg);
                if (ret == SQLITE_BUSY) {
                        ret = MS_MEDIA_ERR_DB_BUSY_FAIL;
index b1b02ea..cd52eb6 100755 (executable)
@@ -177,8 +177,7 @@ int __msc_folder_bulk_extract(void **handle, const char* storage_id, int storage
 gboolean msc_folder_extract_thread(void *data)
 {
        ms_comm_msg_s *extract_data = NULL;
-       int err;
-       int ret;
+       int ret = MS_MEDIA_ERR_NONE;
        void **handle = NULL;
        int scan_type;
        ms_user_storage_type_e storage_type;
@@ -205,9 +204,11 @@ gboolean msc_folder_extract_thread(void *data)
                uid = extract_data->uid;
 
                /*connect to media db, if conneting is failed, db updating is stopped*/
-               err = ms_connect_db(&handle, uid);
-               if (err != MS_MEDIA_ERR_NONE)
-                       continue;
+               ret = ms_connect_db(&handle, uid);
+               if (ret != MS_MEDIA_ERR_NONE) {
+                       MS_DBG_ERR("ms_connect_db failed");
+                       goto NEXT;
+               }
 
                scan_type = extract_data->msg_type;
 
@@ -237,8 +238,10 @@ gboolean msc_folder_extract_thread(void *data)
                end_flag = extract_data->result ? LAST_EVENT : NORMAL_EVENT;
 
                ret = ms_user_get_storage_type(uid, extract_data->msg, &storage_type);
-               if (ret != MS_MEDIA_ERR_NONE)
+               if (ret != MS_MEDIA_ERR_NONE) {
                        MS_DBG_ERR("ms_user_get_storage_type failed");
+                       goto NEXT;
+               }
 
                ret = __msc_check_extract_stop_status(extract_data->msg_type, storage_type, update_path, extract_data->pid, end_flag);
 
@@ -269,6 +272,10 @@ NEXT:
                malloc_trim(0);
 
                if (extract_data->result) {
+                       /*send notification*/
+                       char *folder_uuid = NULL;
+                       ms_get_folder_id(handle, storage_id, extract_data->msg, &folder_uuid);
+                       ms_send_dir_update_noti(handle, storage_id, update_path, folder_uuid, MS_ITEM_UPDATE, extract_data->pid);
                        extract_data->msg_type = MS_MSG_EXTRACTOR_COMPLETE;
                        msc_send_result(ret, extract_data);
                }
@@ -322,8 +329,7 @@ _POWEROFF:
 gboolean msc_storage_extract_thread(void *data)
 {
        ms_comm_msg_s *extract_data = NULL;
-       int ret;
-       int err;
+       int ret = MS_MEDIA_ERR_NONE;
        void **handle = NULL;
        ms_user_storage_type_e storage_type = MS_STORAGE_INTERNAL;
        int scan_type;
@@ -358,8 +364,8 @@ gboolean msc_storage_extract_thread(void *data)
                uid = extract_data->uid;
 
                /*connect to media db, if conneting is failed, db updating is stopped*/
-               err = ms_connect_db(&handle, uid);
-               if (err != MS_MEDIA_ERR_NONE) {
+               ret = ms_connect_db(&handle, uid);
+               if (ret != MS_MEDIA_ERR_NONE) {
                        MS_DBG_ERR("ms_connect_db falied!");
                        continue;
                }
@@ -402,8 +408,10 @@ gboolean msc_storage_extract_thread(void *data)
                }
 
                ret = ms_user_get_storage_type(uid, extract_data->msg, &storage_type);
-               if (ret != MS_MEDIA_ERR_NONE)
+               if (ret != MS_MEDIA_ERR_NONE) {
                        MS_DBG_ERR("ms_user_get_storage_type failed");
+                       goto NEXT;
+               }
 
                /*extract meta*/
                ret = __msc_folder_bulk_extract(handle, extract_data->storage_id, storage_type, update_path, scan_type, end_flag, extract_data->pid, uid, &io_err_count, end_flag);
@@ -436,6 +444,9 @@ gboolean msc_storage_extract_thread(void *data)
                        MS_DBG_WARN("extract_data->result == TRUE, MS_STORAGE_SCAN_COMPLETE");
                        ms_set_storage_scan_status(handle, extract_data->storage_id, MEDIA_EXTRACT_COMPLETE, uid);
                        __msc_set_storage_extract_status(MS_STORAGE_SCAN_COMPLETE);
+
+                       /* send notification */
+                       ms_send_dir_update_noti(handle, extract_data->storage_id, update_path, NULL, MS_ITEM_UPDATE, extract_data->pid);
                        /* set vconf key db extract status */
                        __msc_extract_set_db_status(MS_DB_UPDATED);
                        if (msc_get_disc_stg_scan_status()) {
index 496ef82..173bb9e 100755 (executable)
@@ -1066,7 +1066,6 @@ gboolean msc_directory_scan_thread(void *data)
        int index = 0;
        ms_user_storage_type_e 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;
        char *folder_uuid = NULL;
        uid_t uid = MEDIA_DEFAULT_UID;
 
@@ -1086,9 +1085,11 @@ gboolean msc_directory_scan_thread(void *data)
                uid = scan_data->uid;
 
                /*connect to media db, if conneting is failed, db updating is stopped*/
-               err = ms_connect_db(&handle, uid);
-               if (err != MS_MEDIA_ERR_NONE)
-                       continue;
+               ret = ms_connect_db(&handle, uid);
+               if (ret != MS_MEDIA_ERR_NONE) {
+                       MS_DBG_ERR("ms_connect_db failed");
+                       goto NEXT;
+               }
 
                /*check remain space*/
                err = __msc_check_remain_space(uid);
@@ -1099,9 +1100,11 @@ gboolean msc_directory_scan_thread(void *data)
                }
 
                scan_type = scan_data->msg_type;
-               err = ms_user_get_storage_type(uid, scan_data->msg, &storage_type);
-               if (err != MS_MEDIA_ERR_NONE)
+               ret = ms_user_get_storage_type(uid, scan_data->msg, &storage_type);
+               if (ret != MS_MEDIA_ERR_NONE) {
                        MS_DBG_ERR("ms_user_get_storage_type failed");
+                       goto NEXT;
+               }
 
                storage_id = strdup(scan_data->storage_id);
                if (storage_id == NULL) {
@@ -1130,15 +1133,12 @@ gboolean msc_directory_scan_thread(void *data)
                if (g_file_test(scan_data->msg, G_FILE_TEST_IS_DIR)) {
                        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_WARN("[%s] already exist", scan_data->msg);
                        } else {
-                               noti_type = MS_ITEM_INSERT;
                                MS_DBG_WARN("[%s] new insert path", scan_data->msg);
                        }
                } else {
                        /*directory is deleted*/
-                       noti_type = MS_ITEM_DELETE;
                        scan_type = MS_MSG_DIRECTORY_SCANNING;
                        scan_data->msg_type = MS_MSG_DIRECTORY_SCANNING;
 
@@ -1264,10 +1264,10 @@ gboolean msc_directory_scan_thread(void *data)
                if (ms_delete_invalid_folder(handle, storage_id, storage_type, scan_data->uid) != MS_MEDIA_ERR_NONE)
                        MS_DBG_ERR("deleting invalid folders in storage failed");
 
-               if (ret != MS_MEDIA_ERR_SCANNER_FORCE_STOP) {
+               /*if (ret != MS_MEDIA_ERR_SCANNER_FORCE_STOP) {
                        MS_DBG_INFO("working normally");
                        ms_send_dir_update_noti(handle, storage_id, scan_data->msg, folder_uuid, noti_type, scan_data->pid);
-               }
+               }*/
 
 SCAN_DONE:
                MS_DBG_WARN("storage_id = [%s], dir Path = [%s]", storage_id, scan_data->msg);
@@ -1340,8 +1340,7 @@ int __msc_check_pvr_svc()
 gboolean msc_storage_scan_thread(void *data)
 {
        ms_comm_msg_s *scan_data = NULL;
-       int ret;
-       int err;
+       int ret = MS_MEDIA_ERR_NONE;
        void **handle = NULL;
        ms_user_storage_type_e storage_type = MS_USER_STORAGE_INTERNAL;
        int scan_type;
@@ -1372,13 +1371,17 @@ gboolean msc_storage_scan_thread(void *data)
                uid = scan_data->uid;
 
                /*connect to media db, if conneting is failed, db updating is stopped*/
-               err = ms_connect_db(&handle, uid);
-               if (err != MS_MEDIA_ERR_NONE)
-                       continue;
+               ret = ms_connect_db(&handle, uid);
+               if (ret != MS_MEDIA_ERR_NONE) {
+                       MS_DBG_ERR("ms_connect_db failed");
+                       goto NEXT;
+               }
 
-               err = ms_user_get_storage_type(uid, scan_data->msg, &storage_type);
-               if (err != MS_MEDIA_ERR_NONE)
+               ret = ms_user_get_storage_type(uid, scan_data->msg, &storage_type);
+               if (ret != MS_MEDIA_ERR_NONE) {
                        MS_DBG_ERR("ms_user_get_storage_type failed");
+                       goto NEXT;
+               }
 
                update_path = g_strndup(scan_data->msg, scan_data->msg_size);
                if (!MS_STRING_VALID(update_path)) {
@@ -1387,9 +1390,8 @@ gboolean msc_storage_scan_thread(void *data)
                        goto NEXT;
                }
 
-               err = __msc_check_memory_status(uid);
-               if (err != MS_MEDIA_ERR_NONE) {
-                       ret = err;
+               ret = __msc_check_memory_status(uid);
+               if (ret != MS_MEDIA_ERR_NONE) {
                        ms_set_storage_scan_status(handle, scan_data->storage_id, MEDIA_SCAN_STOP, uid);
                        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, uid);
@@ -1427,7 +1429,7 @@ gboolean msc_storage_scan_thread(void *data)
                        ms_delete_invalid_items(handle, scan_data->storage_id, storage_type, uid);
 
                /* send notification */
-               ms_send_dir_update_noti(handle, scan_data->storage_id, update_path, NULL, MS_ITEM_UPDATE, scan_data->pid);
+               /*ms_send_dir_update_noti(handle, scan_data->storage_id, update_path, NULL, MS_ITEM_UPDATE, scan_data->pid);*/
 
                if (ret == MS_MEDIA_ERR_SCANNER_FORCE_STOP) {
                        ms_set_storage_scan_status(handle, scan_data->storage_id, MEDIA_SCAN_STOP, uid);
index bc78d65..2880034 100755 (executable)
@@ -279,6 +279,7 @@ int msc_send_result(int result, ms_comm_msg_s *res_data)
        return res;
 }
 
+/* define of  SUPPORT_PARTIAL_EVENT is disabled, send partial result will not be active */ 
 int msc_send_result_partial(int result, ms_msg_type_e msg_type, int pid, const char *msg)
 {
 #ifdef SUPPORT_PARTIAL_EVENT