From 602b5f407121f34f8c084b225a6e045838a85efd Mon Sep 17 00:00:00 2001 From: wangtiantian Date: Fri, 8 Dec 2023 14:51:28 +0800 Subject: [PATCH] IssueNo:#I8MTNK Description:fix bug Sig:SIG_ApplicaitonFramework Feature or Bugfix:Bugfix Binary Source:No Signed-off-by: wangtiantian --- .../dbms/include/distributed_data_storage.h | 3 ++- .../dbms/src/distributed_data_storage.cpp | 19 +++++++++++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/services/dbms/include/distributed_data_storage.h b/services/dbms/include/distributed_data_storage.h index fdc2eee..623243d 100644 --- a/services/dbms/include/distributed_data_storage.h +++ b/services/dbms/include/distributed_data_storage.h @@ -53,7 +53,8 @@ private: DistributedBundleInfo ConvertToDistributedBundleInfo(const BundleInfo &bundleInfo); int32_t GetUdidByNetworkId(const std::string &networkId, std::string &udid); bool InnerSaveStorageDistributeInfo(const DistributedBundleInfo &distributedBundleInfo); - std::map GetAllOldDistributionBundleInfo(); + std::map GetAllOldDistributionBundleInfo( + const std::vector &bundleNames); private: static std::mutex mutex_; diff --git a/services/dbms/src/distributed_data_storage.cpp b/services/dbms/src/distributed_data_storage.cpp index a44cd6b..605cfcf 100644 --- a/services/dbms/src/distributed_data_storage.cpp +++ b/services/dbms/src/distributed_data_storage.cpp @@ -370,12 +370,18 @@ void DistributedDataStorage::UpdateDistributedData(int32_t userId) APP_LOGE("Get bundleMgr shared_ptr nullptr"); return; } - std::map oldDistributedBundleInfos = GetAllOldDistributionBundleInfo(); std::vector bundleInfos; if (!bundleMgr->GetBundleInfos(FLAGS, bundleInfos, userId)) { APP_LOGE("get bundleInfos failed"); return; } + std::vector bundleNames; + for (const auto &bundleInfo : bundleInfos) { + bundleNames.push_back(bundleInfo.name); + } + std::map oldDistributedBundleInfos = + GetAllOldDistributionBundleInfo(bundleNames); + for (const auto &bundleInfo : bundleInfos) { if (bundleInfo.singleton) { continue; @@ -392,7 +398,8 @@ void DistributedDataStorage::UpdateDistributedData(int32_t userId) } } -std::map DistributedDataStorage::GetAllOldDistributionBundleInfo() +std::map DistributedDataStorage::GetAllOldDistributionBundleInfo( + const std::vector &bundleNames) { APP_LOGD("start"); std::map oldDistributedBundleInfos; @@ -420,6 +427,14 @@ std::map DistributedDataStorage::GetAllOldDi std::string value = entry.value.ToString(); DistributedBundleInfo distributedBundleInfo; if (distributedBundleInfo.FromJsonString(value)) { + if (std::find(bundleNames.begin(), bundleNames.end(), distributedBundleInfo.bundleName) == + bundleNames.end()) { + APP_LOGW("bundleName:%{public}s need delete", distributedBundleInfo.bundleName.c_str()); + if (kvStorePtr_->Delete(entry.key) != Status::SUCCESS) { + APP_LOGE("Delete key:%{public}s failed", key.c_str()); + } + continue; + } oldDistributedBundleInfos.emplace(distributedBundleInfo.bundleName, distributedBundleInfo); } else { APP_LOGE("DistributionInfo FromJsonString key:%{public}s failed", key.c_str()); -- Gitee