From f3f4a1ec535d1f9af92c1c8ed8ef351525203997 Mon Sep 17 00:00:00 2001 From: xiaozuo00 Date: Thu, 12 Sep 2024 17:22:15 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E8=B4=A8=E9=87=8F=E5=8A=A0=E5=9B=BA?= =?UTF-8?q?=E3=80=91=E4=B8=BBdb=E6=96=87=E4=BB=B6=E4=B8=A2=E5=A4=B1?= =?UTF-8?q?=E5=90=8E=E4=BB=8E=E5=A4=87=E5=BA=93=E6=81=A2=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xiaozuo00 --- services/bundlemgr/src/rdb/rdb_data_manager.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/services/bundlemgr/src/rdb/rdb_data_manager.cpp b/services/bundlemgr/src/rdb/rdb_data_manager.cpp index 5ac102187..dd7de1e3d 100644 --- a/services/bundlemgr/src/rdb/rdb_data_manager.cpp +++ b/services/bundlemgr/src/rdb/rdb_data_manager.cpp @@ -66,9 +66,14 @@ std::shared_ptr RdbDataManager::GetRdbStore() isInitial_ = true; } // for check db exist or not + bool isNeedRebuildDb = false; + std::string rdbFilePath = bmsRdbConfig_.dbPath + std::string("/") + std::string(BMS_BACK_UP_RDB_NAME); if (access(rdbStoreConfig.GetPath().c_str(), F_OK) != 0) { APP_LOGW("bms db :%{public}s is not exist, need to create. errno:%{public}d", rdbStoreConfig.GetPath().c_str(), errno); + if (access(rdbFilePath.c_str(), F_OK) == 0) { + isNeedRebuildDb = true; + } } int32_t errCode = NativeRdb::E_OK; BmsRdbOpenCallback bmsRdbOpenCallback(bmsRdbConfig_); @@ -84,11 +89,10 @@ std::shared_ptr RdbDataManager::GetRdbStore() CheckSystemSizeAndHisysEvent(bmsRdbConfig_.dbPath, bmsRdbConfig_.dbName); NativeRdb::RebuiltType rebuildType = NativeRdb::RebuiltType::NONE; int32_t rebuildCode = rdbStore_->GetRebuilt(rebuildType); - if (rebuildType == NativeRdb::RebuiltType::REBUILT) { + if (rebuildType == NativeRdb::RebuiltType::REBUILT || isNeedRebuildDb) { APP_LOGI("start %{public}s restore ret %{public}d, type:%{public}d", bmsRdbConfig_.dbName.c_str(), rebuildCode, static_cast(rebuildType)); - int32_t restoreRet = rdbStore_->Restore(bmsRdbConfig_.dbPath + std::string("/") + - std::string(BMS_BACK_UP_RDB_NAME)); + int32_t restoreRet = rdbStore_->Restore(rdbFilePath); if (restoreRet != NativeRdb::E_OK) { APP_LOGE("rdb restore failed ret:%{public}d", restoreRet); }