mirror of
https://gitee.com/openharmony/bundlemanager_bundle_framework
synced 2024-11-27 09:20:49 +00:00
!6969 【质量加固】数据库文件丢失后,从备库恢复
Merge pull request !6969 from xuyicong/feat_restore_backupDB
This commit is contained in:
commit
4bd6b61aa7
@ -66,9 +66,14 @@ std::shared_ptr<NativeRdb::RdbStore> 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<NativeRdb::RdbStore> 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<int32_t>(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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user