From 7e532871e9ba82b7d79872487db553c7705c8c7c Mon Sep 17 00:00:00 2001 From: wangpggg Date: Wed, 11 Sep 2024 14:22:32 +0800 Subject: [PATCH] modify unsigned to signed Signed-off-by: wangpeng --- .../native/backup_ext/src/ext_extension.cpp | 127 +----------------- .../backup_ext/src/sub_ext_extension.cpp | 126 +++++++++++++++++ utils/include/b_radar/b_radar.h | 6 +- 3 files changed, 130 insertions(+), 129 deletions(-) diff --git a/frameworks/native/backup_ext/src/ext_extension.cpp b/frameworks/native/backup_ext/src/ext_extension.cpp index 40b1f73b1..5bf369cce 100644 --- a/frameworks/native/backup_ext/src/ext_extension.cpp +++ b/frameworks/native/backup_ext/src/ext_extension.cpp @@ -49,6 +49,7 @@ #include "b_jsonutil/b_jsonutil.h" #include "b_ohos/startup/backup_para.h" #include "b_tarball/b_tarball_factory.h" +#include "b_utils/b_time.h" #include "filemgmt_libhilog.h" #include "hitrace_meter.h" #include "i_service.h" @@ -2106,130 +2107,4 @@ int BackupExtExtension::DoIncrementalBackup(const vector smallFiles.size(), allFiles.size()); return err; } - -bool BackupExtExtension::IfAllowToBackupRestore() -{ - if (extension_ == nullptr) { - HILOGE("Failed to handle backup, extension is nullptr"); - return false; - } - string usrConfig = extension_->GetUsrConfig(); - BJsonCachedEntity cachedEntity(usrConfig); - auto cache = cachedEntity.Structuralize(); - if (!cache.GetAllowToBackupRestore()) { - HILOGE("Application does not allow backup or restore"); - return false; - } - return true; -} - -ErrCode BackupExtExtension::User0OnBackup() -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - if (!IfAllowToBackupRestore()) { - return BError(BError::Codes::EXT_FORBID_BACKUP_RESTORE, "Application does not allow backup or restore") - .GetCode(); - } - AsyncTaskUser0Backup(); - return ERR_OK; -} - -void BackupExtExtension::AsyncTaskUser0Backup() -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - auto task = [obj {wptr(this)}]() { - auto ptr = obj.promote(); - BExcepUltils::BAssert(ptr, BError::Codes::EXT_BROKEN_FRAMEWORK, "Ext extension handle have been released"); - const string config = ptr->extension_->GetUsrConfig(); - try { - HILOGI("Do backup, start fwk timer begin."); - bool isFwkStart; - ptr->StartFwkTimer(isFwkStart); - if (!isFwkStart) { - HILOGE("Do backup, start fwk timer fail."); - return; - } - HILOGI("Do backup, start fwk timer end."); - BJsonCachedEntity cachedEntity(config); - auto cache = cachedEntity.Structuralize(); - auto ret = ptr->User0DoBackup(cache); - if (ret != ERR_OK) { - HILOGE("User0DoBackup, err = %{pubilc}d", ret); - ptr->AppIncrementalDone(BError::GetCodeByErrno(ret)); - } - } catch (const BError &e) { - HILOGE("extension: AsyncTaskBackup error, err code:%{public}d", e.GetCode()); - ptr->AppIncrementalDone(e.GetCode()); - } catch (const exception &e) { - HILOGE("Catched an unexpected low-level exception %{public}s", e.what()); - ptr->AppIncrementalDone(BError(BError::Codes::EXT_INVAL_ARG).GetCode()); - } catch (...) { - HILOGE("Failed to restore the ext bundle"); - ptr->AppIncrementalDone(BError(BError::Codes::EXT_INVAL_ARG).GetCode()); - } - }; - - threadPool_.AddTask([task]() { - try { - task(); - } catch (...) { - HILOGE("Failed to add task to thread pool"); - } - }); -} - -void BackupExtExtension::DoUser0Backup(const BJsonEntityExtensionConfig &usrConfig) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - string path = string(BConstants::PATH_BUNDLE_BACKUP_HOME).append(BConstants::SA_BUNDLE_BACKUP_BACKUP); - if (mkdir(path.data(), S_IRWXU) && errno != EEXIST) { - throw BError(errno); - } - vector includes = usrConfig.GetIncludes(); - vector excludes = usrConfig.GetExcludes(); - auto task = [obj {wptr(this)}, includes, excludes]() { - auto ptr = obj.promote(); - BExcepUltils::BAssert(ptr, BError::Codes::EXT_BROKEN_FRAMEWORK, "Ext extension handle have been released"); - try { - auto [bigFile, smallFile] = BDir::GetBackupList(includes, excludes); - vector allFiles; - vector smallFiles; - vector bigFiles; - BDir::GetUser0FileStat(move(bigFile), move(smallFile), allFiles, smallFiles, bigFiles); - auto ret = ptr->DoIncrementalBackup(allFiles, smallFiles, bigFiles); - ptr->AppIncrementalDone(ret); - HILOGI("User0 backup app done %{public}d", ret); - } catch (const BError &e) { - ptr->AppIncrementalDone(e.GetCode()); - } catch (const exception &e) { - ptr->AppIncrementalDone(BError(BError::Codes::EXT_INVAL_ARG).GetCode()); - } catch (...) { - HILOGE("Failed to restore the ext bundle"); - ptr->AppIncrementalDone(BError(BError::Codes::EXT_INVAL_ARG).GetCode()); - } - }; - - threadPool_.AddTask([task]() { - try { - task(); - } catch (...) { - HILOGE("Failed to add task to thread pool"); - } - }); -} - -int BackupExtExtension::User0DoBackup(const BJsonEntityExtensionConfig &usrConfig) -{ - HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); - HILOGI("Start Do User0Backup"); - if (extension_ == nullptr) { - HILOGE("Failed to do backup, extension is nullptr"); - return BError(BError::Codes::EXT_INVAL_ARG); - } - if (extension_->GetExtensionAction() != BConstants::ExtensionAction::BACKUP) { - return EPERM; - } - DoUser0Backup(usrConfig); - return ERR_OK; -} } // namespace OHOS::FileManagement::Backup diff --git a/frameworks/native/backup_ext/src/sub_ext_extension.cpp b/frameworks/native/backup_ext/src/sub_ext_extension.cpp index 926780571..e1225f60e 100644 --- a/frameworks/native/backup_ext/src/sub_ext_extension.cpp +++ b/frameworks/native/backup_ext/src/sub_ext_extension.cpp @@ -781,4 +781,130 @@ bool BackupExtExtension::SetStagingPathProperties() } return true; } + +bool BackupExtExtension::IfAllowToBackupRestore() +{ + if (extension_ == nullptr) { + HILOGE("Failed to handle backup, extension is nullptr"); + return false; + } + string usrConfig = extension_->GetUsrConfig(); + BJsonCachedEntity cachedEntity(usrConfig); + auto cache = cachedEntity.Structuralize(); + if (!cache.GetAllowToBackupRestore()) { + HILOGE("Application does not allow backup or restore"); + return false; + } + return true; +} + +ErrCode BackupExtExtension::User0OnBackup() +{ + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); + if (!IfAllowToBackupRestore()) { + return BError(BError::Codes::EXT_FORBID_BACKUP_RESTORE, "Application does not allow backup or restore") + .GetCode(); + } + AsyncTaskUser0Backup(); + return ERR_OK; +} + +void BackupExtExtension::AsyncTaskUser0Backup() +{ + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); + auto task = [obj {wptr(this)}]() { + auto ptr = obj.promote(); + BExcepUltils::BAssert(ptr, BError::Codes::EXT_BROKEN_FRAMEWORK, "Ext extension handle have been released"); + const string config = ptr->extension_->GetUsrConfig(); + try { + HILOGI("Do backup, start fwk timer begin."); + bool isFwkStart; + ptr->StartFwkTimer(isFwkStart); + if (!isFwkStart) { + HILOGE("Do backup, start fwk timer fail."); + return; + } + HILOGI("Do backup, start fwk timer end."); + BJsonCachedEntity cachedEntity(config); + auto cache = cachedEntity.Structuralize(); + auto ret = ptr->User0DoBackup(cache); + if (ret != ERR_OK) { + HILOGE("User0DoBackup, err = %{pubilc}d", ret); + ptr->AppIncrementalDone(BError::GetCodeByErrno(ret)); + } + } catch (const BError &e) { + HILOGE("extension: AsyncTaskBackup error, err code:%{public}d", e.GetCode()); + ptr->AppIncrementalDone(e.GetCode()); + } catch (const exception &e) { + HILOGE("Catched an unexpected low-level exception %{public}s", e.what()); + ptr->AppIncrementalDone(BError(BError::Codes::EXT_INVAL_ARG).GetCode()); + } catch (...) { + HILOGE("Failed to restore the ext bundle"); + ptr->AppIncrementalDone(BError(BError::Codes::EXT_INVAL_ARG).GetCode()); + } + }; + + threadPool_.AddTask([task]() { + try { + task(); + } catch (...) { + HILOGE("Failed to add task to thread pool"); + } + }); +} + +void BackupExtExtension::DoUser0Backup(const BJsonEntityExtensionConfig &usrConfig) +{ + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); + string path = string(BConstants::PATH_BUNDLE_BACKUP_HOME).append(BConstants::SA_BUNDLE_BACKUP_BACKUP); + if (mkdir(path.data(), S_IRWXU) && errno != EEXIST) { + throw BError(errno); + } + vector includes = usrConfig.GetIncludes(); + vector excludes = usrConfig.GetExcludes(); + auto task = [obj {wptr(this)}, includes, excludes]() { + auto ptr = obj.promote(); + BExcepUltils::BAssert(ptr, BError::Codes::EXT_BROKEN_FRAMEWORK, "Ext extension handle have been released"); + try { + auto [bigFile, smallFile] = BDir::GetBackupList(includes, excludes); + vector allFiles; + vector smallFiles; + vector bigFiles; + BDir::GetUser0FileStat(move(bigFile), move(smallFile), allFiles, smallFiles, bigFiles); + auto ret = ptr->DoIncrementalBackup(allFiles, smallFiles, bigFiles); + ptr->AppIncrementalDone(ret); + HILOGI("User0 backup app done %{public}d", ret); + } catch (const BError &e) { + ptr->AppIncrementalDone(e.GetCode()); + } catch (const exception &e) { + ptr->AppIncrementalDone(BError(BError::Codes::EXT_INVAL_ARG).GetCode()); + } catch (...) { + HILOGE("Failed to restore the ext bundle"); + ptr->AppIncrementalDone(BError(BError::Codes::EXT_INVAL_ARG).GetCode()); + } + }; + + threadPool_.AddTask([task]() { + try { + task(); + } catch (...) { + HILOGE("Failed to add task to thread pool"); + } + }); +} + +int BackupExtExtension::User0DoBackup(const BJsonEntityExtensionConfig &usrConfig) +{ + HITRACE_METER_NAME(HITRACE_TAG_FILEMANAGEMENT, __PRETTY_FUNCTION__); + HILOGI("Start Do User0Backup"); + if (extension_ == nullptr) { + HILOGE("Failed to do backup, extension is nullptr"); + return BError(BError::Codes::EXT_INVAL_ARG); + } + if (extension_->GetExtensionAction() != BConstants::ExtensionAction::BACKUP) { + return EPERM; + } + DoUser0Backup(usrConfig); + return ERR_OK; +} } // namespace OHOS::FileManagement::Backup diff --git a/utils/include/b_radar/b_radar.h b/utils/include/b_radar/b_radar.h index 87fd5ac4e..226e0ece4 100644 --- a/utils/include/b_radar/b_radar.h +++ b/utils/include/b_radar/b_radar.h @@ -76,11 +76,11 @@ public: struct DoRestoreInfo { uint32_t bigFileNum; uint64_t bigFileSize; - uint32_t bigFileSpendTime; + int64_t bigFileSpendTime; uint32_t tarFileNum; uint64_t tarFileSize; - uint32_t tarFileSpendTime; - uint32_t totalFileSpendTime; + int64_t tarFileSpendTime; + int64_t totalFileSpendTime; }; public: -- Gitee