diff --git a/tools/backup_tool/src/tools_op_restore_async.cpp b/tools/backup_tool/src/tools_op_restore_async.cpp index 104d2194a5098a75c14c1278df3fa5445c843634..44dd326db779fea8029096f28d2bac8669cc71f9 100644 --- a/tools/backup_tool/src/tools_op_restore_async.cpp +++ b/tools/backup_tool/src/tools_op_restore_async.cpp @@ -184,20 +184,8 @@ static int32_t ChangeBundleInfo(const string &pathCapFile, const vector for (auto name : bundleNames) { string versionName = string(BConstants::DEFAULT_VERSION_NAME); uint32_t versionCode = static_cast(BConstants::DEFAULT_VERSION_CODE); - if (type == "false") { - auto iter = find_if(infos.begin(), infos.end(), [name](const auto &it) { return it.name == name; }); - if (iter != infos.end()) { - versionName = iter->versionName; - versionCode = iter->versionCode; - } - } - string installPath = string(BConstants::BACKUP_TOOL_INSTALL_DIR) + name + ".hap"; - bool needToInstall = false; - if (access(installPath.data(), F_OK) == 0) { - needToInstall = true; - } bundleInfos.emplace_back(BJsonEntityCaps::BundleInfo { - .name = name, .needToInstall = needToInstall, .versionCode = versionCode, .versionName = versionName}); + .name = name, .needToInstall = false, .versionCode = versionCode, .versionName = versionName}); } cache.SetBundleInfos(bundleInfos); cachedEntity.Persist(); diff --git a/utils/include/b_error/b_excep_utils.h b/utils/include/b_error/b_excep_utils.h index 25275d602623c22ded2e8977fde6bc92b0794a0f..ac01921650fd064d7b13a352fadeda3a37dd1afd 100644 --- a/utils/include/b_error/b_excep_utils.h +++ b/utils/include/b_error/b_excep_utils.h @@ -72,6 +72,14 @@ public: * @param isExtension */ static void VerifyPath(const std::string_view &path, bool isExtension = false); + + /** + * @brief 获取规范化后的绝对路径 + * + * @param path 路径 + * @return std::string 返回绝对路径 + */ + static std::string Canonicalize(const std::string_view &path); }; } // namespace OHOS::FileManagement::Backup #endif // OHOS_FILEMGMT_BACKUP_B_EXCEP_UTILES_H \ No newline at end of file diff --git a/utils/src/b_error/b_excep_utils.cpp b/utils/src/b_error/b_excep_utils.cpp index 5a6ad2f9144af3aab7ee88fa01b613989fcb2901..032f51b34e171014a63c918a4c6d139f017019b5 100644 --- a/utils/src/b_error/b_excep_utils.cpp +++ b/utils/src/b_error/b_excep_utils.cpp @@ -38,4 +38,14 @@ void BExcepUltils::VerifyPath(const string_view &path, bool isExtension) throw BError(BError::Codes::EXT_INVAL_ARG, "Invalid path"); } } + +string BExcepUltils::Canonicalize(const string_view &path) +{ + try { + auto ret = canonicalize(path.data()); + return ret.c_str(); + } catch (const rust::Error &e) { + throw BError(BError::Codes::EXT_INVAL_ARG, "Invalid path"); + } +} } // namespace OHOS::FileManagement::Backup diff --git a/utils/src/b_tarball/b_tarball_factory.cpp b/utils/src/b_tarball/b_tarball_factory.cpp index ddfedd8a1bbfcf11a9fe5e21557ff63b12d5bd94..bed3c7006f1601ee4a5f702bcefb19c0f577a9be 100644 --- a/utils/src/b_tarball/b_tarball_factory.cpp +++ b/utils/src/b_tarball/b_tarball_factory.cpp @@ -28,10 +28,14 @@ #include #include "b_error/b_error.h" +#include "b_error/b_excep_utils.h" #include "b_tarball/b_tarball_cmdline.h" namespace OHOS::FileManagement::Backup { using namespace std; +namespace { +const string UNTAT_ROOT = "/"; +} // namespace /** * @brief Verifying untar input parameters @@ -41,8 +45,11 @@ using namespace std; */ static void UntarFort(string_view root) { - auto resolvedPath = make_unique(PATH_MAX); - if (!realpath(root.data(), resolvedPath.get()) || (string_view(resolvedPath.get()) != root)) { + auto resolvedPath = BExcepUltils::Canonicalize(root); + if (string_view(UNTAT_ROOT) != root) { + resolvedPath += UNTAT_ROOT; + } + if (string_view(resolvedPath) != root) { throw BError(BError::Codes::UTILS_INVAL_TARBALL_ARG, "The root must be an existing canonicalized path"); } }