Change to get db path condition
authorChanggyu Choi <changyu.choi@samsung.com>
Tue, 16 Mar 2021 07:34:44 +0000 (16:34 +0900)
committer연정현/Tizen Platform Lab(SR)/Staff Engineer/삼성전자 <jungh.yeon@samsung.com>
Wed, 17 Mar 2021 00:49:33 +0000 (09:49 +0900)
Add parameter that is "write" flag.
If use GetParserDBPath() or GetCertDBPath() with write=true flag,
then return file db path.

Signed-off-by: Changgyu Choi <changyu.choi@samsung.com>
src/common/database/abstract_db_handler.cc
src/common/database/db_handle_provider.cc
src/common/database/db_handle_provider.hh

index 5950513..b73ba4f 100644 (file)
@@ -238,11 +238,12 @@ AbstractDBHandler::~AbstractDBHandler() {
 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_);
+    db_path = DBHandleProvider::GetInst(uid_).GetParserDBPath(pid_,
+        op_type_ == OPERATION_TYPE_WRITE);
   else if (db_type_ == DB_TYPE_FILE_CERTDB)
     db_path.emplace_back(
-        std::make_pair(
-            DBHandleProvider::GetInst(uid_).GetCertDBPath(pid_), uid_));
+        std::make_pair(DBHandleProvider::GetInst(uid_).GetCertDBPath(pid_,
+           op_type_ == OPERATION_TYPE_WRITE), uid_));
 
   return db_path;
 }
index 3a989b5..d7988cf 100644 (file)
@@ -101,14 +101,14 @@ DBHandleProvider& DBHandleProvider::GetInst(uid_t uid) {
 }
 
 std::vector<std::pair<std::string, uid_t>> DBHandleProvider::GetParserDBPath(
-    pid_t pid) {
+    pid_t pid, bool write) {
   std::unique_lock<std::recursive_mutex> u(lock_);
   std::unique_lock<std::recursive_mutex> gu(global_lock_);
   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 (is_memory_ && pid_list_.find(pid) == pid_list_.end() && !write) {
     if (uid_ > REGULAR_USER)
       db_path_list.emplace_back(std::make_pair(parser_memory_db_path_, uid_));
     db_path_list.emplace_back(
@@ -130,13 +130,13 @@ std::vector<std::pair<std::string, uid_t>> DBHandleProvider::GetParserDBPath(
   return db_path_list;
 }
 
-std::string DBHandleProvider::GetCertDBPath(pid_t pid) {
+std::string DBHandleProvider::GetCertDBPath(pid_t pid, bool write) {
   std::unique_lock<std::recursive_mutex> u(lock_);
   std::unique_lock<std::recursive_mutex> gu(global_lock_);
   if (is_memory_ != is_memory_global_)
     SetMemoryMode(pid, is_memory_global_);
 
-  if (is_memory_ && pid_list_.find(pid) == pid_list_.end())
+  if ((is_memory_ && pid_list_.find(pid) == pid_list_.end()) && !write)
     return cert_memory_db_path_;
   else
     return cert_file_db_path_;
index 07effc7..adc007d 100644 (file)
@@ -40,8 +40,8 @@ class EXPORT_API DBHandleProvider {
  public:
   ~DBHandleProvider() = default;
   static DBHandleProvider& GetInst(uid_t uid);
-  std::vector<std::pair<std::string, uid_t>> GetParserDBPath(int pid);
-  std::string GetCertDBPath(int pid);
+  std::vector<std::pair<std::string, uid_t>> GetParserDBPath(int pid, bool write);
+  std::string GetCertDBPath(int pid, bool write);
   void SetMemoryMode(int pid, bool flag);
 
  private: