Change db handle provider to store parser dbpath
authorJunghyun Yeon <jungh.yeon@samsung.com>
Sat, 6 Mar 2021 03:52:36 +0000 (12:52 +0900)
committerJunghyun Yeon <jungh.yeon@samsung.com>
Sat, 6 Mar 2021 03:52:36 +0000 (12:52 +0900)
Signed-off-by: Junghyun Yeon <jungh.yeon@samsung.com>
src/common/database/db_handle_provider.cc
src/common/database/db_handle_provider.hh

index c20ba70..714c43a 100644 (file)
@@ -20,6 +20,8 @@
 #include "pkgmgr-info.h"
 #include "pkgmgrinfo_debug.h"
 
+#include <vector>
+
 #ifdef LOG_TAG
 #undef LOG_TAG
 #endif
@@ -29,6 +31,10 @@ namespace {
 
 constexpr uid_t REGULAR_USER = 5000;
 
+uid_t GetGlobalUID() {
+  return tzplatform_getuid(TZ_SYS_GLOBALAPP_USER);
+}
+
 uid_t ConvertUID(uid_t uid) {
   if (uid < REGULAR_USER)
     return tzplatform_getuid(TZ_SYS_GLOBALAPP_USER);
@@ -47,7 +53,11 @@ bool DBHandleProvider::is_memory_ = false;
 DBHandleProvider::DBHandleProvider(uid_t uid) : uid_(uid),
     parser_memory_db_handle_(nullptr, sqlite3_close_v2),
     cert_memory_db_handle_(nullptr, sqlite3_close_v2) {
-  char* tmp_path = getUserPkgParserDBPathUID(uid_);
+  char *tmp_path = getUserPkgParserDBPathUID(GetGlobalUID());
+  global_parser_file_db_path_ = tmp_path;
+  free(tmp_path);
+
+  tmp_path = getUserPkgParserDBPathUID(uid_);
   parser_file_db_path_ = tmp_path;
   free(tmp_path);
 
@@ -55,6 +65,7 @@ DBHandleProvider::DBHandleProvider(uid_t uid) : uid_(uid),
   cert_file_db_path_ = tmp_path;
   free(tmp_path);
 
+  global_parser_memory_db_path_ = "file:parserdb?mode=memory&cache=shared";
   parser_memory_db_path_ = "file:parserdb" +
       std::to_string(static_cast<int>(uid_)) + "?mode=memory&cache=shared";
   cert_memory_db_path_ = "file:certdb" +
@@ -73,12 +84,17 @@ DBHandleProvider& DBHandleProvider::GetInst(uid_t uid) {
   return *prov;
 }
 
-std::string DBHandleProvider::GetParserDBPath() {
+std::vector<std::string> DBHandleProvider::GetParserDBPath() {
   std::unique_lock<std::mutex> u(lock_);
-  if (is_memory_)
-    return parser_memory_db_path_;
-  else
-    return parser_file_db_path_;
+  std::vector<std::string> db_path_list;
+  if (is_memory_) {
+    db_path_list.emplace_back(parser_memory_db_path_);
+    db_path_list.emplace_back(global_parser_memory_db_path_);
+  } else {
+    db_path_list.emplace_back(parser_file_db_path_);
+    db_path_list.emplace_back(global_parser_file_db_path_);
+  }
+  return db_path_list;
 }
 
 std::string DBHandleProvider::GetCertDBPath() {
index 3a5d1e0..57fba66 100644 (file)
@@ -24,6 +24,7 @@
 #include <memory>
 #include <mutex>
 #include <unordered_map>
+#include <vector>
 
 #include "shared_object.hh"
 
@@ -37,7 +38,7 @@ class EXPORT_API DBHandleProvider {
  public:
   ~DBHandleProvider() = default;
   static DBHandleProvider& GetInst(uid_t uid);
-  std::string GetParserDBPath();
+  std::vector<std::string> GetParserDBPath();
   std::string GetCertDBPath();
   void SetMemoryMode(bool flag);
 
@@ -52,7 +53,9 @@ class EXPORT_API DBHandleProvider {
   std::unique_ptr<sqlite3, decltype(sqlite3_close_v2)*> parser_memory_db_handle_;
   std::unique_ptr<sqlite3, decltype(sqlite3_close_v2)*> cert_memory_db_handle_;
   std::string parser_memory_db_path_;
+  std::string global_parser_memory_db_path_;
   std::string parser_file_db_path_;
+  std::string global_parser_file_db_path_;
   std::string cert_memory_db_path_;
   std::string cert_file_db_path_;
   static bool is_memory_;