Add api to update cache using pkgid 59/300559/4
authorilho kim <ilho159.kim@samsung.com>
Wed, 25 Oct 2023 06:39:51 +0000 (15:39 +0900)
committerilho kim <ilho159.kim@samsung.com>
Mon, 30 Oct 2023 07:27:13 +0000 (16:27 +0900)
Change-Id: I1693bd1b3644167b1fa2338251aab32524de96e8
Signed-off-by: ilho kim <ilho159.kim@samsung.com>
16 files changed:
parser/include/pkgmgr_parser_db.h
parser/src/pkgmgr_parser_db.c
src/common/parcel/command_parcelable.cc
src/common/parcel/command_parcelable.hh
src/manager/pkginfo_manager.cc
src/manager/pkginfo_manager.h
src/server/database/db_handle_provider.cc
src/server/database/db_handle_provider.hh
src/server/database/pkg_set_db_handler.cc
src/server/database/remove_cache_db_handler.cc [deleted file]
src/server/database/remove_cache_db_handler.hh [deleted file]
src/server/database/update_pending_cache_handler.cc [new file with mode: 0644]
src/server/database/update_pending_cache_handler.hh [new file with mode: 0644]
src/server/request_handler/command_request_handler.cc
src/server/worker_thread.cc
test/unit_tests/test_parcel.cc

index 4be306df9af2e9d50d8d5aeffa68aa4dc39b6e9d..0fd5eb8f34032816a12ce1626dfa07722d5cf20a 100644 (file)
@@ -585,6 +585,8 @@ int pkgmgr_parser_create_and_initialize_db(uid_t uid);
 int pkgmgr_parser_clear_cache_memory_db(void);
 int pkgmgr_parser_clear_cache_usr_memory_db(uid_t uid);
 
+int pkgmgr_parser_update_pending_cache(const char *pkgid);
+
 /** @} */
 #ifdef __cplusplus
 }
index 866e529f5534a2d8c1ebbe5ebbd7823d59b8876d..9f256a9c17403b53856cf49835fbc6ff4ed3c488 100644 (file)
@@ -646,3 +646,8 @@ API int pkgmgr_parser_clear_cache_memory_db(void)
 {
        return pkgmgr_parser_clear_cache_usr_memory_db(__getuid());
 }
+
+API int pkgmgr_parser_update_pending_cache(const char *pkgid)
+{
+       return _parser_update_pending_cache(pkgid);
+}
index 83649b8394867a65308a6f1db0785faa697ca966..c6f47475b8bfaded4aaa920ea5b5d8f757afb722 100644 (file)
@@ -26,32 +26,45 @@ CommandParcelable::CommandParcelable()
     : AbstractParcelable(0, ParcelableType::Command),
     uid_(0), cmd_(CommandType::Unknown) {}
 
-CommandParcelable::CommandParcelable(uid_t uid, CommandType cmd)
-    : AbstractParcelable(0, ParcelableType::Command), uid_(uid), cmd_(cmd) {}
+CommandParcelable::CommandParcelable(uid_t uid, CommandType cmd,
+    std::vector<std::string> args)
+        : AbstractParcelable(0, ParcelableType::Command),
+            uid_(uid), cmd_(cmd), args_(std::move(args)) {}
 
 void CommandParcelable::WriteToParcel(tizen_base::Parcel* parcel) const {
   AbstractParcelable::WriteToParcel(parcel);
   parcel->WriteUInt32(static_cast<int>(uid_));
   parcel->WriteUInt32(static_cast<int>(cmd_));
+  parcel->WriteUInt32(static_cast<int>(args_.size()));
+  for (const auto& arg : args_)
+    parcel->WriteString(arg);
 }
 
 void CommandParcelable::ReadFromParcel(tizen_base::Parcel* parcel) {
   AbstractParcelable::ReadFromParcel(parcel);
 
-  uint32_t cmd, uid;
+  uint32_t cmd, uid, arg_size;
 
   parcel->ReadUInt32(&uid);
   uid_ = uid;
   parcel->ReadUInt32(&cmd);
   cmd_ = static_cast<CommandType>(cmd);
+  parcel->ReadUInt32(&arg_size);
+  for (uint32_t i = 0; i < arg_size; ++i)
+    args_.emplace_back(parcel->ReadString());
 }
 
 CommandType CommandParcelable::GetCmd() {
   return cmd_;
 }
+
 void CommandParcelable::SetCmd(CommandType cmd) {
   cmd_ = cmd;
 }
 
+const std::vector<std::string>& CommandParcelable::GetArgs() {
+  return args_;
+}
+
 }  // namespace parcel
 }  // namespace pkgmgr_common
index b3006c630cda8ccf4dbff0a333265e204d69dfad..102d7803365338858b9dfb8c5106bb24f547893e 100644 (file)
@@ -9,6 +9,7 @@
 enum CommandType {
   Unknown = -1,
   RemoveCache,
+  UpdatePendingCache
 };
 
 namespace pkgmgr_common {
@@ -21,8 +22,9 @@ namespace parcel {
 class EXPORT_API CommandParcelable : public AbstractParcelable {
  public:
   CommandParcelable();
-  CommandParcelable(uid_t uid, CommandType cmd);
+  CommandParcelable(uid_t uid, CommandType cmd, std::vector<std::string> args);
   CommandType GetCmd();
+  const std::vector<std::string>& GetArgs();
   void SetCmd(CommandType cmd);
   void WriteToParcel(tizen_base::Parcel* parcel) const override;
   void ReadFromParcel(tizen_base::Parcel* parcel) override;
@@ -30,6 +32,7 @@ class EXPORT_API CommandParcelable : public AbstractParcelable {
  private:
   uid_t uid_;
   CommandType cmd_;
+  std::vector<std::string> args_;
 };
 
 }  // namespace parcel
index c6d5bb1308153222b1a8513e0444a26cef59c58b..1145bc90b4657e7078d203e46e42a32af7efa6c6 100644 (file)
@@ -927,7 +927,7 @@ extern "C" EXPORT_API int _pkginfo_delete_certinfo(const char* pkgid) {
 
 extern "C" EXPORT_API int _parser_clear_cache_memory_db(uid_t uid) {
   std::shared_ptr<pcp::AbstractParcelable> parcelable(
-      new pcp::CommandParcelable(uid, CommandType::RemoveCache));
+      new pcp::CommandParcelable(uid, CommandType::RemoveCache, {}));
 
   pkgmgr_client::PkgInfoClient client(parcelable, uid,
                                       pkgmgr_common::ReqType::COMMAND);
@@ -939,6 +939,21 @@ extern "C" EXPORT_API int _parser_clear_cache_memory_db(uid_t uid) {
       client.GetResultParcel(), pcp::ParcelableType::Result);
 }
 
+extern "C" EXPORT_API int _parser_update_pending_cache(const char* pkgid) {
+  std::shared_ptr<pcp::AbstractParcelable> parcelable(
+      new pcp::CommandParcelable(_getuid(),
+          CommandType::RemoveCache, { pkgid }));
+
+  pkgmgr_client::PkgInfoClient client(parcelable, _getuid(),
+                                      pkgmgr_common::ReqType::COMMAND);
+
+  if (!client.SendRequest())
+    return PMINFO_R_ERROR;
+
+  return  ValidateParcelable(
+      client.GetResultParcel(), pcp::ParcelableType::Result);
+}
+
 static int __create_and_initialize_db(uid_t uid) {
   std::shared_ptr<pcp::AbstractParcelable> parcelable(
       new pcp::CreateDBParcelable(uid));
index 03c0ea00824cf97d3c44bdffdc8c1ae4a4a390ea..9d4ea9405e8a51b2a9dcde9ab03a05d220d1193c 100644 (file)
@@ -95,6 +95,8 @@ int _pkginfo_delete_certinfo(const char *pkgid);
 
 int _parser_clear_cache_memory_db(uid_t uid);
 
+int _parser_update_pending_cache(const char *pkgid);
+
 int _parser_create_and_initialize_db(uid_t uid);
 
 #ifdef __cplusplus
index 516f3b07f38d17462a9ef40b804b839c26fb3ec9..a6b49f18f9600412fd23407da4c1ec9be7dcf7dd 100644 (file)
@@ -126,29 +126,26 @@ DBHandleProvider& DBHandleProvider::GetInst(uid_t uid) {
   return *prov;
 }
 
-std::vector<pid_t> DBHandleProvider::CrashedWriteRequestPIDs() {
+std::unordered_set<pid_t> DBHandleProvider::CrashedWriteRequestPIDs() {
   std::unique_lock<std::shared_mutex> u(pid_list_lock_);
 
   if (writer_pid_list_.empty())
     return {};
 
   LOG(DEBUG) << "Check process count : " << writer_pid_list_.size();
-  std::vector<pid_t> remove_pids;
+  std::unordered_set<pid_t> remove_pids;
   for (pid_t pid : writer_pid_list_) {
     std::string status_path = "/proc/" + std::to_string(pid) + "/status";
 
     int fd = open(status_path.c_str(), O_RDONLY);
     if (fd < 0) {
       LOG(ERROR) << "Process is crashed : " << pid;
-      remove_pids.push_back(pid);
+      remove_pids.emplace(pid);
     } else {
       close(fd);
     }
   }
 
-  for (pid_t pid : remove_pids)
-    writer_pid_list_.erase(pid);
-
   return remove_pids;
 }
 
@@ -218,7 +215,7 @@ int DBHandleProvider::UpdateCache(const tizen_base::Database& db, pid_t pid,
   int ret = internal::GetPkgInfo(db, &tmp_filter, uid_, locale, pkgs);
   if (ret == PMINFO_R_OK) {
     for (auto& [key, val] : pkgs)
-      AddPackage(std::move(key), std::move(val));
+      AddPackage(std::move(val));
   }
 
   if (!GetModifiedTime(dbpath, &end_time))
@@ -251,8 +248,7 @@ int DBHandleProvider::UpdateCache(const tizen_base::Database& db, pid_t pid,
       }
 
       app->privileges = it->second->privileges;
-      std::string appid = app->appid;
-      AddApplication(std::move(appid), std::move(app));
+      AddApplication(std::move(app));
     }
   }
 
@@ -334,9 +330,26 @@ std::vector<std::shared_ptr<package_x>> DBHandleProvider::GetPackages(
   return ret;
 }
 
-void DBHandleProvider::AddPackage(std::string package,
-    std::shared_ptr<package_x> info) {
-  pkg_map_[package] = std::move(info);
+void DBHandleProvider::AddPackage(std::shared_ptr<package_x> info) {
+  pkg_map_[info->package] = std::move(info);
+}
+
+void DBHandleProvider::AddApplication(std::shared_ptr<application_x> info) {
+  std::string appid = info->appid;
+  std::string pkgid = info->package;
+  app_map_[appid] = std::move(info);
+  pkg_app_map_[pkgid].emplace(std::move(appid));
+}
+
+void DBHandleProvider::ErasePackage(const std::string& pkgid) {
+  auto it = pkg_app_map_.find(pkgid);
+  if (it != pkg_app_map_.end()) {
+    for (const auto& app : it->second)
+      app_map_.erase(app);
+    pkg_app_map_.erase(it);
+  }
+
+  pkg_map_.erase(pkgid);
 }
 
 inline bool CheckAppFilters(pkgmgrinfo_filter_x* filter,
@@ -405,74 +418,110 @@ std::vector<std::shared_ptr<application_x>> DBHandleProvider::GetApplications(
   return ret;
 }
 
-void DBHandleProvider::AddApplication(std::string app,
-    std::shared_ptr<application_x> info) {
-  pkg_app_map_[info->package].emplace(app);
-  app_map_[app] = std::move(info);
-}
-
-void DBHandleProvider::InsertPID(pid_t pid) {
+void DBHandleProvider::InsertWriterPID(pid_t pid) {
   std::unique_lock<std::shared_mutex> u(pid_list_lock_);
 
   writer_pid_list_.insert(pid);
 }
 
-bool DBHandleProvider::ErasePID(pid_t pid) {
+bool DBHandleProvider::EraseWriterPID(pid_t pid) {
   std::unique_lock<std::shared_mutex> u(pid_list_lock_);
 
   return writer_pid_list_.erase(pid) == 1;
 }
 
-void DBHandleProvider::RegisterPendingPackageInfo(package_x* info, pid_t pid) {
+void DBHandleProvider::RegisterPendingPackageInfo(
+    const tizen_base::Database& db, package_x* info, pid_t pid, uid_t uid,
+    const std::string& locale, pkgmgr_common::PkgWriteType write_type) {
   if (!info || !info->package)
     return;
 
-  InsertPID(pid);
+  InsertWriterPID(pid);
 
-  pending_pkg_[pid].emplace(info->package);
-}
+  if (write_type != pkgmgr_common::PkgWriteType::Delete) {
+    pkgmgrinfo_filter_x tmp_filter = { 0, };
+    pkgmgrinfo_node_x node = {
+      .prop = E_PMINFO_PKGINFO_PROP_PACKAGE_ID
+    };
+    tmp_filter.cache_flag = true;
+    tmp_filter.list = g_slist_append(tmp_filter.list, (gpointer)&node);
+    std::map<std::string, std::shared_ptr<package_x>> pkgs;
 
-void DBHandleProvider::UpdatePendingPackageInfo(const tizen_base::Database& db,
-    const std::vector<pid_t>& pids, uid_t uid, const std::string& locale) {
-  pkgmgrinfo_filter_x tmp_filter = { 0, };
-  pkgmgrinfo_node_x node = {
-    .prop = E_PMINFO_PKGINFO_PROP_PACKAGE_ID
-  };
-  tmp_filter.cache_flag = true;
-  tmp_filter.list = g_slist_append(tmp_filter.list, (gpointer)&node);
-  std::map<std::string, std::shared_ptr<package_x>> pkgs;
-  for (const pid_t& pid : pids) {
-    for (const auto& pkg : pending_pkg_[pid]) {
-      pkg_map_.erase(pkg);
-      for (auto& appid : pkg_app_map_[pkg]) {
-        app_map_.erase(appid);
+    node.value = const_cast<char*>(info->package);
+    internal::GetPkgInfo(db, &tmp_filter, uid_, locale, pkgs);
+    node.prop = E_PMINFO_APPINFO_PROP_APP_PACKAGE;
+    for (auto& [pkgid, pkg_handle] : pkgs) {
+      node.value = const_cast<char*>(pkgid.c_str());
+      std::vector<std::shared_ptr<application_x>> app_list;
+      internal::GetAppInfo(db, &tmp_filter, uid_, uid, locale, app_list);
+
+      for (auto& app : app_list) {
+        app->privileges = pkg_handle->privileges;
+        pending_app_[pkgid].emplace_back(std::move(app));
       }
 
-      pkg_app_map_.erase(pkg);
-      node.value = const_cast<char*>(pkg.c_str());
-      internal::GetPkgInfo(db, &tmp_filter, uid_, locale, pkgs);
+      pending_pkg_[pkgid] = std::make_pair(pid, std::move(pkg_handle));
     }
 
-    pending_pkg_.erase(pid);
+    g_slist_free(tmp_filter.list);
+  } else {
+    pending_pkg_[info->package] = std::make_pair(pid, nullptr);
+    pending_app_.erase(info->package);
   }
+}
 
-  for (auto& [key, val] : pkgs)
-    AddPackage(key, val);
-
-  node.prop = E_PMINFO_APPINFO_PROP_APP_PACKAGE;
-  for (auto& [key, val] : pkgs) {
-    node.value = val->package;
-    std::vector<std::shared_ptr<application_x>> app_list;
-    internal::GetAppInfo(db, &tmp_filter, uid_, uid, locale, app_list);
+void DBHandleProvider::UpdatePendingPackageInfo(
+    const std::vector<std::string>& pkgids) {
+  for (const auto& pkgid : pkgids) {
+    auto pkg_it = pending_pkg_.find(pkgid);
+    if (pkg_it == pending_pkg_.end())
+      continue;
 
-    for (auto& app : app_list) {
-      app->privileges = val->privileges;
-      std::string appid = app->appid;
-      AddApplication(std::move(appid), std::move(app));
+    ErasePackage(pkgid);
+    auto app_it = pending_app_.find(pkgid);
+    if (app_it != pending_app_.end()) {
+      for (auto& app : app_it->second)
+        AddApplication(std::move(app));
+      pending_app_.erase(app_it);
     }
+
+    if (pkg_it->second.second)
+      AddPackage(std::move(pkg_it->second.second));
+
+    EraseWriterPID(pkg_it->second.first);
+    pending_pkg_.erase(pkg_it);
   }
+}
 
-  g_slist_free(tmp_filter.list);
+void DBHandleProvider::UpdateCrashedWriterPackageInfo(
+    const std::unordered_set<pid_t>& pids) {
+  for (auto it = pending_pkg_.begin(); it != pending_pkg_.end();) {
+    pid_t pid = it->second.first;
+    if (pids.find(pid) == pids.end()) {
+      it++;
+      continue;
+    }
+
+    const auto& pkgid = it->first;
+    auto old_app_it = pkg_app_map_.find(pkgid);
+    if (old_app_it != pkg_app_map_.end()) {
+      for (const auto& app : old_app_it->second)
+        app_map_.erase(app);
+
+      pkg_app_map_.erase(old_app_it);
+    }
+
+    auto app_it = pending_app_.find(pkgid);
+    if (app_it != pending_app_.end()) {
+      for (auto& app : app_it->second)
+        AddApplication(std::move(app));
+      pending_app_.erase(app_it);
+    }
+
+    AddPackage(std::move(it->second.second));
+    EraseWriterPID(it->second.first);
+    it = pending_pkg_.erase(it);
+  }
 }
 
 bool DBHandleProvider::UpdateCachePkg(const tizen_base::Database& db, uid_t uid,
@@ -487,10 +536,9 @@ bool DBHandleProvider::UpdateCachePkg(const tizen_base::Database& db, uid_t uid,
   std::map<std::string, std::shared_ptr<package_x>> pkgs;
   internal::GetPkgInfo(db, &tmp_filter, uid_, locale, pkgs);
   for (auto& [key, val] : pkgs) {
-    AddPackage(key, val);
-    for (auto& appid : pkg_app_map_[key]) {
+    AddPackage(val);
+    for (auto& appid : pkg_app_map_[key])
       app_map_.erase(appid);
-    }
 
     pkg_app_map_.erase(key);
     std::vector<std::shared_ptr<application_x>> app_list;
@@ -499,8 +547,7 @@ bool DBHandleProvider::UpdateCachePkg(const tizen_base::Database& db, uid_t uid,
     internal::GetAppInfo(db, &tmp_filter, uid_, uid, locale, app_list);
     for (auto& app : app_list) {
       app->privileges = val->privileges;
-      std::string appid = app->appid;
-      AddApplication(std::move(appid), std::move(app));
+      AddApplication(std::move(app));
     }
   }
 
@@ -531,8 +578,7 @@ bool DBHandleProvider::UpdateCacheApp(const tizen_base::Database& db, uid_t uid,
 
     pkg_app_map_[app->package].erase(app->appid);
     app->privileges = it->second->privileges;
-    std::string appid = app->appid;
-    AddApplication(std::move(appid), std::move(app));
+    AddApplication(std::move(app));
   }
 
   return true;
@@ -566,8 +612,7 @@ bool DBHandleProvider::UpdateCacheAppByPkgid(const tizen_base::Database& db,
 
   for (auto& app : app_list) {
     app->privileges = pkg->privileges;
-    std::string appid = app->appid;
-    AddApplication(std::move(appid), std::move(app));
+    AddApplication(std::move(app));
   }
 
   g_slist_free(tmp_filter.list);
index e99e1c72fda5c8c856eacec2afdbde142cf9e08b..1323957ff537ab31142a5daa931b4782be4286df 100644 (file)
@@ -30,6 +30,7 @@
 
 #include <database.hpp>
 #include "filter_checker_provider.hh"
+#include "pkg_write_type.hh"
 #include "pkgmgrinfo_basic.h"
 #include "pkgmgrinfo_private.h"
 #include "shared_object.hh"
@@ -45,7 +46,7 @@ class EXPORT_API DBHandleProvider {
  public:
   ~DBHandleProvider() = default;
   static DBHandleProvider& GetInst(uid_t uid);
-  static std::vector<pid_t> CrashedWriteRequestPIDs();
+  static std::unordered_set<pid_t> CrashedWriteRequestPIDs();
   static bool IsWriter(pid_t pid);
   std::vector<std::pair<std::string, uid_t>> GetParserDBPath();
   std::string GetCertDBPath();
@@ -58,9 +59,11 @@ class EXPORT_API DBHandleProvider {
       pid_t pid, pkgmgrinfo_filter_x* filter,
       const std::string& app);
   void TrimCache();
-  void RegisterPendingPackageInfo(package_x* info, pid_t pid);
-  void UpdatePendingPackageInfo(const tizen_base::Database& db,
-      const std::vector<pid_t>& pids, uid_t uid, const std::string& locale);
+  void RegisterPendingPackageInfo(const tizen_base::Database& db,
+      package_x* info, pid_t pid, uid_t uid, const std::string& locale,
+      pkgmgr_common::PkgWriteType write_type);
+  void UpdatePendingPackageInfo(const std::vector<std::string>& pkgids);
+  void UpdateCrashedWriterPackageInfo(const std::unordered_set<pid_t>& pids);
   bool UpdateCachePkg(const tizen_base::Database& db, uid_t uid,
       const std::string& pkgid, const std::string& locale);
   bool UpdateCacheApp(const tizen_base::Database& db, uid_t uid,
@@ -71,10 +74,11 @@ class EXPORT_API DBHandleProvider {
  private:
   explicit DBHandleProvider(uid_t uid);
   void ReleaseCache();
-  void AddPackage(std::string package, std::shared_ptr<package_x> info);
-  void AddApplication(std::string app, std::shared_ptr<application_x> info);
-  void InsertPID(pid_t pid);
-  bool ErasePID(pid_t pid);
+  void AddPackage(std::shared_ptr<package_x> info);
+  void AddApplication(std::shared_ptr<application_x> info);
+  void ErasePackage(const std::string& pkgid);
+  void InsertWriterPID(pid_t pid);
+  bool EraseWriterPID(pid_t pid);
   std::shared_ptr<package_x> GetPackageByApp(const char* appid);
 
  private:
@@ -92,7 +96,8 @@ class EXPORT_API DBHandleProvider {
   std::unordered_map<std::string, std::shared_ptr<package_x>> pkg_map_;
   std::unordered_map<std::string, std::shared_ptr<application_x>> app_map_;
   std::unordered_map<std::string, std::unordered_set<std::string>> pkg_app_map_;
-  std::unordered_map<pid_t, std::unordered_set<std::string>> pending_pkg_;
+  std::unordered_map<std::string, std::pair<pid_t, std::shared_ptr<package_x>>> pending_pkg_;
+  std::unordered_map<std::string, std::vector<std::shared_ptr<application_x>>> pending_app_;
 };
 
 }  // namespace database
index 90aa2ae6ea0b20775e1199fa1ae4fce8158ae282..5ce24ffb87717465ad97bf9dd2f9b6b56ce27502 100644 (file)
@@ -60,22 +60,25 @@ int PkgSetDBHandler::Execute() {
   const auto& db = GetConnection().front().first;
   int ret = 0;
 
-  if (write_type_ == pkgmgr_common::PkgWriteType::Insert)
+  if (write_type_ == pkgmgr_common::PkgWriteType::Insert) {
     ret = pkgmgr_server::internal::InsertPkgInfo(db, package_, uid_);
-  else if (write_type_ == pkgmgr_common::PkgWriteType::Update)
+  } else if (write_type_ == pkgmgr_common::PkgWriteType::Update) {
     ret = pkgmgr_server::internal::UpdatePkgInfo(db, package_, uid_);
-  else if (write_type_ == pkgmgr_common::PkgWriteType::Delete)
+  } else if (write_type_ == pkgmgr_common::PkgWriteType::Delete) {
     ret = pkgmgr_server::internal::DeletePkgInfo(db, package_->package, uid_);
-  else
+  } else {
     LOG(ERROR) << "Unknown db write type";
+    return PMINFO_R_ERROR;
+  }
 
   if (is_offline_ || ret != PMINFO_R_OK)
     return ret;
 
   auto lock = CacheFlag::GetWriterLock();
-  if (CacheFlag::GetStatus() == CacheFlag::Status::PREPARED)
-    DBHandleProvider::GetInst(uid_)
-        .RegisterPendingPackageInfo(package_, GetPID());
+  if (CacheFlag::GetStatus() == CacheFlag::Status::PREPARED) {
+    DBHandleProvider::GetInst(uid_).RegisterPendingPackageInfo(db,
+        package_, GetPID(), uid_, GetLocale(), write_type_);
+  }
 
   return ret;
 }
diff --git a/src/server/database/remove_cache_db_handler.cc b/src/server/database/remove_cache_db_handler.cc
deleted file mode 100644 (file)
index ab3279a..0000000
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "remove_cache_db_handler.hh"
-
-#include "cache_flag.hh"
-#include "db_handle_provider.hh"
-
-namespace pkgmgr_server {
-namespace database {
-
-RemoveCacheDBHandler::RemoveCacheDBHandler(uid_t uid, std::vector<pid_t> pids)
-    : AbstractDBHandler(uid, 0), uid_(uid), pids_(std::move(pids)) {}
-
-int RemoveCacheDBHandler::Execute() {
-  std::unique_lock<std::shared_mutex> u(lock_);
-  SetOpType(pkgmgr_common::DBOperationType::OPERATION_TYPE_READ);
-  SetDBType(pkgmgr_common::DBType::DB_TYPE_FILE_PKGDB);
-
-  if (!Connect()) {
-    database::DBHandleProvider::GetInst(GetUID()).TrimCache();
-    return PMINFO_R_ERROR;
-  }
-
-  const auto& conn_list = GetConnection();
-  auto lock = CacheFlag::GetWriterLock();
-  if (CacheFlag::GetStatus() != CacheFlag::Status::PREPARED)
-    return PMINFO_R_OK;
-
-  CacheFlag::SetStatus(CacheFlag::Status::PREPARING);
-  for (const auto& [db, uid] : conn_list) {
-    auto& provider = database::DBHandleProvider::GetInst(uid);
-    provider.UpdatePendingPackageInfo(db, pids_, uid_, GetLocale());
-  }
-
-  CacheFlag::SetStatus(CacheFlag::Status::PREPARED);
-
-  return PMINFO_R_OK;
-}
-
-}  // namespace database
-}  // namespace pkgmgr_server
diff --git a/src/server/database/remove_cache_db_handler.hh b/src/server/database/remove_cache_db_handler.hh
deleted file mode 100644 (file)
index 1019755..0000000
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef REMOVE_CACHE_DB_HANDLER_HH_
-#define REMOVE_CACHE_DB_HANDLER_HH_
-
-#include <sys/types.h>
-
-#include <vector>
-
-#include "abstract_db_handler.hh"
-
-namespace pkgmgr_server {
-namespace database {
-
-#ifndef EXPORT_API
-#define EXPORT_API __attribute__((visibility("default")))
-#endif
-
-class EXPORT_API RemoveCacheDBHandler : public AbstractDBHandler {
- public:
-  RemoveCacheDBHandler(uid_t uid, std::vector<pid_t> pids);
-  int Execute() override;
-
- private:
-  uid_t uid_;
-  std::vector<pid_t> pids_;
-};
-
-}  // namespace database
-}  // namespace pkgmgr_server
-
-#endif  // REMOVE_CACHE_DB_HANDLER_HH_
-
diff --git a/src/server/database/update_pending_cache_handler.cc b/src/server/database/update_pending_cache_handler.cc
new file mode 100644 (file)
index 0000000..5a4ecc5
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "update_pending_cache_handler.hh"
+
+#include "cache_flag.hh"
+#include "db_handle_provider.hh"
+
+namespace pkgmgr_server {
+namespace database {
+
+UpdatePendingCacheHandler::UpdatePendingCacheHandler(uid_t uid, std::unordered_set<pid_t> pids, std::vector<std::string> args)
+    : AbstractDBHandler(uid, 0), uid_(uid), pids_(std::move(pids)), args_(std::move(args)) {}
+
+int UpdatePendingCacheHandler::Execute() {
+  std::unique_lock<std::shared_mutex> u(lock_);
+  SetOpType(pkgmgr_common::DBOperationType::OPERATION_TYPE_READ);
+  SetDBType(pkgmgr_common::DBType::DB_TYPE_FILE_PKGDB);
+
+  if (!Connect()) {
+    database::DBHandleProvider::GetInst(GetUID()).TrimCache();
+    return PMINFO_R_ERROR;
+  }
+
+  const auto& conn_list = GetConnection();
+  auto lock = CacheFlag::GetWriterLock();
+  if (CacheFlag::GetStatus() != CacheFlag::Status::PREPARED)
+    return PMINFO_R_OK;
+
+  CacheFlag::SetStatus(CacheFlag::Status::PREPARING);
+  for (const auto& [db, uid] : conn_list) {
+    auto& provider = database::DBHandleProvider::GetInst(uid);
+    if (!args_.empty())
+      provider.UpdatePendingPackageInfo(args_);
+    else
+      provider.UpdateCrashedWriterPackageInfo(pids_);
+  }
+
+  CacheFlag::SetStatus(CacheFlag::Status::PREPARED);
+
+  return PMINFO_R_OK;
+}
+
+}  // namespace database
+}  // namespace pkgmgr_server
diff --git a/src/server/database/update_pending_cache_handler.hh b/src/server/database/update_pending_cache_handler.hh
new file mode 100644 (file)
index 0000000..cad8054
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef UPDATE_PENDING_CACHE_HANDLER_HH_
+#define UPDATE_PENDING_CACHE_HANDLER_HH_
+
+#include <sys/types.h>
+
+#include <unordered_set>
+#include <vector>
+
+#include "abstract_db_handler.hh"
+
+namespace pkgmgr_server {
+namespace database {
+
+#ifndef EXPORT_API
+#define EXPORT_API __attribute__((visibility("default")))
+#endif
+
+class EXPORT_API UpdatePendingCacheHandler : public AbstractDBHandler {
+ public:
+  UpdatePendingCacheHandler(uid_t uid, std::unordered_set<pid_t> pids,
+      std::vector<std::string> args);
+  int Execute() override;
+
+ private:
+  uid_t uid_;
+  std::unordered_set<pid_t> pids_;
+  std::vector<std::string> args_;
+};
+
+}  // namespace database
+}  // namespace pkgmgr_server
+
+#endif  // UPDATE_PENDING_CACHE_HANDLER_HH_
+
index 1577349de6bfc8c699839f53b999456273300e5b..3cb6b9d090879daafd2dfcb9bd3bba1e79ef0a55 100644 (file)
@@ -9,7 +9,7 @@
 #include "db_handle_provider.hh"
 #include "parcelable_factory.hh"
 #include "pkginfo_parcelable.hh"
-#include "remove_cache_db_handler.hh"
+#include "update_pending_cache_handler.hh"
 #include "utils/logging.hh"
 
 #include "pkgmgrinfo_debug.h"
@@ -41,8 +41,8 @@ bool CommandRequestHandler::HandleRequest(unsigned char* data, size_t size,
     return false;
   }
 
-  if (parcel->GetCmd() == CommandType::RemoveCache) {
-    database::RemoveCacheDBHandler db(parcel->GetUid(), {GetPID()});
+  if (parcel->GetCmd() == CommandType::UpdatePendingCache) {
+    database::UpdatePendingCacheHandler db(parcel->GetUid(), {GetPID()}, parcel->GetArgs());
     db.SetLocale(locale);
     int ret = db.Execute();
     result_ = std::make_shared<pcp::ResultParcelable>(
index 129ff1da3a2af7ffae81fe8fe701b1c3a1491e6b..5e50517f098ef984e7a5c26ca93b329ae679d0da 100644 (file)
@@ -26,7 +26,7 @@
 #include "cynara_checker.hh"
 #include "request_handler_factory.hh"
 #include "server/database/db_handle_provider.hh"
-#include "server/database/remove_cache_db_handler.hh"
+#include "server/database/update_pending_cache_handler.hh"
 #include "utils/logging.hh"
 
 #include "pkgmgrinfo_debug.h"
@@ -185,7 +185,7 @@ gboolean WorkerThread::TrimMemory(void* data) {
   auto crashed_writer_pids =
       database::DBHandleProvider::CrashedWriteRequestPIDs();
   if (!crashed_writer_pids.empty()) {
-    database::RemoveCacheDBHandler db(getuid(), std::move(crashed_writer_pids));
+    database::UpdatePendingCacheHandler db(getuid(), std::move(crashed_writer_pids), {});
     db.SetLocale(h->locale_.GetObject());
     db.Execute();
   }
index a8d8f4c700de15211298b2ffb6ef7b5536d765ff..3f315ea96d015eaff9f6503a14b4cc051f5828c3 100644 (file)
@@ -219,7 +219,7 @@ TEST_F(ParcelTest, QueryParcelable) {
 TEST_F(ParcelTest, CommandParcelable) {
   tizen_base::Parcel parcel;
 
-  pp::CommandParcelable origin_parcelable(0, RemoveCache);
+  pp::CommandParcelable origin_parcelable(0, UpdatePendingCache, {});
   pp::CommandParcelable new_parcelable;
   parcel.WriteParcelable(origin_parcelable);
   parcel.ReadParcelable(&new_parcelable);