From 38da759f878027d0da9dbe968abe662adf703627 Mon Sep 17 00:00:00 2001 From: xujintong Date: Mon, 20 Nov 2023 09:35:56 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BB=A3=E7=A0=81=E5=91=8A?= =?UTF-8?q?=E8=AD=A6=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: xujintong --- .../native/backup_ext/src/ext_extension.cpp | 17 +++++++++-------- services/backup_sa/src/module_ipc/service.cpp | 4 ++-- tools/backup_tool/src/tools_op_restore.cpp | 13 ++++++------- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/frameworks/native/backup_ext/src/ext_extension.cpp b/frameworks/native/backup_ext/src/ext_extension.cpp index 485f0b643..4d22553fc 100644 --- a/frameworks/native/backup_ext/src/ext_extension.cpp +++ b/frameworks/native/backup_ext/src/ext_extension.cpp @@ -222,14 +222,15 @@ static bool IsUserTar(const string &tarFile, const string &indexFile) if (tarFile.empty()) { return false; } - BJsonCachedEntity cachedEntity(UniqueFd(open(indexFile.data(), O_RDONLY))); + string filePath = BExcepUltils::Canonicalize(indexFile); + BJsonCachedEntity cachedEntity(UniqueFd(open(filePath.data(), O_RDONLY))); auto cache = cachedEntity.Structuralize(); auto info = cache.GetExtManageInfo(); - for (auto &item : info) { - if (item.hashName == tarFile) { - HILOGI("tarFile:%{public}s isUserTar:%{public}d", tarFile.data(), item.isUserTar); - return item.isUserTar; - } + auto iter = find_if(info.begin(), info.end(), + [&tarFile](const auto& item) { return item.hashName == tarFile; }); + if (iter != info.end()) { + HILOGI("tarFile:%{public}s isUserTar:%{public}d", tarFile.data(), iter->isUserTar); + return iter->isUserTar; } HILOGE("Can not find tarFile %{public}s", tarFile.data()); return false; @@ -243,7 +244,7 @@ static map> GetBigFileInfo(const vector return {}; } - auto GetStringHash = [](const map> &m, const string &str) -> string { + auto getStringHash = [](const map> &m, const string &str) -> string { ostringstream strHex; strHex << hex; @@ -262,7 +263,7 @@ static map> GetBigFileInfo(const vector map> bigFiles; for (const auto &item : files) { - string md5Name = GetStringHash(bigFiles, item.first); + string md5Name = getStringHash(bigFiles, item.first); if (!md5Name.empty()) { bigFiles.emplace(md5Name, make_tuple(item.first, item.second, true)); } diff --git a/services/backup_sa/src/module_ipc/service.cpp b/services/backup_sa/src/module_ipc/service.cpp index d33611279..2aa144e4e 100644 --- a/services/backup_sa/src/module_ipc/service.cpp +++ b/services/backup_sa/src/module_ipc/service.cpp @@ -242,7 +242,7 @@ static bool GetRestoreBundleNames(const vector &bun vector restoreBundleInfos {}; for (auto &restoreInfo : restoreInfos) { auto it = find_if(bundleInfos.begin(), bundleInfos.end(), - [&restoreInfo](auto &obj) { return obj.name == restoreInfo.name; }); + [&restoreInfo](const auto &obj) { return obj.name == restoreInfo.name; }); if (it == bundleInfos.end()) { HILOGE("Can't find %{public}s, append bundles error", restoreInfo.name.data()); return false; @@ -737,7 +737,7 @@ void Service::HandleRestoreDepsBundle(const string &bundleName) } // 启动恢复会话 vector restoreBundleNames {}; - for (auto &bundle : restoreBundleMap) { + for (const auto &bundle : restoreBundleMap) { HILOGI("Start restore session, bundle: %{public}s", bundle.first.c_str()); restoreBundleNames.emplace_back(bundle.first); } diff --git a/tools/backup_tool/src/tools_op_restore.cpp b/tools/backup_tool/src/tools_op_restore.cpp index 90c3538c3..b8493cf56 100644 --- a/tools/backup_tool/src/tools_op_restore.cpp +++ b/tools/backup_tool/src/tools_op_restore.cpp @@ -278,7 +278,6 @@ static int32_t InitRestoreSession(shared_ptr ctx) { if (!ctx) { throw BError(BError::Codes::TOOL_INVAL_ARG, generic_category().message(errno)); - return -1; } ctx->session_ = BSessionRestore::Init( BSessionRestore::Callbacks {.onFileReady = bind(OnFileReady, ctx, placeholders::_1, placeholders::_2), @@ -318,16 +317,16 @@ static int32_t InitPathCapFile(const string &pathCapFile, vector bundleN if (depMode) { for (auto &bundleName : bundleNames) { - UniqueFd fd(open(realPath.data(), O_RDWR, S_IRWXU)); - if (fd < 0) { + UniqueFd fileFd(open(realPath.data(), O_RDWR, S_IRWXU)); + if (fileFd < 0) { fprintf(stderr, "Failed to open file error: %d %s\n", errno, strerror(errno)); FinishTrace(HITRACE_TAG_FILEMANAGEMENT); return -errno; } - int ret = ctx->session_->AppendBundles(move(fd), {bundleName}); - if (ret != 0) { - printf("restore append bundles error: %d\n", ret); - return -ret; + int result = ctx->session_->AppendBundles(move(fileFd), {bundleName}); + if (result != 0) { + printf("restore append bundles error: %d\n", result); + return -result; } } } else { -- Gitee