Change logic of delivering db path and handle
authorJunghyun Yeon <jungh.yeon@samsung.com>
Fri, 12 Mar 2021 05:54:03 +0000 (14:54 +0900)
committer연정현/Tizen Platform Lab(SR)/Staff Engineer/삼성전자 <jungh.yeon@samsung.com>
Fri, 12 Mar 2021 09:25:15 +0000 (18:25 +0900)
UID will be included with it.

Signed-off-by: Junghyun Yeon <jungh.yeon@samsung.com>
13 files changed:
src/appinfo_internal.c
src/common/database/abstract_db_handler.cc
src/common/database/abstract_db_handler.hh
src/common/database/appinfo_db_handler.cc
src/common/database/cert_get_db_handler.cc
src/common/database/cert_set_db_handler.cc
src/common/database/db_handle_provider.cc
src/common/database/db_handle_provider.hh
src/common/database/depinfo_db_handler.cc
src/common/database/pkg_get_db_handler.cc
src/common/database/pkg_set_db_handler.cc
src/common/database/query_handler.cc
src/pkginfo_internal.c

index f16785c..54c4958 100644 (file)
@@ -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;
 }
index 3296c46..505e140 100644 (file)
@@ -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<std::string> AbstractDBHandler::GetDBPath() {
-  std::vector<std::string> db_path;
+std::vector<std::pair<std::string, uid_t>> AbstractDBHandler::GetDBPath() {
+  std::vector<std::pair<std::string, uid_t>> 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<sqlite3*> AbstractDBHandler::GetConnection() {
+std::vector<std::pair<sqlite3*, uid_t>> AbstractDBHandler::GetConnection() {
   return db_handle_list_;
 }
 
index 8b0d292..31c7342 100644 (file)
@@ -55,17 +55,17 @@ class EXPORT_API AbstractDBHandler {
  protected:
   bool Connect();
   int GetPID();
-  std::vector<sqlite3*> GetConnection();
+  std::vector<std::pair<sqlite3*, uid_t>> GetConnection();
   std::string GetLocale();
 
  private:
-  std::vector<std::string> GetDBPath();
+  std::vector<std::pair<std::string, uid_t>> GetDBPath();
   DBType db_type_ = DB_TYPE_NONE;
   OperationType op_type_ = OPERATION_TYPE_NONE;
   uid_t uid_;
   pid_t pid_;
   std::string locale_;
-  std::vector<sqlite3*> db_handle_list_;
+  std::vector<std::pair<sqlite3*, uid_t>> db_handle_list_;
 };
 
 }  // namespace database
index 5e88e43..0aed7f9 100644 (file)
@@ -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<sqlite3*> conn_list = GetConnection();
+  std::vector<std::pair<sqlite3*, uid_t>> 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);
index 18c0651..b15d604 100644 (file)
@@ -49,7 +49,7 @@ int CertGetDBHandler::Execute() {
     return ret;
 
   handle_ = static_cast<pkgmgr_certinfo_x*>(handle);
-  sqlite3* conn = GetConnection().front();
+  sqlite3* conn = GetConnection().front().first;
   ret = certinfo_internal_get(conn, pkgid_.c_str(), uid_, handle_);
 
   return ret;
index 54a5e17..1b41cc8 100644 (file)
@@ -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;
index 67bfc5a..0bdf0e1 100644 (file)
@@ -98,28 +98,28 @@ DBHandleProvider& DBHandleProvider::GetInst(uid_t uid) {
   return *prov;
 }
 
-std::vector<std::string> DBHandleProvider::GetParserDBPath(pid_t pid) {
+std::vector<std::pair<std::string, uid_t>> DBHandleProvider::GetParserDBPath(pid_t pid) {
   std::unique_lock<std::recursive_mutex> u(lock_);
   std::unique_lock<std::recursive_mutex> gu(global_lock_);
-  std::vector<std::string> db_path_list;
+  std::vector<std::pair<std::string, uid_t>> 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;
index e315b64..07effc7 100644 (file)
@@ -40,7 +40,7 @@ class EXPORT_API DBHandleProvider {
  public:
   ~DBHandleProvider() = default;
   static DBHandleProvider& GetInst(uid_t uid);
-  std::vector<std::string> GetParserDBPath(int pid);
+  std::vector<std::pair<std::string, uid_t>> GetParserDBPath(int pid);
   std::string GetCertDBPath(int pid);
   void SetMemoryMode(int pid, bool flag);
 
index 13441d4..94ac734 100644 (file)
@@ -46,11 +46,11 @@ int DepInfoGetDBHandler::Execute() {
     return PMINFO_R_ERROR;
   }
   GList *list = nullptr;
-  std::vector<sqlite3*> conn_list = GetConnection();
+  std::vector<std::pair<sqlite3*, uid_t>> 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;
   }
index 8752a20..81f4b48 100644 (file)
@@ -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<sqlite3*> conn_list = GetConnection();
+  std::vector<std::pair<sqlite3*, uid_t>> 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);
index 6dc6e90..d7cb78e 100644 (file)
@@ -52,8 +52,8 @@ int PkgSetDBHandler::Execute() {
   int ret = 0;
 
   DBHandleProvider::GetInst(uid_).SetMemoryMode(GetPID(), true);
-  std::vector<sqlite3*> conn_list = GetConnection();
-  sqlite3* conn = conn_list.front();
+  std::vector<std::pair<sqlite3*, uid_t>> 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) {
index 20c1312..f6c4b87 100644 (file)
@@ -56,10 +56,10 @@ int QueryHandler::Execute() {
   }
 
   int ret = PMINFO_R_ERROR;
-  std::vector<sqlite3*> conn_list = GetConnection();
+  std::vector<std::pair<sqlite3*, uid_t>> 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);
index 4b5dace..5b7def9 100644 (file)
@@ -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;
 }