Merge get_extract_list() and update_one_extract_item() 83/239783/4
authorMinje Ahn <minje.ahn@samsung.com>
Wed, 29 Jul 2020 23:08:36 +0000 (08:08 +0900)
committerMinje Ahn <minje.ahn@samsung.com>
Thu, 30 Jul 2020 07:21:23 +0000 (16:21 +0900)
This patch only affects media-scanner-v2.

Change-Id: Ib8e8a1a70e870d6faea89cddbe870c1767d0bf8b
Signed-off-by: Minje Ahn <minje.ahn@samsung.com>
src/common/include/media-common-db-svc.h
src/common/media-common-db-svc.c
src/scanner-v2/media-scanner-extract-v2.c
src/scanner-v2/media-scanner-scan-v2.c

index b110fbe..5f6a413 100755 (executable)
@@ -68,8 +68,7 @@ typedef int (*UPDATE_ITEM_META)(sqlite3 *, uid_t);
 
 typedef int (*DELETE_INVALID_FOLDER_BY_PATH)(sqlite3 *, const char *, const char *, uid_t);
 typedef int (*CHECK_FOLDER_EXIST)(sqlite3*, const char*, const char*);
-typedef int (*GET_EXTRACT_LIST)(sqlite3*, const char*, int, int, const char*, int, uid_t, void*);
-typedef int (*UPDATE_ONE_EXTRACT_ITEM)(sqlite3*, const char*, int, void *);
+typedef int (*GET_AND_EXTRACT_MEDIA)(sqlite3*, const char*, int, const char *);
 typedef int (*GET_MEDIA_TYPE)(const char *, int *);
 typedef int (*REFRESH_ITEM)(sqlite3 *, const char *, const char *, uid_t);
 
@@ -117,8 +116,7 @@ bool ms_check_support_media_type(const char *path);
 void ms_register_start(bool noti_status, int pid);
 void ms_register_end(uid_t uid);
 
-int ms_get_extract_list(sqlite3 *handle, const char* storage_id, int storage_type, int scan_type, const char* path, int is_end, uid_t uid, void* array);
-int ms_update_one_extract_item(sqlite3 *handle, const char* storage_id, int storage_type, void* data);
+int ms_get_and_extract_media(sqlite3 *handle, const char *storage_id, int scan_type, const char *path);
 
 void ms_batch_commit_enable(bool noti_enable, int pid);
 void ms_batch_commit_disable(uid_t uid);
index bfef515..71b0d8b 100644 (file)
@@ -65,8 +65,7 @@ enum func_list {
        eDELETE_INVALID_FOLDER_BY_PATH,
        eCHECK_FOLDER_EXIST,
        eGET_MEDIA_TYPE,
-       eGET_EXTRACT_LIST,
-       eUPDATE_ONE_EXTRACT_ITEM,
+       eGET_AND_EXTRACT_MEDIA,
        eREFRESH_ITEM,
        eFUNC_MAX
 };
@@ -104,8 +103,7 @@ int ms_load_functions(void)
                "delete_invalid_folder_by_path",
                "check_folder_exist",
                "get_media_type",
-               "get_extract_list",
-               "update_one_extract_item",
+               "get_and_extract_media",
                "refresh_item",
                };
 
@@ -213,11 +211,11 @@ static int __ms_check_item_exist(sqlite3 *handle, const char *storage_id, const
                        } else {
                                *modified = false;
 #ifdef _USE_TVPD_MODE
-                               charfolder_id_media = NULL;
-                               charfolder_id_folder = NULL;
+                               char *folder_id_media = NULL;
+                               char *folder_id_folder = NULL;
 
                                folder_id_media = (char *)sqlite3_column_text(sql_stmt, 4);
-                               charfolder_path = NULL;
+                               char *folder_path = NULL;
                                folder_path = g_path_get_dirname(path);
                                ret = ms_get_folder_id(handle, storage_id, folder_path, &folder_id_folder);
                                g_free(folder_path);
@@ -310,7 +308,7 @@ int ms_validity_change_all_items(sqlite3 *handle, const char *storage_id, bool v
        return ret;
 }
 
-int ms_insert_item_batch(sqlite3 *handle, const charstorage_id, const char *path, uid_t uid)
+int ms_insert_item_batch(sqlite3 *handle, const char *storage_id, const char *path, uid_t uid)
 {
        int ret = MS_MEDIA_ERR_NONE;
        ms_user_storage_type_e storage_type = -1;
@@ -326,7 +324,7 @@ int ms_insert_item_batch(sqlite3 *handle, const char* storage_id, const char *pa
        return ret;
 }
 
-int ms_scan_item_batch(sqlite3 *handle, const charstorage_id, const char *path, uid_t uid)
+int ms_scan_item_batch(sqlite3 *handle, const char *storage_id, const char *path, uid_t uid)
 {
        int ret = MS_MEDIA_ERR_NONE;
        ms_user_storage_type_e storage_type;
@@ -342,26 +340,16 @@ int ms_scan_item_batch(sqlite3 *handle, const char* storage_id, const char *path
        return ret;
 }
 
-int ms_get_extract_list(sqlite3 *handle, const char* storage_id, int storage_type, int scan_type, const char* path, int is_end, uid_t uid, void* array)
+int ms_get_and_extract_media(sqlite3 *handle, const char *storage_id, int scan_type, const char *path)
 {
        int ret = MS_MEDIA_ERR_NONE;
 
-       ret = ((GET_EXTRACT_LIST)func_array[eGET_EXTRACT_LIST])(handle, storage_id, storage_type, scan_type, path, is_end, uid, array); /*dlopen*/
+       ret = ((GET_AND_EXTRACT_MEDIA)func_array[eGET_AND_EXTRACT_MEDIA])(handle, storage_id, scan_type, path); /*dlopen*/
        MS_DBG_RETVM_IF(ret != MS_MEDIA_ERR_NONE, ret, "GET_EXTRACT_LIST failed [%d]", ret);
 
        return ret;
 }
 
-int ms_update_one_extract_item(sqlite3 *handle, const char* storage_id, int storage_type, void* data)
-{
-       int ret = MS_MEDIA_ERR_NONE;
-
-       ret = ((UPDATE_ONE_EXTRACT_ITEM)func_array[eUPDATE_ONE_EXTRACT_ITEM])(handle, storage_id, storage_type, data); /*dlopen*/
-       MS_DBG_RETVM_IF(ret != MS_MEDIA_ERR_NONE, ret, "UPDATE_ONE_EXTRACT_ITEM failed [%d]", ret);
-
-       return ret;
-}
-
 int ms_delete_invalid_items(sqlite3 *handle, const char *storage_id, uid_t uid)
 {
        int ret = MS_MEDIA_ERR_NONE;
@@ -446,7 +434,7 @@ int ms_set_folder_item_validity(sqlite3 *handle, const char *storage_id, const c
        return ret;
 }
 
-int ms_delete_invalid_items_in_folder(sqlite3 *handle, const char* storage_id, const char*path, bool is_recursive, uid_t uid)
+int ms_delete_invalid_items_in_folder(sqlite3 *handle, const char *storage_id, const char *path, bool is_recursive, uid_t uid)
 {
        int ret = MS_MEDIA_ERR_NONE;
 
index 7aefbd4..d427eb6 100644 (file)
@@ -50,7 +50,6 @@ bool g_directory_extract_processing;
 static int stg_extract_status;
 
 static GMutex extract_item_mutex;
-static GMutex decode_mutex;
 
 static s_extract_item* cancel_extract_item = NULL;
 static s_extract_item* cur_extract_item = NULL;
@@ -58,10 +57,8 @@ static s_extract_item* cur_extract_item = NULL;
 static GCond extract_data_cond;
 static GMutex extract_data_mutex;
 #define VCONFKEY_PRIVATE_EXTRACTSTATUS "db/private/extractstatus"
-#define LAST_EVENT 1
-#define NORMAL_EVENT 0
 
-static int __msc_check_extract_stop_status(int scan_type, const char *start_path, int pid, bool is_end);
+static int __msc_check_extract_stop_status(int scan_type, const char *start_path, int pid);
 static void __msc_set_storage_extract_status(ms_storage_scan_status_e status);
 static void __msc_get_storage_extract_status(ms_storage_scan_status_e *status);
 static void __msc_resume_extract(void);
@@ -72,12 +69,6 @@ static void __msc_set_cur_extract_item(const char* cur_path, int pid);
 static void __msc_del_cur_extract_item(void);
 static void __msc_del_extract_blocked_path(const char* blocked_path);
 
-
-typedef struct {
-       int media_type;
-       char *path;
-} ms_item_info_s;
-
 void msc_init_extract_thread(void)
 {
        if (!storage_extract_queue) storage_extract_queue = g_async_queue_new();
@@ -88,7 +79,6 @@ void msc_init_extract_thread(void)
        g_mutex_init(&extract_data_mutex);
 
        g_mutex_init(&extract_item_mutex);
-       g_mutex_init(&decode_mutex);
 
        g_cond_init(&extract_data_cond);
 }
@@ -103,66 +93,39 @@ void msc_deinit_extract_thread(void)
        g_mutex_clear(&extract_data_mutex);
 
        g_mutex_clear(&extract_item_mutex);
-       g_mutex_clear(&decode_mutex);
 
        g_cond_clear(&extract_data_cond);
 }
 
-static int __msc_folder_bulk_extract(sqlite3 *handle, const char *storage_id, int storage_type, const char *path, int scan_type, int pid, uid_t uid, bool is_end)
+static int __msc_folder_bulk_extract(sqlite3 *handle, const char *storage_id, const char *path, int scan_type, int pid)
 {
-       MS_DBG_WARN("begin of __msc_folder_bulk_extract");
        int ret = MS_MEDIA_ERR_NONE;
-       GArray *data_array = NULL;
-       ms_item_info_s* db_data = NULL;
-       int sleep_count = 0;
 
-       ret = ms_get_extract_list(handle, storage_id, storage_type, scan_type, path, is_end, uid, (void *)&data_array);
-       MS_DBG_RETVM_IF(ret != MS_MEDIA_ERR_NONE, MS_MEDIA_ERR_NONE, "ms_get_extract_list failed!!!");
-       MS_DBG_RETVM_IF(!data_array, MS_MEDIA_ERR_NONE, "data_array is NULL!!!");
-
-       while (data_array->len != 0) {
-               db_data = NULL;
+       MS_DBG_FENTER();
 
-               ret = __msc_check_extract_stop_status(scan_type, path, pid, is_end);
+       while (1) {
+               ret = __msc_check_extract_stop_status(scan_type, path, pid);
                if (ret == MS_MEDIA_ERR_SCANNER_FORCE_STOP) {
                        MS_DBG_ERR("__msc_folder_bulk_extract MS_MEDIA_ERR_SCANNER_FORCE_STOP");
                        break;
                }
 
-               db_data = g_array_index(data_array, ms_item_info_s*, 0);
-               g_array_remove_index(data_array, 0);
-
-               g_mutex_lock(&decode_mutex);
-               ms_update_one_extract_item(handle, storage_id, storage_type, db_data);
-               g_mutex_unlock(&decode_mutex);
-
-               if (db_data) {
-                       g_free(db_data->path);
-                       g_free(db_data);
-                       db_data = NULL;
-               }
+               ret = ms_get_and_extract_media(handle, storage_id, scan_type, path);
+               if (ret != MS_MEDIA_ERR_NONE) {
+                       if (ret == MS_MEDIA_ERR_DB_NO_RECORD)
+                               MS_DBG("Extract done");
+                       else
+                               MS_DBG_ERR("ms_get_and_extract_media failed!!!");
 
-               if (++sleep_count == 5) {
-                       sleep_count = 0;
-                       usleep(SCAN_SLEEP_TIME);
+                       break;
                }
+               /* Sleep per 10 items. refer to META_UPDATE_MAX */
+               usleep(SCAN_SLEEP_TIME);
        }
 
-       while (data_array->len != 0) {
-               db_data = g_array_index(data_array, ms_item_info_s *, 0);
-               g_array_remove_index(data_array, 0);
-
-               if (db_data) {
-                       g_free(db_data->path);
-                       g_free(db_data);
-                       db_data = NULL;
-               }
-       }
-       g_array_free(data_array, FALSE);
-       data_array = NULL;
+       MS_DBG_FLEAVE();
 
-       MS_DBG_WARN("end of __msc_folder_bulk_extract");
-       return ret;
+       return MS_MEDIA_ERR_NONE;
 }
 
 gpointer msc_folder_extract_thread(gpointer data)
@@ -171,11 +134,9 @@ gpointer msc_folder_extract_thread(gpointer data)
        int ret = MS_MEDIA_ERR_NONE;
        sqlite3 *handle = NULL;
        int scan_type;
-       ms_user_storage_type_e storage_type;
        char *storage_id = NULL;
        char *update_path = NULL;
        uid_t uid = MEDIA_DEFAULT_UID;
-       int end_flag = NORMAL_EVENT;
        ms_noti_type_e noti_type = MS_ITEM_INSERT;
 
        while (1) {
@@ -191,7 +152,7 @@ gpointer msc_folder_extract_thread(gpointer data)
                g_directory_extract_processing = true;
                uid = extract_data->uid;
 
-               /*connect to media db, if conneting is failed, db updating is stopped*/
+               /*connect to media db, if connecting is failed, db updating is stopped*/
                ret = ms_connect_db(&handle, uid);
                if (ret != MS_MEDIA_ERR_NONE) {
                        MS_DBG_ERR("ms_connect_db failed");
@@ -224,15 +185,8 @@ gpointer msc_folder_extract_thread(gpointer data)
                        ret = MS_MEDIA_ERR_INVALID_PARAMETER;
                        goto NEXT;
                }
-               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) {
-                       MS_DBG_ERR("ms_user_get_storage_type failed");
-                       goto NEXT;
-               }
-
-               ret = __msc_check_extract_stop_status(extract_data->msg_type, update_path, extract_data->pid, end_flag);
+               ret = __msc_check_extract_stop_status(extract_data->msg_type, update_path, extract_data->pid);
 
                if (ret == MS_MEDIA_ERR_SCANNER_FORCE_STOP) {
                        MS_DBG_ERR("MS_MEDIA_ERR_SCANNER_FORCE_STOP");
@@ -249,7 +203,7 @@ gpointer msc_folder_extract_thread(gpointer data)
                        goto NEXT;
                }
 
-               ret = __msc_folder_bulk_extract(handle, extract_data->storage_id, storage_type, update_path, scan_type, extract_data->pid, uid, end_flag);
+               ret = __msc_folder_bulk_extract(handle, extract_data->storage_id, update_path, scan_type, extract_data->pid);
 
 NEXT:
                g_directory_extract_processing = false;
@@ -321,7 +275,6 @@ gpointer msc_storage_extract_thread(gpointer data)
        int scan_type;
        char *update_path = NULL;
        uid_t uid = MEDIA_DEFAULT_UID;
-       int end_flag = NORMAL_EVENT;
        int tem_ret = MS_MEDIA_ERR_NONE;
 
        while (1) {
@@ -347,14 +300,13 @@ gpointer msc_storage_extract_thread(gpointer data)
 
                uid = extract_data->uid;
 
-               /*connect to media db, if conneting is failed, db updating is stopped*/
+               /*connect to media db, if connecting is failed, db updating is stopped*/
                ret = ms_connect_db(&handle, uid);
                if (ret != MS_MEDIA_ERR_NONE) {
                        MS_DBG_ERR("ms_connect_db falied!");
                        continue;
                }
 
-               end_flag = extract_data->result ? LAST_EVENT : NORMAL_EVENT;
                update_path = g_strdup(extract_data->msg);
                if (!MS_STRING_VALID(update_path)) {
                        MS_DBG_ERR("Invalid update_path");
@@ -386,12 +338,12 @@ gpointer msc_storage_extract_thread(gpointer data)
                }
 
                /*extract meta*/
-               ret = __msc_folder_bulk_extract(handle, extract_data->storage_id, storage_type, update_path, scan_type, extract_data->pid, uid, end_flag);
+               ret = __msc_folder_bulk_extract(handle, extract_data->storage_id, update_path, scan_type, extract_data->pid);
                MS_DBG_WARN("extract PAUSE");
                __msc_pause_extract();
                MS_DBG_WARN("extract RESUME");
 
-               tem_ret = __msc_check_extract_stop_status(extract_data->msg_type, update_path, extract_data->pid, end_flag);
+               tem_ret = __msc_check_extract_stop_status(extract_data->msg_type, update_path, extract_data->pid);
                if (tem_ret == MS_MEDIA_ERR_SCANNER_FORCE_STOP) {
                        ms_set_storage_scan_status(handle, extract_data->storage_id, MEDIA_EXTRACT_STOP, uid);
                        __msc_set_storage_extract_status(MS_STORAGE_SCAN_META_STOP);
@@ -638,15 +590,12 @@ static void __msc_del_extract_blocked_path(const char* blocked_path)
        MS_DBG_FLEAVE();
 }
 
-static int __msc_check_extract_stop_status(int scan_type, const char *start_path, int pid, bool is_end)
+static int __msc_check_extract_stop_status(int scan_type, const char *start_path, int pid)
 {
        int ret = MS_MEDIA_ERR_NONE;
 
        /*check poweroff status*/
-       if (_msc_is_power_off()) {
-               ret = MS_MEDIA_ERR_SCANNER_FORCE_STOP;
-               goto END;
-       }
+       MS_DBG_RETV_IF(_msc_is_power_off(), MS_MEDIA_ERR_SCANNER_FORCE_STOP);
 
        if (scan_type == MS_MSG_DIRECTORY_SCANNING || scan_type == MS_MSG_DIRECTORY_SCANNING_NON_RECURSIVE) {
                g_mutex_lock(&extract_req_mutex);
@@ -690,17 +639,11 @@ static int __msc_check_extract_stop_status(int scan_type, const char *start_path
                                MS_DBG_SERR("Receive blocked message[%s][%s]. STOP extract!!", g_extract_blocked_path, start_path);
                                ret = MS_MEDIA_ERR_SCANNER_FORCE_STOP;
                        }
-                       if (is_end) {
-                               MS_DBG("[END REQUEST]");
-                               /*MS_SAFE_FREE(g_extract_blocked_path);*/
-                       } else {
-                               MS_DBG("[NOT END REQUEST]");
-                       }
                }
 
                g_mutex_unlock(&extract_blocked_mutex);
        }
-END:
+
        return ret;
 }
 
index 287b37d..273c0f8 100644 (file)
@@ -527,7 +527,7 @@ static int __msc_dir_scan_for_storage(sqlite3 *handle, const char *storage_id, c
        /* make new array for storing directory */
        dir_array = g_array_new(FALSE, FALSE, sizeof(char*));
 
-       /* add first direcotiry to directory array */
+       /* add first directory to directory array */
        new_start_path = g_strdup(start_path);
 
        g_array_append_val(dir_array, start_path);
@@ -979,7 +979,7 @@ gpointer msc_directory_scan_thread(gpointer data)
                g_directory_scan_processing2 = DIR_SCAN_NON_RECURSIVE;
                uid = scan_data->uid;
 
-               /*connect to media db, if conneting is failed, db updating is stopped*/
+               /*connect to media db, if connecting is failed, db updating is stopped*/
                ret = ms_connect_db(&handle, uid);
                if (ret != MS_MEDIA_ERR_NONE) {
                        MS_DBG_ERR("ms_connect_db failed");
@@ -1145,21 +1145,9 @@ gpointer msc_directory_scan_thread(gpointer data)
                MS_DBG_WARN("folder scan done, sent cb event path = [%.*s]", MAX_MSG_SIZE, scan_data->msg);
                __msc_call_dir_scan_cb();
 
-               /*delete invalid folder first, then delete invalid item, avoid to folder was deleted but item not when unmount*/
-               /*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 (!ms_delete_invalid_items(handle, storage_id, storage_type, scan_data->uid))
-                       MS_DBG_ERR("deleting invalid items in storage failed");*/
-
                /*revert to 3.0,folder scan should only delete invalid in folder instead of delete invalid in storage*/
-               if (ms_delete_invalid_items_in_folder(handle, storage_id, scan_data->msg, is_recursive, uid)  != MS_MEDIA_ERR_NONE) {
+               if (ms_delete_invalid_items_in_folder(handle, storage_id, scan_data->msg, is_recursive, uid) != MS_MEDIA_ERR_NONE)
                        MS_DBG_ERR("deleting invalid items in folder failed");
-               }
-
-               /*if (ret != MS_MEDIA_ERR_SCANNER_FORCE_STOP) {
-                       ms_send_dir_update_noti(scan_data->msg, folder_uuid, noti_type, scan_data->pid);
-               }*/
 
 SCAN_DONE:
                MS_DBG_WARN("storage_id = [%s], dir Path = [%.*s], pid = [%d]", storage_id, MAX_MSG_SIZE, scan_data->msg, scan_data->pid);
@@ -1266,7 +1254,7 @@ gpointer msc_storage_scan_thread(gpointer data)
 
                uid = scan_data->uid;
 
-               /*connect to media db, if conneting is failed, db updating is stopped*/
+               /*connect to media db, if connecting is failed, db updating is stopped*/
                ret = ms_connect_db(&handle, uid);
                if (ret != MS_MEDIA_ERR_NONE) {
                        MS_DBG_ERR("ms_connect_db failed");
@@ -1400,7 +1388,7 @@ static int __msc_make_file_list(char *file_path, GPtrArray **path_array, uid_t u
                /* check valid path */
                ret = ms_check_ignore_dir(path, uid);
                if (ret != MS_MEDIA_ERR_NONE) {
-                       MS_DBG_SERR("invalide path : %s", path);
+                       MS_DBG_SERR("Invalid path : %s", path);
                        g_free(path);
                        continue;
                }