From 1208c387b275d2a3ae2810bdbaece8448dddeac3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E6=A1=A2?= Date: Thu, 7 Sep 2023 14:37:30 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E5=85=AC=E5=85=B1=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E5=A4=87=E4=BB=BD=E6=81=A2=E5=A4=8D=EF=BC=8C=E6=8C=89=E7=85=A7?= =?UTF-8?q?=E5=BA=94=E7=94=A8=E5=B1=9E=E6=80=A7=EF=BC=8C=E6=81=A2=E5=A4=8D?= =?UTF-8?q?=E5=88=B0=E6=A0=B9=E7=9B=AE=E5=BD=95=E6=88=96=E8=80=85=E7=89=B9?= =?UTF-8?q?=E5=AE=9A=E7=9B=AE=E5=BD=95=E4=B8=8B=E3=80=82=202=E3=80=81?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=90=8C=E6=AD=A5=E8=B0=83=E7=94=A8=E9=98=BB?= =?UTF-8?q?=E5=A1=9E=E7=9A=84=E9=97=AE=E9=A2=98=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 王桢 --- frameworks/native/backup_ext/include/ext_backup.h | 7 +++++++ frameworks/native/backup_ext/src/ext_backup.cpp | 13 +++++++++++++ frameworks/native/backup_ext/src/ext_backup_js.cpp | 10 ++++++---- frameworks/native/backup_ext/src/ext_extension.cpp | 2 +- .../include/b_json/b_json_entity_extension_config.h | 9 ++++++++- utils/src/b_json/b_json_entity_extension_config.cpp | 12 +++++++++++- 6 files changed, 46 insertions(+), 7 deletions(-) diff --git a/frameworks/native/backup_ext/include/ext_backup.h b/frameworks/native/backup_ext/include/ext_backup.h index 73d64e731..bf2e48c6b 100644 --- a/frameworks/native/backup_ext/include/ext_backup.h +++ b/frameworks/native/backup_ext/include/ext_backup.h @@ -108,6 +108,13 @@ public: */ virtual bool AllowToBackupRestore() const; + /** + * @brief Get whether FullBackupOnly or not + * + * @return FullBackupOnly ro not + */ + virtual bool UseFullBackupOnly(void) const; + /** * @brief Get the user configure * diff --git a/frameworks/native/backup_ext/src/ext_backup.cpp b/frameworks/native/backup_ext/src/ext_backup.cpp index cf584ce06..127a5ca08 100644 --- a/frameworks/native/backup_ext/src/ext_backup.cpp +++ b/frameworks/native/backup_ext/src/ext_backup.cpp @@ -113,6 +113,19 @@ bool ExtBackup::AllowToBackupRestore() const return false; } +bool ExtBackup::UseFullBackupOnly(void) const +{ + string usrConfig = GetUsrConfig(); + BJsonCachedEntity cachedEntity(usrConfig); + auto cache = cachedEntity.Structuralize(); + if (cache.GetFullBackupOnly()) { + HILOGI("backup use fullBackupOnly."); + return true; + } + HILOGI("backup not use fullBackupOnly."); + return false; +} + BConstants::ExtensionAction ExtBackup::GetExtensionAction() const { return extAction_; diff --git a/frameworks/native/backup_ext/src/ext_backup_js.cpp b/frameworks/native/backup_ext/src/ext_backup_js.cpp index ef8cd0e7a..d2e58a09a 100644 --- a/frameworks/native/backup_ext/src/ext_backup_js.cpp +++ b/frameworks/native/backup_ext/src/ext_backup_js.cpp @@ -223,10 +223,11 @@ ErrCode ExtBackupJs::OnBackup(function callback) BExcepUltils::BAssert(jsObj_, BError::Codes::EXT_BROKEN_FRAMEWORK, "The app does not provide the onRestore interface."); callbackInfo_ = std::make_shared(callback); - auto retParser = [jsRuntime {&jsRuntime_}, callback, callbackInfo {callbackInfo_}](NativeEngine &engine, + auto retParser = [jsRuntime {&jsRuntime_}, callbackInfo {callbackInfo_}](NativeEngine &engine, NativeValue *result) -> bool { if (!CheckPromise(result)) { - return false; + callbackInfo->callback(); + return true; } HILOGI("CheckPromise(JS) OnBackup ok."); return CallPromise(*jsRuntime, result, callbackInfo.get()); @@ -257,10 +258,11 @@ ErrCode ExtBackupJs::OnRestore(function callback) return true; }; callbackInfo_ = std::make_shared(callback); - auto retParser = [jsRuntime {&jsRuntime_}, callback, callbackInfo {callbackInfo_}](NativeEngine &engine, + auto retParser = [jsRuntime {&jsRuntime_}, callbackInfo {callbackInfo_}](NativeEngine &engine, NativeValue *result) -> bool { if (!CheckPromise(result)) { - return false; + callbackInfo->callback(); + return true; } HILOGI("CheckPromise(JS) OnRestore ok."); return CallPromise(*jsRuntime, result, callbackInfo.get()); diff --git a/frameworks/native/backup_ext/src/ext_extension.cpp b/frameworks/native/backup_ext/src/ext_extension.cpp index 53cdf9bd1..1a1146937 100644 --- a/frameworks/native/backup_ext/src/ext_extension.cpp +++ b/frameworks/native/backup_ext/src/ext_extension.cpp @@ -312,7 +312,7 @@ int BackupExtExtension::DoRestore(const string &fileName) string tarName = path + fileName; auto tarballFunc = BTarballFactory::Create("cmdline", tarName); - if (extension_->WasFromSpeicalVersion()) { + if (extension_->WasFromSpeicalVersion() || extension_->UseFullBackupOnly()) { (tarballFunc->untar)(path); } else { (tarballFunc->untar)("/"); diff --git a/utils/include/b_json/b_json_entity_extension_config.h b/utils/include/b_json/b_json_entity_extension_config.h index b79dd06a3..54f002324 100644 --- a/utils/include/b_json/b_json_entity_extension_config.h +++ b/utils/include/b_json/b_json_entity_extension_config.h @@ -48,6 +48,13 @@ public: */ bool GetAllowToBackupRestore() const; + /** + * @brief 从JSon对象中获取备份标志 + * + * @return 备份标志: 是否恢复到根目录进行覆盖 + */ + bool GetFullBackupOnly() const; + public: std::string GetJSonSource(std::string_view jsonFromRealWorld, std::any option); @@ -62,4 +69,4 @@ public: }; } // namespace OHOS::FileManagement::Backup -#endif // OHOS_FILEMGMT_BACKUP_B_JSON_ENTITY_EXTENSION_CONFIG_H \ No newline at end of file +#endif // OHOS_FILEMGMT_BACKUP_B_JSON_ENTITY_EXTENSION_CONFIG_H diff --git a/utils/src/b_json/b_json_entity_extension_config.cpp b/utils/src/b_json/b_json_entity_extension_config.cpp index 39fed9282..0b63368d9 100644 --- a/utils/src/b_json/b_json_entity_extension_config.cpp +++ b/utils/src/b_json/b_json_entity_extension_config.cpp @@ -96,6 +96,16 @@ bool BJsonEntityExtensionConfig::GetAllowToBackupRestore() const return obj_["allowToBackupRestore"].asBool(); } +bool BJsonEntityExtensionConfig::GetFullBackupOnly() const +{ + if (!obj_ || !obj_.isMember("fullBackupOnly") || !obj_["fullBackupOnly"].isBool()) { + HILOGE("Failed to init field fullBackupOnly"); + return false; + } + + return obj_["fullBackupOnly"].asBool(); +} + string BJsonEntityExtensionConfig::GetJSonSource(string_view jsonFromRealWorld, any option) { if (!BackupPara().GetBackupDebugOverrideExtensionConfig()) { @@ -126,4 +136,4 @@ string BJsonEntityExtensionConfig::GetJSonSource(string_view jsonFromRealWorld, append(BConstants::BACKUP_CONFIG_JSON); return BFile::ReadFile(UniqueFd(open(jsonFilePath.c_str(), O_RDONLY))).get(); } -} // namespace OHOS::FileManagement::Backup \ No newline at end of file +} // namespace OHOS::FileManagement::Backup -- Gitee