From 0abf9c353f96253c0e38c2c24722b65ad58a6672 Mon Sep 17 00:00:00 2001 From: zqq Date: Thu, 10 Mar 2022 17:30:08 +0800 Subject: [PATCH 1/2] check realpath in another thread when autolaunch but enable autolaunch still check Signed-off-by: zqq --- .../distributeddb/common/include/auto_launch.h | 4 ++-- .../common/include/param_check_utils.h | 4 ++-- .../libs/distributeddb/common/src/auto_launch.cpp | 13 +++++++------ .../distributeddb/common/src/param_check_utils.cpp | 14 ++++++++++++-- .../interfaces/src/kv_store_delegate_manager.cpp | 2 +- 5 files changed, 24 insertions(+), 13 deletions(-) diff --git a/services/distributeddataservice/libs/distributeddb/common/include/auto_launch.h b/services/distributeddataservice/libs/distributeddb/common/include/auto_launch.h index ea898c47c..6debcc82f 100644 --- a/services/distributeddataservice/libs/distributeddb/common/include/auto_launch.h +++ b/services/distributeddataservice/libs/distributeddb/common/include/auto_launch.h @@ -64,7 +64,7 @@ struct AutoLaunchItem { class AutoLaunch { public: - static int GetAutoLaunchProperties(const AutoLaunchParam ¶m, const DBType &openType, + static int GetAutoLaunchProperties(const AutoLaunchParam ¶m, const DBType &openType, bool checkDir, std::shared_ptr &propertiesPtr); AutoLaunch() = default; @@ -96,7 +96,7 @@ protected: static int SetConflictNotifier(AutoLaunchItem &autoLaunchItem); static int GetAutoLaunchKVProperties(const AutoLaunchParam ¶m, - const std::shared_ptr &propertiesPtr); + const std::shared_ptr &propertiesPtr, bool checkDir); static int GetAutoLaunchRelationProperties(const AutoLaunchParam ¶m, const std::shared_ptr &propertiesPtr); diff --git a/services/distributeddataservice/libs/distributeddb/common/include/param_check_utils.h b/services/distributeddataservice/libs/distributeddb/common/include/param_check_utils.h index a5927a266..f55e66a46 100644 --- a/services/distributeddataservice/libs/distributeddb/common/include/param_check_utils.h +++ b/services/distributeddataservice/libs/distributeddb/common/include/param_check_utils.h @@ -46,8 +46,8 @@ public: static bool IsS3SECEOpt(const SecurityOption &secOpt); - static int CheckAndTransferAutoLaunchParam(const AutoLaunchParam ¶m, - SchemaObject &schemaObject); + static int CheckAndTransferAutoLaunchParam(const AutoLaunchParam ¶m, bool checkDir, + SchemaObject &schemaObject, std::string &canonicalDir); static uint8_t GetValidCompressionRate(uint8_t compressionRate); diff --git a/services/distributeddataservice/libs/distributeddb/common/src/auto_launch.cpp b/services/distributeddataservice/libs/distributeddb/common/src/auto_launch.cpp index 2ef7cd1ab..979b3dd4f 100644 --- a/services/distributeddataservice/libs/distributeddb/common/src/auto_launch.cpp +++ b/services/distributeddataservice/libs/distributeddb/common/src/auto_launch.cpp @@ -791,7 +791,7 @@ int AutoLaunch::AutoLaunchExt(const std::string &identifier, const std::string & } std::shared_ptr ptr; - errCode = AutoLaunch::GetAutoLaunchProperties(param, openType, ptr); + errCode = AutoLaunch::GetAutoLaunchProperties(param, openType, false, ptr); if (errCode != E_OK) { LOGE("[AutoLaunch] AutoLaunchExt param check fail errCode:%d", errCode); if (!param.notifier) { @@ -981,14 +981,14 @@ END: return errCode; } -int AutoLaunch::GetAutoLaunchProperties(const AutoLaunchParam ¶m, const DBType &openType, +int AutoLaunch::GetAutoLaunchProperties(const AutoLaunchParam ¶m, const DBType &openType, bool checkDir, std::shared_ptr &propertiesPtr) { switch (openType) { case DBType::DB_KV: { propertiesPtr = std::make_shared(); std::shared_ptr kvPtr = std::static_pointer_cast(propertiesPtr); - return GetAutoLaunchKVProperties(param, kvPtr); + return GetAutoLaunchKVProperties(param, kvPtr, checkDir); } case DBType::DB_RELATION: { propertiesPtr = std::make_shared(); @@ -1002,10 +1002,11 @@ int AutoLaunch::GetAutoLaunchProperties(const AutoLaunchParam ¶m, const DBTy } int AutoLaunch::GetAutoLaunchKVProperties(const AutoLaunchParam ¶m, - const std::shared_ptr &propertiesPtr) + const std::shared_ptr &propertiesPtr, bool checkDir) { SchemaObject schemaObject; - int errCode = ParamCheckUtils::CheckAndTransferAutoLaunchParam(param, schemaObject); + std::string canonicalDir; + int errCode = ParamCheckUtils::CheckAndTransferAutoLaunchParam(param, checkDir, schemaObject, canonicalDir); if (errCode != E_OK) { return errCode; } @@ -1013,7 +1014,7 @@ int AutoLaunch::GetAutoLaunchKVProperties(const AutoLaunchParam ¶m, if (param.option.isEncryptedDb) { propertiesPtr->SetPassword(param.option.cipher, param.option.passwd); } - propertiesPtr->SetStringProp(KvDBProperties::DATA_DIR, param.option.dataDir); + propertiesPtr->SetStringProp(KvDBProperties::DATA_DIR, canonicalDir); propertiesPtr->SetBoolProp(KvDBProperties::CREATE_IF_NECESSARY, param.option.createIfNecessary); propertiesPtr->SetBoolProp(KvDBProperties::CREATE_DIR_BY_STORE_ID_ONLY, param.option.createDirByStoreIdOnly); propertiesPtr->SetBoolProp(KvDBProperties::MEMORY_MODE, false); diff --git a/services/distributeddataservice/libs/distributeddb/common/src/param_check_utils.cpp b/services/distributeddataservice/libs/distributeddb/common/src/param_check_utils.cpp index 098735fef..1d498a370 100644 --- a/services/distributeddataservice/libs/distributeddb/common/src/param_check_utils.cpp +++ b/services/distributeddataservice/libs/distributeddb/common/src/param_check_utils.cpp @@ -145,8 +145,8 @@ bool ParamCheckUtils::IsS3SECEOpt(const SecurityOption &secOpt) return (secOpt == S3SeceOpt); } -int ParamCheckUtils::CheckAndTransferAutoLaunchParam(const AutoLaunchParam ¶m, - SchemaObject &schemaObject) +int ParamCheckUtils::CheckAndTransferAutoLaunchParam(const AutoLaunchParam ¶m, bool checkDir, + SchemaObject &schemaObject, std::string &canonicalDir) { if ((param.option.notifier && !ParamCheckUtils::CheckConflictNotifierType(param.option.conflictType)) || (!param.option.notifier && param.option.conflictType != 0)) { @@ -178,6 +178,16 @@ int ParamCheckUtils::CheckAndTransferAutoLaunchParam(const AutoLaunchParam ¶ return -E_INVALID_SCHEMA; } } + + if (!checkDir) { + canonicalDir = param.option.dataDir; + return E_OK; + } + + if (!ParamCheckUtils::CheckDataDir(param.option.dataDir, canonicalDir)) { + LOGE("[AutoLaunch] CheckDataDir is invalid."); + return -E_INVALID_ARGS; + } return E_OK; } diff --git a/services/distributeddataservice/libs/distributeddb/interfaces/src/kv_store_delegate_manager.cpp b/services/distributeddataservice/libs/distributeddb/interfaces/src/kv_store_delegate_manager.cpp index 6dff4d5e7..b9afb3c96 100644 --- a/services/distributeddataservice/libs/distributeddb/interfaces/src/kv_store_delegate_manager.cpp +++ b/services/distributeddataservice/libs/distributeddb/interfaces/src/kv_store_delegate_manager.cpp @@ -528,7 +528,7 @@ DBStatus KvStoreDelegateManager::EnableKvStoreAutoLaunch(const std::string &user } AutoLaunchParam param{ userId, appId, storeId, option, notifier, {}}; std::shared_ptr ptr = std::make_shared(); - int errCode = AutoLaunch::GetAutoLaunchProperties(param, DBType::DB_KV, ptr); + int errCode = AutoLaunch::GetAutoLaunchProperties(param, DBType::DB_KV, true, ptr); if (errCode != E_OK) { LOGE("[KvStoreManager] Enable auto launch failed:%d", errCode); return TransferDBErrno(errCode); -- Gitee From fb2618698914d8558b855e97e79e5eb491742f05 Mon Sep 17 00:00:00 2001 From: zqq Date: Fri, 11 Mar 2022 14:13:00 +0800 Subject: [PATCH 2/2] just query push check syncOperation Signed-off-by: zqq --- .../syncer/src/single_ver_sync_task_context.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/services/distributeddataservice/libs/distributeddb/syncer/src/single_ver_sync_task_context.cpp b/services/distributeddataservice/libs/distributeddb/syncer/src/single_ver_sync_task_context.cpp index 362a04f0c..456a03d70 100644 --- a/services/distributeddataservice/libs/distributeddb/syncer/src/single_ver_sync_task_context.cpp +++ b/services/distributeddataservice/libs/distributeddb/syncer/src/single_ver_sync_task_context.cpp @@ -479,14 +479,14 @@ DEFINE_OBJECT_TAG_FACILITIES(SingleVerSyncTaskContext) bool SingleVerSyncTaskContext::IsCurrentSyncTaskCanBeSkipped() const { - if (syncOperation_ == nullptr) { - return true; - } if (mode_ == SyncModeType::PUSH) { if (lastFullSyncTaskStatus_ != SyncOperation::OP_FINISHED_ALL) { return false; } } else if (mode_ == SyncModeType::QUERY_PUSH) { + if (syncOperation_ == nullptr) { + return true; + } auto it = lastQuerySyncTaskStatusMap_.find(syncOperation_->GetQueryId()); if (it == lastQuerySyncTaskStatusMap_.end()) { // no last query_push and push -- Gitee