From 19b466e7e4e2c41e2a31dca1f101f8a64bede897 Mon Sep 17 00:00:00 2001 From: Minje Ahn Date: Wed, 29 May 2019 11:29:30 +0900 Subject: [PATCH] Change folder scanning Fixed an issue where media could not be seen during folder scan Change-Id: I6e5b9ec780b4a96a0b6876c579fee928f3cb02bf Signed-off-by: Minje Ahn --- src/common/media-svc-media-folder.c | 88 +---------------------------- src/include/common/media-svc-media-folder.h | 2 - 2 files changed, 1 insertion(+), 89 deletions(-) diff --git a/src/common/media-svc-media-folder.c b/src/common/media-svc-media-folder.c index 24b3cd4..94f7288 100755 --- a/src/common/media-svc-media-folder.c +++ b/src/common/media-svc-media-folder.c @@ -52,32 +52,6 @@ int _media_svc_get_folder_id_by_foldername(sqlite3 *handle, const char *storage_ return ret; } -int _media_svc_get_folder_id_by_foldername_with_validity(sqlite3 *handle, const char *storage_id, const char *folder_name, char *folder_id, uid_t uid, int *validity) -{ - int ret = MS_MEDIA_ERR_NONE; - sqlite3_stmt *sql_stmt = NULL; - char *sql = NULL; - - sql = sqlite3_mprintf("SELECT folder_id, validity FROM %q WHERE storage_uuid='%q' AND folder_path='%q';", MEDIA_SVC_DB_TABLE_FOLDER, storage_id, folder_name); - - ret = _media_svc_sql_prepare_to_step(handle, sql, &sql_stmt); - if (ret != MS_MEDIA_ERR_NONE) { - if (ret == MS_MEDIA_ERR_DB_NO_RECORD) - media_svc_debug("there is no folder."); - else - media_svc_error("error when _media_svc_get_folder_id_by_foldername_with_validity. err = [%d]", ret); - - return ret; - } - - SAFE_STRLCPY(folder_id, (const char *)sqlite3_column_text(sql_stmt, 0), MEDIA_SVC_UUID_SIZE + 1); - *validity = (int)sqlite3_column_int(sql_stmt, 1); - - SQLITE3_FINALIZE(sql_stmt); - - return ret; -} - static int __media_svc_append_folder(bool is_direct, const char *storage_id, ms_user_storage_type_e storage_type, const char *folder_id, const char *folder_path, uid_t uid) { int ret = MS_MEDIA_ERR_NONE; @@ -203,73 +177,13 @@ static int __media_svc_get_and_append_parent_folder(sqlite3 *handle, bool is_dir return MS_MEDIA_ERR_NONE; } -static int __media_svc_update_parent_folder_validity(sqlite3 *handle, bool is_direct, const char *storage_id, const char *path, uid_t uid) -{ - int ret = MS_MEDIA_ERR_NONE; - unsigned int next_pos = 0; - char *next = NULL; - char *dir_path = NULL; - const char *token = "/"; - bool folder_search_end = false; - char *internal_path = NULL; - - ret = ms_user_get_internal_root_path(uid, &internal_path); - media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "Fail to get root path"); - - if (STRING_VALID(internal_path) && (strncmp(path, internal_path, strlen(internal_path)) == 0)) - next_pos = strlen(internal_path); - else if (STRING_VALID(MEDIA_ROOT_PATH_SDCARD) && strncmp(path, MEDIA_ROOT_PATH_SDCARD, strlen(MEDIA_ROOT_PATH_SDCARD)) == 0) - next_pos = strlen(MEDIA_ROOT_PATH_SDCARD); - else if (STRING_VALID(MEDIA_ROOT_PATH_EXTERNAL) && strncmp(path, MEDIA_ROOT_PATH_EXTERNAL, strlen(MEDIA_ROOT_PATH_EXTERNAL)) == 0) - next_pos = strlen(MEDIA_ROOT_PATH_EXTERNAL); - else if (STRING_VALID(MEDIA_ROOT_PATH_DISC) && strncmp(path, MEDIA_ROOT_PATH_DISC, strlen(MEDIA_ROOT_PATH_DISC)) == 0) - next_pos = strlen(MEDIA_ROOT_PATH_DISC); - else { - media_svc_error("Invalid Path"); - media_svc_sec_error("Invalid Path [%s], internal_path [%s]", path, internal_path); - SAFE_FREE(internal_path); - return MS_MEDIA_ERR_INTERNAL; - } - - SAFE_FREE(internal_path); - - while (!folder_search_end) { - next = strstr(path + next_pos, token); - if (next != NULL) { - next_pos = (next - path); - dir_path = strndup(path, next_pos); - next_pos++; - } else { - dir_path = strndup(path, strlen(path)); - folder_search_end = true; - media_svc_sec_debug("End Path [%s]", dir_path); - } - - if (STRING_VALID(MEDIA_ROOT_PATH_EXTERNAL) && (g_strcmp0(dir_path, MEDIA_ROOT_PATH_EXTERNAL) == 0)) { - /*To avoid insert MEDIA_ROOT_PATH_EXTERNAL path*/ - SAFE_FREE(dir_path); - continue; - } - - ret = _media_svc_set_folder_validity(handle, is_direct, storage_id, dir_path, 1, false, uid); - SAFE_FREE(dir_path); - media_svc_retvm_if(ret != MS_MEDIA_ERR_NONE, ret, "Fail to set folder validity"); - } - - return MS_MEDIA_ERR_NONE; -} - int _media_svc_get_and_append_folder(sqlite3 *handle, bool is_direct, const char *storage_id, const char *path, ms_user_storage_type_e storage_type, char *folder_id, uid_t uid) { int ret = MS_MEDIA_ERR_NONE; - int validity = -1; - - ret = _media_svc_get_folder_id_by_foldername_with_validity(handle, storage_id, path, folder_id, uid, &validity); + ret = _media_svc_get_folder_id_by_foldername(handle, storage_id, path, folder_id, uid); if (ret == MS_MEDIA_ERR_DB_NO_RECORD) ret = __media_svc_get_and_append_parent_folder(handle, is_direct, storage_id, path, storage_type, folder_id, uid); - else if (ret == MS_MEDIA_ERR_NONE && validity == 0) - ret = __media_svc_update_parent_folder_validity(handle, is_direct, storage_id, path, uid); return ret; } diff --git a/src/include/common/media-svc-media-folder.h b/src/include/common/media-svc-media-folder.h index 412d6de..50bc6a6 100755 --- a/src/include/common/media-svc-media-folder.h +++ b/src/include/common/media-svc-media-folder.h @@ -27,13 +27,11 @@ #include int _media_svc_get_folder_id_by_foldername(sqlite3 *handle, const char *storage_id, const char *folder_name, char *folder_id, uid_t uid); -int _media_svc_get_folder_id_by_foldername_with_validity(sqlite3 *handle, const char *storage_id, const char *folder_name, char *folder_id, uid_t uid, int *validity); int _media_svc_update_folder_modified_time_by_folder_uuid(const char *folder_uuid, const char *folder_path, uid_t uid); int _media_svc_get_and_append_folder(sqlite3 *handle, bool is_direct, const char *storage_id, const char *path, ms_user_storage_type_e storage_type, char *folder_id, uid_t uid); int _media_svc_get_and_append_folder_id_by_path(sqlite3 *handle, bool is_direct, const char *storage_id, const char *path, ms_user_storage_type_e storage_type, char *folder_id, uid_t uid); int _media_svc_get_and_append_folder_id_by_folder_path(sqlite3 *handle, const char *storage_id, const char *path, ms_user_storage_type_e storage_type, uid_t uid); int _media_svc_set_folder_validity(sqlite3 *handle, bool is_direct, const char *storage_id, const char *start_path, int validity, bool is_recursive, uid_t uid); - int _media_svc_count_folder_with_path(sqlite3 *handle, const char *storage_id, const char *path, int *count); #endif /*_MEDIA_SVC_MEDIA_FOLDER_H_*/ -- 2.7.4