diff --git a/services/distributeddataservice/libs/distributeddb/common/include/auto_launch.h b/services/distributeddataservice/libs/distributeddb/common/include/auto_launch.h index ea898c47c2bbcb8cf01de8ed54638ac32a12612d..6debcc82f8d9ad7097fe95b125c4fc36d26aaa29 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 a5927a266225456da0c9b44ab59d0a6a7c0d9396..f55e66a4622c7aa372859ffb9835c318dceda1f7 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 2ef7cd1ab4ee1c6e108eb344ef47c1b893b6231a..979b3dd4fc1cfb9221ee7bb2f4f16fb0c5565884 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 098735fefcd5b66a3af325b7462b54be853f149f..1d498a370fa2a124a733401cfc6c5b37999c61d9 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 6dff4d5e7ec2abd8483b4953a7e5ab1a676ff1b9..b9afb3c96d16ddf3a1e103684a68a247047686f4 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); 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 362a04f0c797884fe8d934dac7735fb5934737c1..456a03d709fe54283713385e03d255555ac13f95 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