diff --git a/services/dbms/include/distributed_data_storage.h b/services/dbms/include/distributed_data_storage.h index fdc2eee34cd5b6294982dd51823b98a6a4e28078..623243dc32afb3b9a75690be987334ac31b8fdf7 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 a44cd6b63c7f636fdf1a90005ebefbe18c81e991..605cfcf66f9bf9cb2f3ab761bbfa6729b6472532 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());