diff --git a/frameworks/native/backup_ext/src/ext_extension.cpp b/frameworks/native/backup_ext/src/ext_extension.cpp index 31fe0acf27fc799fdabef4b749179882c3ff35cd..592b339d2bf72a5428555cfb9c81636a418dd365 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.fileName == 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.fileName == 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 3fe8dd7e0df51347af654678228f4fa268a3a392..dea7544e3658978db1db46f2d457c380b4c189c3 100644 --- a/services/backup_sa/src/module_ipc/service.cpp +++ b/services/backup_sa/src/module_ipc/service.cpp @@ -241,7 +241,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; @@ -727,7 +727,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 53c1b301b32ee49f3cf9f4a13f66178cbf2768c7..b43efe910066c6db161648741820a1e85d33f3b1 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 {