From 53510752988757bdaa2124111f105617ff3db194 Mon Sep 17 00:00:00 2001 From: Junghyun Yeon Date: Fri, 12 Mar 2021 14:54:03 +0900 Subject: [PATCH] Change logic of delivering db path and handle UID will be included with it. Signed-off-by: Junghyun Yeon --- src/appinfo_internal.c | 3 --- src/common/database/abstract_db_handler.cc | 25 ++++++++++++++----------- src/common/database/abstract_db_handler.hh | 6 +++--- src/common/database/appinfo_db_handler.cc | 4 ++-- src/common/database/cert_get_db_handler.cc | 2 +- src/common/database/cert_set_db_handler.cc | 2 +- src/common/database/db_handle_provider.cc | 18 +++++++++--------- src/common/database/db_handle_provider.hh | 2 +- src/common/database/depinfo_db_handler.cc | 4 ++-- src/common/database/pkg_get_db_handler.cc | 4 ++-- src/common/database/pkg_set_db_handler.cc | 4 ++-- src/common/database/query_handler.cc | 6 +++--- src/pkginfo_internal.c | 4 ---- 13 files changed, 40 insertions(+), 44 deletions(-) diff --git a/src/appinfo_internal.c b/src/appinfo_internal.c index f16785c..54c4958 100644 --- a/src/appinfo_internal.c +++ b/src/appinfo_internal.c @@ -669,8 +669,5 @@ API int appinfo_internal_filter_get_list(sqlite3 *db, ret = _appinfo_get_applications(db, uid, uid, locale, filter, PMINFO_APPINFO_GET_ALL, appinfo_list); - if (!g_hash_table_size(appinfo_list) && uid != GLOBAL_USER) - ret = _appinfo_get_applications(db, GLOBAL_USER, uid, locale, filter, - PMINFO_APPINFO_GET_ALL, appinfo_list); return ret; } diff --git a/src/common/database/abstract_db_handler.cc b/src/common/database/abstract_db_handler.cc index 3296c46..505e140 100644 --- a/src/common/database/abstract_db_handler.cc +++ b/src/common/database/abstract_db_handler.cc @@ -224,15 +224,15 @@ AbstractDBHandler::AbstractDBHandler(uid_t uid, int pid) { AbstractDBHandler::~AbstractDBHandler() { // Is this necessary? for (auto db_handle : db_handle_list_) - sqlite3_close(db_handle); + sqlite3_close(db_handle.first); } -std::vector AbstractDBHandler::GetDBPath() { - std::vector db_path; +std::vector> AbstractDBHandler::GetDBPath() { + std::vector> db_path; if (db_type_ == DB_TYPE_FILE_PKGDB) { db_path = DBHandleProvider::GetInst(uid_).GetParserDBPath(pid_); } else if (db_type_ == DB_TYPE_FILE_CERTDB) { - db_path.emplace_back(DBHandleProvider::GetInst(uid_).GetCertDBPath(pid_)); + db_path.emplace_back(std::make_pair(DBHandleProvider::GetInst(uid_).GetCertDBPath(pid_), uid_)); } return db_path; @@ -247,17 +247,20 @@ bool AbstractDBHandler::Connect() { int ret = 0; sqlite3* db; for (auto dbpath : dbpath_list) { - if (op_type_ == OPERATION_TYPE_READ) - ret = __open_read_db(dbpath.c_str(), &db, SQLITE_OPEN_READONLY | + if (op_type_ == OPERATION_TYPE_READ) { + ret = __open_read_db(dbpath.first.c_str(), &db, SQLITE_OPEN_READONLY | SQLITE_OPEN_URI); - else - ret = __open_write_db(uid_, dbpath.c_str(), &db, + } else { + if (dbpath.second != uid_) + continue; + ret = __open_write_db(uid_, dbpath.first.c_str(), &db, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE); - // TODO: if write request has received, only one database should be delivered + } + if (ret != SQLITE_OK) return false; - db_handle_list_.emplace_back(db); + db_handle_list_.emplace_back(std::make_pair(db, dbpath.second)); } return true; @@ -277,7 +280,7 @@ bool AbstractDBHandler::Connect() { */ } -std::vector AbstractDBHandler::GetConnection() { +std::vector> AbstractDBHandler::GetConnection() { return db_handle_list_; } diff --git a/src/common/database/abstract_db_handler.hh b/src/common/database/abstract_db_handler.hh index 8b0d292..31c7342 100644 --- a/src/common/database/abstract_db_handler.hh +++ b/src/common/database/abstract_db_handler.hh @@ -55,17 +55,17 @@ class EXPORT_API AbstractDBHandler { protected: bool Connect(); int GetPID(); - std::vector GetConnection(); + std::vector> GetConnection(); std::string GetLocale(); private: - std::vector GetDBPath(); + std::vector> GetDBPath(); DBType db_type_ = DB_TYPE_NONE; OperationType op_type_ = OPERATION_TYPE_NONE; uid_t uid_; pid_t pid_; std::string locale_; - std::vector db_handle_list_; + std::vector> db_handle_list_; }; } // namespace database diff --git a/src/common/database/appinfo_db_handler.cc b/src/common/database/appinfo_db_handler.cc index 5e88e43..0aed7f9 100644 --- a/src/common/database/appinfo_db_handler.cc +++ b/src/common/database/appinfo_db_handler.cc @@ -61,10 +61,10 @@ int AppInfoDBHandler::Execute() { GHashTable* list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, __free_applications); - std::vector conn_list = GetConnection(); + std::vector> conn_list = GetConnection(); int ret = PMINFO_R_OK; for (auto conn : conn_list) { - ret = appinfo_internal_filter_get_list(conn, filter_, uid_, + ret = appinfo_internal_filter_get_list(conn.first, filter_, conn.second, GetLocale().c_str(), list); if (ret == PMINFO_R_ERROR) { _LOGE("Failed to appinfo_internal_filter_get_list (%d)", ret); diff --git a/src/common/database/cert_get_db_handler.cc b/src/common/database/cert_get_db_handler.cc index 18c0651..b15d604 100644 --- a/src/common/database/cert_get_db_handler.cc +++ b/src/common/database/cert_get_db_handler.cc @@ -49,7 +49,7 @@ int CertGetDBHandler::Execute() { return ret; handle_ = static_cast(handle); - sqlite3* conn = GetConnection().front(); + sqlite3* conn = GetConnection().front().first; ret = certinfo_internal_get(conn, pkgid_.c_str(), uid_, handle_); return ret; diff --git a/src/common/database/cert_set_db_handler.cc b/src/common/database/cert_set_db_handler.cc index 54a5e17..1b41cc8 100644 --- a/src/common/database/cert_set_db_handler.cc +++ b/src/common/database/cert_set_db_handler.cc @@ -40,7 +40,7 @@ int CertSetDBHandler::Execute() { return PMINFO_R_ERROR; DBHandleProvider::GetInst(uid_).SetMemoryMode(GetPID(), true); - sqlite3 *conn = GetConnection().front(); + sqlite3 *conn = GetConnection().front().first; int ret = certinfo_internal_set(conn, handle_->pkgid, handle_, uid_); return ret; diff --git a/src/common/database/db_handle_provider.cc b/src/common/database/db_handle_provider.cc index 67bfc5a..0bdf0e1 100644 --- a/src/common/database/db_handle_provider.cc +++ b/src/common/database/db_handle_provider.cc @@ -98,28 +98,28 @@ DBHandleProvider& DBHandleProvider::GetInst(uid_t uid) { return *prov; } -std::vector DBHandleProvider::GetParserDBPath(pid_t pid) { +std::vector> DBHandleProvider::GetParserDBPath(pid_t pid) { std::unique_lock u(lock_); std::unique_lock gu(global_lock_); - std::vector db_path_list; + std::vector> db_path_list; if (is_memory_ != is_memory_global_) SetMemoryMode(pid, is_memory_global_); if (is_memory_ && pid_list_.find(pid) == pid_list_.end()) { if (uid_ > REGULAR_USER) - db_path_list.emplace_back(parser_memory_db_path_); - db_path_list.emplace_back(global_parser_memory_db_path_); + db_path_list.emplace_back(std::make_pair(parser_memory_db_path_, uid_)); + db_path_list.emplace_back(std::make_pair(global_parser_memory_db_path_, GetGlobalUID())); } else { if (uid_ > REGULAR_USER) - db_path_list.emplace_back(parser_file_db_path_); - db_path_list.emplace_back(global_parser_file_db_path_); + db_path_list.emplace_back(std::make_pair(parser_file_db_path_, uid_)); + db_path_list.emplace_back(std::make_pair(global_parser_file_db_path_, GetGlobalUID())); } if (db_path_list.size() == 1) { - LOGD("global db path : %s", db_path_list[0].c_str()); + LOGD("global db path : %s", db_path_list[0].first.c_str()); } else { - LOGD("local db path : %s", db_path_list[0].c_str()); - LOGD("global db path : %s", db_path_list[1].c_str()); + LOGD("local db path : %s", db_path_list[0].first.c_str()); + LOGD("global db path : %s", db_path_list[1].first.c_str()); } return db_path_list; diff --git a/src/common/database/db_handle_provider.hh b/src/common/database/db_handle_provider.hh index e315b64..07effc7 100644 --- a/src/common/database/db_handle_provider.hh +++ b/src/common/database/db_handle_provider.hh @@ -40,7 +40,7 @@ class EXPORT_API DBHandleProvider { public: ~DBHandleProvider() = default; static DBHandleProvider& GetInst(uid_t uid); - std::vector GetParserDBPath(int pid); + std::vector> GetParserDBPath(int pid); std::string GetCertDBPath(int pid); void SetMemoryMode(int pid, bool flag); diff --git a/src/common/database/depinfo_db_handler.cc b/src/common/database/depinfo_db_handler.cc index 13441d4..94ac734 100644 --- a/src/common/database/depinfo_db_handler.cc +++ b/src/common/database/depinfo_db_handler.cc @@ -46,11 +46,11 @@ int DepInfoGetDBHandler::Execute() { return PMINFO_R_ERROR; } GList *list = nullptr; - std::vector conn_list = GetConnection(); + std::vector> conn_list = GetConnection(); int ret = PMINFO_R_OK; for (auto& conn : conn_list) { ret = pkginfo_internal_filter_get_depends_on( - conn, pkgid_.c_str(), &list); + conn.first, pkgid_.c_str(), &list); if (ret == PMINFO_R_ERROR) break; } diff --git a/src/common/database/pkg_get_db_handler.cc b/src/common/database/pkg_get_db_handler.cc index 8752a20..81f4b48 100644 --- a/src/common/database/pkg_get_db_handler.cc +++ b/src/common/database/pkg_get_db_handler.cc @@ -64,10 +64,10 @@ int PkgGetDBHandler::Execute() { GHashTable* list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, __free_packages); - std::vector conn_list = GetConnection(); + std::vector> conn_list = GetConnection(); int ret = PMINFO_R_OK; for (auto& conn : conn_list) { - ret = pkginfo_internal_filter_get_list(conn, filter_, uid_, + ret = pkginfo_internal_filter_get_list(conn.first, filter_, conn.second, GetLocale().c_str(), list); if (ret == PMINFO_R_ERROR) { _LOGE("Failed to pkginfo_internal_filter_get_list (%d)", ret); diff --git a/src/common/database/pkg_set_db_handler.cc b/src/common/database/pkg_set_db_handler.cc index 6dc6e90..d7cb78e 100644 --- a/src/common/database/pkg_set_db_handler.cc +++ b/src/common/database/pkg_set_db_handler.cc @@ -52,8 +52,8 @@ int PkgSetDBHandler::Execute() { int ret = 0; DBHandleProvider::GetInst(uid_).SetMemoryMode(GetPID(), true); - std::vector conn_list = GetConnection(); - sqlite3* conn = conn_list.front(); + std::vector> conn_list = GetConnection(); + sqlite3* conn = conn_list.front().first; if (write_type_ == Insert) { ret = pkgmgr_parser_insert_pkg_info(conn, package_, uid_); } else if (write_type_ == Update) { diff --git a/src/common/database/query_handler.cc b/src/common/database/query_handler.cc index 20c1312..f6c4b87 100644 --- a/src/common/database/query_handler.cc +++ b/src/common/database/query_handler.cc @@ -56,10 +56,10 @@ int QueryHandler::Execute() { } int ret = PMINFO_R_ERROR; - std::vector conn_list = GetConnection(); + std::vector> conn_list = GetConnection(); if (GetOpType() == OPERATION_TYPE_READ) { for (auto& conn : conn_list) { - ret = get_query_result(conn, query_[0].c_str(), &list, &row, &col); + ret = get_query_result(conn.first, query_[0].c_str(), &list, &row, &col); if (ret == PMINFO_R_ERROR) { _LOGE("Failed to execute query"); return ret; @@ -90,7 +90,7 @@ int QueryHandler::Execute() { queries[i++] = query.c_str(); for (auto& conn : conn_list) { - ret = execute_write_queries(conn, queries, query_.size()); + ret = execute_write_queries(conn.first, queries, query_.size()); // TODO: error check? } free(queries); diff --git a/src/pkginfo_internal.c b/src/pkginfo_internal.c index 4b5dace..5b7def9 100644 --- a/src/pkginfo_internal.c +++ b/src/pkginfo_internal.c @@ -632,10 +632,6 @@ API int pkginfo_internal_filter_get_list( ret = _pkginfo_get_packages(db, uid, locale, filter, PMINFO_PKGINFO_GET_ALL, pkginfo_list); - if (ret == PMINFO_R_OK && uid != GLOBAL_USER) - ret = _pkginfo_get_packages(db, GLOBAL_USER, locale, filter, - PMINFO_PKGINFO_GET_ALL, pkginfo_list); - return ret; } -- 2.7.4