Add pid handling logic at db handle provider
authorJunghyun Yeon <jungh.yeon@samsung.com>
Mon, 8 Mar 2021 07:50:58 +0000 (16:50 +0900)
committerJunghyun Yeon <jungh.yeon@samsung.com>
Mon, 8 Mar 2021 07:50:58 +0000 (16:50 +0900)
Signed-off-by: Junghyun Yeon <jungh.yeon@samsung.com>
src/common/database/abstract_db_handler.cc
src/common/database/db_handle_provider.cc
src/common/database/db_handle_provider.hh
src/common/request_handler/get_appinfo_request_handler.cc

index 0168e6b..3a46d10 100644 (file)
@@ -227,9 +227,9 @@ AbstractDBHandler::~AbstractDBHandler() {
 std::vector<std::string> AbstractDBHandler::GetDBPath() {
   std::vector<std::string> db_path;
   if (db_type_ == DB_TYPE_FILE_PKGDB) {
-    db_path = DBHandleProvider::GetInst(uid_).GetParserDBPath();
+    db_path = DBHandleProvider::GetInst(uid_).GetParserDBPath(pid_);
   } else if (db_type_ == DB_TYPE_FILE_CERTDB) {
-    db_path.emplace_back(DBHandleProvider::GetInst(uid_).GetCertDBPath());
+    db_path.emplace_back(DBHandleProvider::GetInst(uid_).GetCertDBPath(pid_));
   }
 
   return db_path;
index 8e7c7ab..d65e691 100644 (file)
@@ -20,6 +20,7 @@
 #include "pkgmgr-info.h"
 #include "pkgmgrinfo_debug.h"
 
+#include <algorithm>
 #include <vector>
 
 #ifdef LOG_TAG
@@ -89,10 +90,16 @@ DBHandleProvider& DBHandleProvider::GetInst(uid_t uid) {
   return *prov;
 }
 
-std::vector<std::string> DBHandleProvider::GetParserDBPath() {
+std::vector<std::string> DBHandleProvider::GetParserDBPath(int pid) {
   std::unique_lock<std::mutex> u(lock_);
   std::vector<std::string> db_path_list;
-  if (is_memory_) {
+  bool is_file_access = is_memory_;
+  std::vector<int>::iterator it = std::find(pid_list_.begin(),
+      pid_list_.end(), pid);
+  if (it == pid_list_.end())
+    is_file_access = true;
+
+  if (is_file_access) {
     db_path_list.emplace_back(parser_memory_db_path_);
     if (IsUserRequest(uid_))
       db_path_list.emplace_back(global_parser_memory_db_path_);
@@ -104,9 +111,15 @@ std::vector<std::string> DBHandleProvider::GetParserDBPath() {
   return db_path_list;
 }
 
-std::string DBHandleProvider::GetCertDBPath() {
+std::string DBHandleProvider::GetCertDBPath(int pid) {
   std::unique_lock<std::mutex> u(lock_);
-  if (is_memory_)
+  bool is_file_access = is_memory_;
+  std::vector<int>::iterator it = std::find(pid_list_.begin(),
+      pid_list_.end(), pid);
+  if (it == pid_list_.end())
+    is_file_access = true;
+
+  if (is_file_access)
     return cert_memory_db_path_;
   else
     return cert_file_db_path_;
index a9daba7..c1eb90c 100644 (file)
@@ -38,8 +38,8 @@ class EXPORT_API DBHandleProvider {
  public:
   ~DBHandleProvider() = default;
   static DBHandleProvider& GetInst(uid_t uid);
-  std::vector<std::string> GetParserDBPath();
-  std::string GetCertDBPath();
+  std::vector<std::string> GetParserDBPath(int pid);
+  std::string GetCertDBPath(int pid);
   void SetMemoryMode(bool flag);
 
  private:
@@ -60,6 +60,7 @@ class EXPORT_API DBHandleProvider {
   std::string cert_memory_db_path_;
   std::string cert_file_db_path_;
   static bool is_memory_;
+  std::vector<int> pid_list_;
   std::mutex lock_;
 };
 
index 0d53cf9..33ad9ab 100644 (file)
@@ -38,6 +38,7 @@ bool GetAppinfoRequestHandler::HandleRequest(unsigned char* data, int size,
   }
 
   AppInfoDBHandler db(parcel->GetUid());
+  db.SetPID(GetPID());
   db.SetLocale(locale);
   db.SetFilter(const_cast<pkgmgrinfo_filter_x*>(parcel->GetFilter()));
   int ret = db.Execute();