Delay Creation of cache if backup database is exist 47/287947/3
authorilho kim <ilho159.kim@samsung.com>
Wed, 8 Feb 2023 06:37:28 +0000 (15:37 +0900)
committerilho kim <ilho159.kim@samsung.com>
Thu, 9 Feb 2023 07:35:30 +0000 (16:35 +0900)
If the backup database created during pkg_upgrade remains due to power off
the backup database will be restored in the next pkg_upgrade
In this case, the package information of the database and cache may be
different

Change-Id: I3b17a659cdaeccd3fc2c01224336f771b4bd7f5f
Signed-off-by: ilho kim <ilho159.kim@samsung.com>
src/server/database/cache_db_handler.cc
src/server/database/cache_db_handler.hh

index af61c81..ae4e366 100644 (file)
@@ -31,11 +31,30 @@ CacheDBHandler::CacheDBHandler(uid_t uid, int pid)
 
 CacheDBHandler::~CacheDBHandler() {}
 
+bool CacheDBHandler::IsBackupDBExist() {
+  auto dbpath_list = GetDBPath();
+  for (const auto& [path, uid] : dbpath_list) {
+    auto backup_db_path = path + ".bck";
+
+    if (access(backup_db_path.c_str(), F_OK) == 0) {
+      LOG(WARNING) << "Backup database[" << backup_db_path
+          << "] created during pkg_upgrade remain, Try to delay cache creation";
+      return true;
+    }
+  }
+
+  return false;
+}
+
 int CacheDBHandler::Execute() {
-  std::shared_lock<std::shared_mutex> s(lock_);
   SetOpType(pkgmgr_common::DBOperationType::OPERATION_TYPE_READ);
   SetDBType(pkgmgr_common::DBType::DB_TYPE_FILE_PKGDB);
 
+  while (IsBackupDBExist())
+    sleep(1);
+
+  std::shared_lock<std::shared_mutex> s(lock_);
+
   if (!Connect()) {
     CacheFlag::SetStatus(CacheFlag::Status::UNPREPARED);
     return PMINFO_R_ERROR;
index 0e73b0b..6a2450b 100644 (file)
@@ -42,6 +42,9 @@ class EXPORT_API CacheDBHandler : public AbstractDBHandler {
   pkgmgrinfo_filter_x* filter_ = nullptr;
   std::vector<std::shared_ptr<package_x>> handle_list_;
   uid_t uid_;
+
+ private:
+  bool IsBackupDBExist();
 };
 
 }  // namespace database