From 7ba55a8dc442beeb254937c0ef1eb5e7ea07c448 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=81=E5=86=AC=E5=86=AC?= Date: Tue, 6 Feb 2024 15:50:49 +0800 Subject: [PATCH] modify sync MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 丁冬冬 --- conf/config.json | 7 ++- .../app/src/checker/bundle_checker.cpp | 28 ++++++++++++ .../app/src/checker/bundle_checker.h | 5 ++- .../app/src/checker/system_checker.cpp | 18 ++++++++ .../app/src/checker/system_checker.h | 5 ++- .../app/src/kvstore_meta_manager.cpp | 45 +++++++++++++++---- .../app/src/kvstore_meta_manager.h | 9 ++-- .../distributeddataservice/framework/BUILD.gn | 1 + .../framework/checker/checker_manager.cpp | 14 ++++++ .../include/checker/checker_manager.h | 6 ++- .../include/metadata/meta_data_manager.h | 3 +- .../include/metadata/store_meta_data.h | 6 +-- .../include/metadata/version_meta_data.h | 37 +++++++++++++++ .../framework/metadata/meta_data_manager.cpp | 11 ++++- .../framework/metadata/version_meta_data.cpp | 45 +++++++++++++++++++ .../service/bootstrap/src/bootstrap.cpp | 7 +++ .../config/include/model/checker_config.h | 2 + .../config/src/model/checker_config.cpp | 2 + .../service/kvdb/kvdb_service_impl.cpp | 8 ++-- .../service/test/cloud_data_test.cpp | 3 +- .../service/test/device_matrix_test.cpp | 3 +- 21 files changed, 234 insertions(+), 31 deletions(-) create mode 100755 services/distributeddataservice/framework/include/metadata/version_meta_data.h create mode 100755 services/distributeddataservice/framework/metadata/version_meta_data.cpp diff --git a/conf/config.json b/conf/config.json index 55cca51f6..a14102e76 100644 --- a/conf/config.json +++ b/conf/config.json @@ -28,8 +28,6 @@ "checkers": [ "SystemChecker", "BundleChecker", - "PackageChecker", - "ExternalChecker" ], "trusts": [ { @@ -37,7 +35,8 @@ "appId": "bundle_manager_service", "checker": "SystemChecker" } - ] + ], + "distrusts": [] }, "networks": { "chains": [ @@ -92,4 +91,4 @@ "backupInternal" : 36000, "backupNumber" : 20 } -} +} \ No newline at end of file diff --git a/services/distributeddataservice/app/src/checker/bundle_checker.cpp b/services/distributeddataservice/app/src/checker/bundle_checker.cpp index 557c99900..69c2739e3 100644 --- a/services/distributeddataservice/app/src/checker/bundle_checker.cpp +++ b/services/distributeddataservice/app/src/checker/bundle_checker.cpp @@ -44,6 +44,12 @@ bool BundleChecker::SetTrustInfo(const CheckerManager::Trust &trust) return true; } +bool BundleChecker::SetDistrustInfo(const CheckerManager::Distrust &distrust) +{ + distrusts_[distrust.bundleName] = distrust.appId; + return true; +} + std::string BundleChecker::GetAppId(const CheckerManager::StoreInfo &info) { if (AccessTokenKit::GetTokenTypeFlag(info.tokenId) != TOKEN_HAP) { @@ -80,5 +86,27 @@ bool BundleChecker::IsValid(const CheckerManager::StoreInfo &info) return tokenInfo.bundleName == info.bundleName; } + +bool BundleChecker::IsDistrust(const CheckerManager::StoreInfo &info) +{ + if (AccessTokenKit::GetTokenTypeFlag(info.tokenId) != TOKEN_HAP) { + return false; + } + HapTokenInfo tokenInfo; + auto result = AccessTokenKit::GetHapTokenInfo(info.tokenId, tokenInfo); + if (result != RET_SUCCESS) { + ZLOGE("token:0x%{public}x, result:%{public}d", info.tokenId, result); + return false; + } + if (!info.bundleName.empty() && tokenInfo.bundleName != info.bundleName) { + ZLOGE("bundlename:%{public}s <-> %{public}s", info.bundleName.c_str(), tokenInfo.bundleName.c_str()); + return false; + } + auto it = distrusts_.find(info.bundleName); + if (it != distrusts_.end() && (it->second == tokenInfo.appID)) { + return true; + } + return false; +} } // namespace DistributedData } // namespace OHOS \ No newline at end of file diff --git a/services/distributeddataservice/app/src/checker/bundle_checker.h b/services/distributeddataservice/app/src/checker/bundle_checker.h index e55a20a56..539234738 100644 --- a/services/distributeddataservice/app/src/checker/bundle_checker.h +++ b/services/distributeddataservice/app/src/checker/bundle_checker.h @@ -24,12 +24,15 @@ public: ~BundleChecker(); void Initialize() override; bool SetTrustInfo(const CheckerManager::Trust &trust) override; + bool SetDistrustInfo(const CheckerManager::Distrust &distrust) override; std::string GetAppId(const CheckerManager::StoreInfo &info) override; bool IsValid(const CheckerManager::StoreInfo &info) override; + bool IsDistrust(const CheckerManager::StoreInfo &info) override; private: static BundleChecker instance_; std::map trusts_; + std::map distrusts_; }; } // namespace DistributedData } // namespace OHOS -#endif // OHOS_DISTRIBUTED_DATA_SERVICES_FRAMEWORK_CHECKER_BUNDLE_CHECKER_H +#endif // OHOS_DISTRIBUTED_DATA_SERVICES_FRAMEWORK_CHECKER_BUNDLE_CHECKER_H \ No newline at end of file diff --git a/services/distributeddataservice/app/src/checker/system_checker.cpp b/services/distributeddataservice/app/src/checker/system_checker.cpp index c653d9576..aff8299e0 100644 --- a/services/distributeddataservice/app/src/checker/system_checker.cpp +++ b/services/distributeddataservice/app/src/checker/system_checker.cpp @@ -40,6 +40,12 @@ bool SystemChecker::SetTrustInfo(const CheckerManager::Trust &trust) return true; } +bool SystemChecker::SetDistrustInfo(const CheckerManager::Distrust &distrust) +{ + distrusts_[distrust.bundleName] = distrust.appId; + return true; +} + std::string SystemChecker::GetAppId(const CheckerManager::StoreInfo &info) { if (!IsValid(info)) { @@ -55,5 +61,17 @@ bool SystemChecker::IsValid(const CheckerManager::StoreInfo &info) auto type = AccessTokenKit::GetTokenTypeFlag(info.tokenId); return (type == TOKEN_NATIVE || type == TOKEN_SHELL); } + +bool SystemChecker::IsDistrust(const CheckerManager::StoreInfo &info) +{ + if (!IsValid(info)) { + return false; + } + auto it = distrusts_.find(info.bundleName); + if (it != distrusts_.end()) { + return true; + } + return false; +} } // namespace DistributedData } // namespace OHOS \ No newline at end of file diff --git a/services/distributeddataservice/app/src/checker/system_checker.h b/services/distributeddataservice/app/src/checker/system_checker.h index 1f441908e..f81bcc995 100644 --- a/services/distributeddataservice/app/src/checker/system_checker.h +++ b/services/distributeddataservice/app/src/checker/system_checker.h @@ -25,12 +25,15 @@ public: ~SystemChecker(); void Initialize() override; bool SetTrustInfo(const CheckerManager::Trust &trust) override; + bool SetDistrustInfo(const CheckerManager::Distrust &distrust) override; std::string GetAppId(const CheckerManager::StoreInfo &info) override; bool IsValid(const CheckerManager::StoreInfo &info) override; + bool IsDistrust(const CheckerManager::StoreInfo &info) override; private: std::map trusts_; + std::map distrusts_; static SystemChecker instance_; }; } // namespace DistributedData } // namespace OHOS -#endif // OHOS_DISTRIBUTED_DATA_SERVICES_FRAMEWORK_SYSTEM_CHECKER_H +#endif // OHOS_DISTRIBUTED_DATA_SERVICES_FRAMEWORK_SYSTEM_CHECKER_H \ No newline at end of file diff --git a/services/distributeddataservice/app/src/kvstore_meta_manager.cpp b/services/distributeddataservice/app/src/kvstore_meta_manager.cpp index 6764b030b..aa1ececae 100644 --- a/services/distributeddataservice/app/src/kvstore_meta_manager.cpp +++ b/services/distributeddataservice/app/src/kvstore_meta_manager.cpp @@ -32,11 +32,13 @@ #include "log_print.h" #include "matrix_event.h" #include "metadata/meta_data_manager.h" +#include "metadata/version_meta_data.h" #include "runtime_config.h" #include "utils/anonymous.h" #include "utils/block_integer.h" #include "utils/crypto.h" #include "utils/ref_count.h" +#include "utils/converter.h" namespace OHOS { namespace DistributedKv { @@ -180,9 +182,34 @@ void KvStoreMetaManager::InitMetaData() MetaDataManager::GetInstance().SaveMeta(data.GetKey(), data, true))) { ZLOGE("save meta fail"); } + UpdateMetaData(); + SetSyncer(); ZLOGI("end."); } +void KvStoreMetaManager::UpdateMetaData() +{ + VersionMetaData versionMeta; + if (!MetaDataManager::GetInstance().LoadMeta(versionMeta.GetKey(), versionMeta, true) + || versionMeta.version < META_VERSION) { + std::vector metaDataList; + std::string prefix = StoreMetaData::GetPrefix({ DmAdapter::GetInstance().GetLocalDevice().uuid }); + MetaDataManager::GetInstance().LoadMeta(prefix, metaDataList); + for (auto metaData : metaDataList) { + MetaDataManager::GetInstance().SaveMeta(metaData.GetKey(), metaData, true); + if (CheckerManager::GetInstance().IsDistrust(Converter::ConvertToStoreInfo(metaData)) || + (metaData.storeType >= StoreMetaData::StoreType::STORE_RELATIONAL_BEGIN + && metaData.storeType <= StoreMetaData::StoreType::STORE_RELATIONAL_END)) { + MetaDataManager::GetInstance().DelMeta(metaData.GetKey()); + } + } + } + if (versionMeta.version != VersionMetaData::CURRENT_VERSION) { + versionMeta.version = VersionMetaData::CURRENT_VERSION; + MetaDataManager::GetInstance().SaveMeta(versionMeta.GetKey(), versionMeta, true); + } +} + void KvStoreMetaManager::InitMetaParameter() { ZLOGI("start."); @@ -222,8 +249,13 @@ KvStoreMetaManager::NbDelegate KvStoreMetaManager::GetMetaKvStore() std::lock_guard lock(mutex_); if (metaDelegate_ == nullptr) { metaDelegate_ = CreateMetaKvStore(); + auto fullName = GetBackupPath(); + auto backup = [fullName](const auto &store) -> int32_t { + DistributedDB::CipherPassword password; + return store->Export(fullName, password); + }; + MetaDataManager::GetInstance().Initialize(metaDelegate_, backup); } - ConfigMetaDataManager(); return metaDelegate_; } @@ -270,13 +302,8 @@ KvStoreMetaManager::NbDelegate KvStoreMetaManager::CreateMetaKvStore() return NbDelegate(delegate, release); } -void KvStoreMetaManager::ConfigMetaDataManager() +void KvStoreMetaManager::SetSyncer() { - auto fullName = GetBackupPath(); - auto backup = [fullName](const auto &store) -> int32_t { - DistributedDB::CipherPassword password; - return store->Export(fullName, password); - }; auto syncer = [this](const auto &store, int32_t status) { DeviceMatrix::GetInstance().OnChanged(DeviceMatrix::META_STORE_MASK); auto size = DmAdapter::GetInstance().GetOnlineSize(); @@ -293,7 +320,7 @@ void KvStoreMetaManager::ConfigMetaDataManager() executors_->Reset(delaySyncTaskId_, std::chrono::milliseconds(DELAY_SYNC)); } }; - MetaDataManager::GetInstance().Initialize(metaDelegate_, backup, syncer); + MetaDataManager::GetInstance().SetSyncer(syncer); } std::function KvStoreMetaManager::SyncTask(const NbDelegate &store, int32_t status) @@ -532,4 +559,4 @@ AppDistributedKv::ChangeLevelType KvStoreMetaManager::DBInfoDeviceChangeListener return AppDistributedKv::ChangeLevelType::MIN; } } // namespace DistributedKv -} // namespace OHOS +} // namespace OHOS \ No newline at end of file diff --git a/services/distributeddataservice/app/src/kvstore_meta_manager.h b/services/distributeddataservice/app/src/kvstore_meta_manager.h index b127e21ae..9ffc56edb 100644 --- a/services/distributeddataservice/app/src/kvstore_meta_manager.h +++ b/services/distributeddataservice/app/src/kvstore_meta_manager.h @@ -62,12 +62,14 @@ private: NbDelegate CreateMetaKvStore(); - void ConfigMetaDataManager(); + void SetSyncer(); KvStoreMetaManager(); void InitMetaData(); + void UpdateMetaData(); + void SubscribeMetaKvStore(); void SyncMeta(); @@ -86,7 +88,7 @@ private: std::string GetBackupPath() const; ExecutorPool::Task GetTask(uint32_t retry); - + std::function SyncTask(const NbDelegate &store, int32_t status); class KvStoreMetaObserver : public DistributedDB::KvStoreObserver { @@ -121,7 +123,8 @@ private: std::mutex mutex_; std::shared_ptr executors_; TaskId delaySyncTaskId_ = ExecutorPool::INVALID_TASK_ID; + static constexpr int32_t META_VERSION = 1; }; } // namespace DistributedKv } // namespace OHOS -#endif // KVSTORE_META_MANAGER_H +#endif // KVSTORE_META_MANAGER_H \ No newline at end of file diff --git a/services/distributeddataservice/framework/BUILD.gn b/services/distributeddataservice/framework/BUILD.gn index 14d7b5852..aa0df79dd 100644 --- a/services/distributeddataservice/framework/BUILD.gn +++ b/services/distributeddataservice/framework/BUILD.gn @@ -80,6 +80,7 @@ ohos_shared_library("distributeddatasvcfwk") { "metadata/store_meta_data_local.cpp", "metadata/strategy_meta_data.cpp", "metadata/user_meta_data.cpp", + "metadata/version_meta_data.cpp", "serializable/serializable.cpp", "snapshot/bind_event.cpp", "snapshot/snapshot.cpp", diff --git a/services/distributeddataservice/framework/checker/checker_manager.cpp b/services/distributeddataservice/framework/checker/checker_manager.cpp index 8dbc1bb39..9a384153d 100644 --- a/services/distributeddataservice/framework/checker/checker_manager.cpp +++ b/services/distributeddataservice/framework/checker/checker_manager.cpp @@ -76,6 +76,20 @@ bool CheckerManager::IsValid(const StoreInfo &info) return false; } +bool CheckerManager::IsDistrust(const StoreInfo &info) +{ + for (auto &[name, checker] : checkers_) { + if (checker == nullptr) { + continue; + } + if (!checker->IsDistrust(info)) { + continue; + } + return true; + } + return false; +} + CheckerManager::Checker *CheckerManager::GetChecker(const std::string &checker) { auto it = checkers_.find(checker); diff --git a/services/distributeddataservice/framework/include/checker/checker_manager.h b/services/distributeddataservice/framework/include/checker/checker_manager.h index 95b402279..b54063d7e 100644 --- a/services/distributeddataservice/framework/include/checker/checker_manager.h +++ b/services/distributeddataservice/framework/include/checker/checker_manager.h @@ -29,6 +29,7 @@ public: std::string base64Key; std::string checker; }; + using Distrust = Trust; struct StoreInfo { pid_t uid; uint32_t tokenId; @@ -39,8 +40,10 @@ public: public: virtual void Initialize() = 0; virtual bool SetTrustInfo(const Trust &trust) = 0; + virtual bool SetDistrustInfo(const Distrust &distrust) = 0; virtual std::string GetAppId(const StoreInfo &info) = 0; virtual bool IsValid(const StoreInfo &info) = 0; + virtual bool IsDistrust(const StoreInfo &info) = 0; protected: API_EXPORT ~Checker() = default; }; @@ -48,6 +51,7 @@ public: API_EXPORT void RegisterPlugin(const std::string &checker, std::function getter); API_EXPORT std::string GetAppId(const StoreInfo &info); API_EXPORT bool IsValid(const StoreInfo &info); + API_EXPORT bool IsDistrust(const StoreInfo &info); API_EXPORT void LoadCheckers(std::vector &checkers); API_EXPORT Checker *GetChecker(const std::string &checker); private: @@ -56,4 +60,4 @@ private: }; } // namespace DistributedData } // namespace OHOS -#endif // OHOS_DISTRIBUTED_DATA_SERVICES_FRAMEWORK_CHECKER_CHECKER_MANAGER_H +#endif // OHOS_DISTRIBUTED_DATA_SERVICES_FRAMEWORK_CHECKER_CHECKER_MANAGER_H \ No newline at end of file diff --git a/services/distributeddataservice/framework/include/metadata/meta_data_manager.h b/services/distributeddataservice/framework/include/metadata/meta_data_manager.h index 5b2ff1aaf..2f196678a 100644 --- a/services/distributeddataservice/framework/include/metadata/meta_data_manager.h +++ b/services/distributeddataservice/framework/include/metadata/meta_data_manager.h @@ -50,7 +50,8 @@ public: using Backup = std::function &)>; using Bytes = std::vector; API_EXPORT static MetaDataManager &GetInstance(); - API_EXPORT void Initialize(std::shared_ptr metaStore, const Backup &backup, const Syncer &syncer); + API_EXPORT void Initialize(std::shared_ptr metaStore, const Backup &backup); + API_EXPORT void SetSyncer(const Syncer &syncer); API_EXPORT bool SaveMeta(const std::string &key, const Serializable &value, bool isLocal = false); API_EXPORT bool LoadMeta(const std::string &key, Serializable &value, bool isLocal = false); template diff --git a/services/distributeddataservice/framework/include/metadata/store_meta_data.h b/services/distributeddataservice/framework/include/metadata/store_meta_data.h index 6a8a15e4d..fdcb3d49a 100644 --- a/services/distributeddataservice/framework/include/metadata/store_meta_data.h +++ b/services/distributeddataservice/framework/include/metadata/store_meta_data.h @@ -26,6 +26,7 @@ struct API_EXPORT StoreMetaData final : public Serializable { // UID -> uid, deviceAccountId -> userId, userId -> user static constexpr uint32_t FIELD_CHANGED_TAG = 0x03000003; static constexpr uint32_t UUID_CHANGED_TAG = 0x03000004; + static constexpr const char *KEY_PREFIX = "KvStoreMetaData"; uint32_t version = CURRENT_VERSION; bool isAutoSync = false; bool isBackup = false; @@ -77,9 +78,6 @@ struct API_EXPORT StoreMetaData final : public Serializable { API_EXPORT std::string GetStoreAlias() const; API_EXPORT static std::string GetKey(const std::initializer_list &fields); API_EXPORT static std::string GetPrefix(const std::initializer_list &fields); - -private: - static constexpr const char *KEY_PREFIX = "KvStoreMetaData"; }; } // namespace OHOS::DistributedData -#endif // OHOS_DISTRIBUTED_DATA_SERVICES_FRAMEWORK_METADATA_STORE_META_DATA_H +#endif // OHOS_DISTRIBUTED_DATA_SERVICES_FRAMEWORK_METADATA_STORE_META_DATA_H \ No newline at end of file diff --git a/services/distributeddataservice/framework/include/metadata/version_meta_data.h b/services/distributeddataservice/framework/include/metadata/version_meta_data.h new file mode 100755 index 000000000..196631171 --- /dev/null +++ b/services/distributeddataservice/framework/include/metadata/version_meta_data.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef DISTRIBUTEDDATAMGR_VERSION_META_DATA_H +#define DISTRIBUTEDDATAMGR_VERSION_META_DATA_H +#include "serializable/serializable.h" + +namespace OHOS::DistributedData { +class API_EXPORT VersionMetaData final : public Serializable { +public: + static constexpr int32_t CURRENT_VERSION = 1; + static constexpr int32_t INVALID_VERSION = -1; + int32_t version = INVALID_VERSION; + + API_EXPORT VersionMetaData(); + API_EXPORT ~VersionMetaData(); + API_EXPORT bool Marshal(json &node) const override; + API_EXPORT bool Unmarshal(const json &node) override; + API_EXPORT std::string GetKey() const; + +private: + static constexpr const char *KEY_PREFIX = "VersionKey"; +}; +} // namespace OHOS::DistributedData +#endif // DISTRIBUTEDDATAMGR_VERSION_META_DATA_H diff --git a/services/distributeddataservice/framework/metadata/meta_data_manager.cpp b/services/distributeddataservice/framework/metadata/meta_data_manager.cpp index a6e22d3fa..fb6e8e2fe 100644 --- a/services/distributeddataservice/framework/metadata/meta_data_manager.cpp +++ b/services/distributeddataservice/framework/metadata/meta_data_manager.cpp @@ -107,7 +107,7 @@ MetaDataManager::~MetaDataManager() metaObservers_.Clear(); } -void MetaDataManager::Initialize(std::shared_ptr metaStore, const Backup &backup, const Syncer &syncer) +void MetaDataManager::Initialize(std::shared_ptr metaStore, const Backup &backup) { if (metaStore == nullptr) { return; @@ -119,10 +119,17 @@ void MetaDataManager::Initialize(std::shared_ptr metaStore, const Bac } metaStore_ = std::move(metaStore); backup_ = backup; - syncer_ = syncer; inited_ = true; } +void MetaDataManager::SetSyncer(const Syncer &syncer) +{ + if (metaStore_ == nullptr) { + return; + } + syncer_ = syncer; +} + bool MetaDataManager::SaveMeta(const std::string &key, const Serializable &value, bool isLocal) { if (!inited_) { diff --git a/services/distributeddataservice/framework/metadata/version_meta_data.cpp b/services/distributeddataservice/framework/metadata/version_meta_data.cpp new file mode 100755 index 000000000..a7da7e3ef --- /dev/null +++ b/services/distributeddataservice/framework/metadata/version_meta_data.cpp @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "metadata/version_meta_data.h" + +namespace OHOS::DistributedData { +VersionMetaData::VersionMetaData() +{ +} + +VersionMetaData::~VersionMetaData() +{ +} + +bool VersionMetaData::Marshal(json &node) const +{ + bool ret = true; + ret = SetValue(node[GET_NAME(version)], version) && ret; + return ret; +} + +bool VersionMetaData::Unmarshal(const json &node) +{ + bool ret = true; + ret = GetValue(node, GET_NAME(version), version) && ret; + return ret; +} + +std::string VersionMetaData::GetKey() const +{ + return KEY_PREFIX; +} +} // namespace OHOS::DistributedData \ No newline at end of file diff --git a/services/distributeddataservice/service/bootstrap/src/bootstrap.cpp b/services/distributeddataservice/service/bootstrap/src/bootstrap.cpp index 8f958cf3a..ab8832b6f 100644 --- a/services/distributeddataservice/service/bootstrap/src/bootstrap.cpp +++ b/services/distributeddataservice/service/bootstrap/src/bootstrap.cpp @@ -93,6 +93,13 @@ void Bootstrap::LoadCheckers() } checker->SetTrustInfo(trust); } + for (const auto &distrust : checkers->distrusts) { + auto *checker = CheckerManager::GetInstance().GetChecker(distrust.checker); + if (checker == nullptr) { + continue; + } + checker->SetDistrustInfo(distrust); + } } void Bootstrap::LoadBackup(std::shared_ptr executors) diff --git a/services/distributeddataservice/service/config/include/model/checker_config.h b/services/distributeddataservice/service/config/include/model/checker_config.h index 1cbb8c447..c4755d8ee 100644 --- a/services/distributeddataservice/service/config/include/model/checker_config.h +++ b/services/distributeddataservice/service/config/include/model/checker_config.h @@ -25,8 +25,10 @@ public: bool Marshal(json &node) const override; bool Unmarshal(const json &node) override; }; + using Distrust = Trust; std::vector checkers; std::vector trusts; + std::vector distrusts; bool Marshal(json &node) const override; bool Unmarshal(const json &node) override; }; diff --git a/services/distributeddataservice/service/config/src/model/checker_config.cpp b/services/distributeddataservice/service/config/src/model/checker_config.cpp index f543df0ab..f65f2d0d3 100644 --- a/services/distributeddataservice/service/config/src/model/checker_config.cpp +++ b/services/distributeddataservice/service/config/src/model/checker_config.cpp @@ -40,6 +40,7 @@ bool CheckerConfig::Marshal(json &node) const { SetValue(node[GET_NAME(checkers)], checkers); SetValue(node[GET_NAME(trusts)], trusts); + SetValue(node[GET_NAME(distrusts)], distrusts); return true; } @@ -47,6 +48,7 @@ bool CheckerConfig::Unmarshal(const json &node) { GetValue(node, GET_NAME(checkers), checkers); GetValue(node, GET_NAME(trusts), trusts); + GetValue(node, GET_NAME(distrusts), distrusts); return true; } } // namespace DistributedData diff --git a/services/distributeddataservice/service/kvdb/kvdb_service_impl.cpp b/services/distributeddataservice/service/kvdb/kvdb_service_impl.cpp index 1310aa2b3..72e271bd5 100644 --- a/services/distributeddataservice/service/kvdb/kvdb_service_impl.cpp +++ b/services/distributeddataservice/service/kvdb/kvdb_service_impl.cpp @@ -383,7 +383,7 @@ Status KVDBServiceImpl::BeforeCreate(const AppId &appId, const StoreId &storeId, AddOptions(options, meta); StoreMetaData old; - auto isCreated = MetaDataManager::GetInstance().LoadMeta(meta.GetKey(), old); + auto isCreated = MetaDataManager::GetInstance().LoadMeta(meta.GetKey(), old, true); if (!isCreated) { return SUCCESS; } @@ -416,7 +416,7 @@ Status KVDBServiceImpl::AfterCreate(const AppId &appId, const StoreId &storeId, AddOptions(options, metaData); StoreMetaData oldMeta; - auto isCreated = MetaDataManager::GetInstance().LoadMeta(metaData.GetKey(), oldMeta); + auto isCreated = MetaDataManager::GetInstance().LoadMeta(metaData.GetKey(), oldMeta, true); Status status = SUCCESS; if (isCreated && oldMeta != metaData) { auto dbStatus = Upgrade::GetInstance().UpdateStore(oldMeta, metaData, password); @@ -430,7 +430,9 @@ Status KVDBServiceImpl::AfterCreate(const AppId &appId, const StoreId &storeId, } if (!isCreated || oldMeta != metaData) { - MetaDataManager::GetInstance().SaveMeta(metaData.GetKey(), metaData); + if (!CheckerManager::GetInstance().IsDistrust(Converter::ConvertToStoreInfo(metaData))) { + MetaDataManager::GetInstance().SaveMeta(metaData.GetKey(), metaData); + } MetaDataManager::GetInstance().SaveMeta(metaData.GetKey(), metaData, true); } AppIDMetaData appIdMeta; diff --git a/services/distributeddataservice/service/test/cloud_data_test.cpp b/services/distributeddataservice/service/test/cloud_data_test.cpp index 1242139bb..6b8c965a2 100644 --- a/services/distributeddataservice/service/test/cloud_data_test.cpp +++ b/services/distributeddataservice/service/test/cloud_data_test.cpp @@ -135,7 +135,8 @@ void CloudDataTest::InitSchemaMeta() void CloudDataTest::SetUpTestCase(void) { - MetaDataManager::GetInstance().Initialize(dbStoreMock_, nullptr, [](const auto &, auto) { + MetaDataManager::GetInstance().Initialize(dbStoreMock_, nullptr); + MetaDataManager::GetInstance().SetSyncer([](const auto &, auto) { DeviceMatrix::GetInstance().OnChanged(DeviceMatrix::META_STORE_MASK); }); diff --git a/services/distributeddataservice/service/test/device_matrix_test.cpp b/services/distributeddataservice/service/test/device_matrix_test.cpp index 11c8b53d2..ab03d50ce 100644 --- a/services/distributeddataservice/service/test/device_matrix_test.cpp +++ b/services/distributeddataservice/service/test/device_matrix_test.cpp @@ -61,7 +61,8 @@ std::shared_ptr DeviceMatrixTest::dbStoreMock_ = std::make_shared