diff --git a/utils/src/b_error/b_excep_utils.cpp b/utils/src/b_error/b_excep_utils.cpp index 032f51b34e171014a63c918a4c6d139f017019b5..8ffc30323a6f3228ad04f226c51e3b64542587f7 100644 --- a/utils/src/b_error/b_excep_utils.cpp +++ b/utils/src/b_error/b_excep_utils.cpp @@ -16,36 +16,33 @@ #include "b_error/b_excep_utils.h" #include +#include +#include #include "b_resources/b_constants.h" -#include "cxx.h" -#include "lib.rs.h" namespace OHOS::FileManagement::Backup { using namespace std; void BExcepUltils::VerifyPath(const string_view &path, bool isExtension) { - try { - auto ret = canonicalize(path.data()); - string absPath = ret.c_str(); - if (isExtension && - absPath.find(string(BConstants::PATH_BUNDLE_BACKUP_HOME) - .append(BConstants::SA_BUNDLE_BACKUP_RESTORE)) == std::string::npos) { - throw BError(BError::Codes::EXT_INVAL_ARG, "Invalid path, not in backup restore path"); - } - } catch (const rust::Error &e) { - throw BError(BError::Codes::EXT_INVAL_ARG, "Invalid path"); + string absPath = BExcepUltils::Canonicalize(path); + if (isExtension && + absPath.find(string(BConstants::PATH_BUNDLE_BACKUP_HOME) + .append(BConstants::SA_BUNDLE_BACKUP_RESTORE)) == string::npos) { + throw BError(BError::Codes::EXT_INVAL_ARG, "Invalid path, not in backup restore 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"); - } + char full_path[PATH_MAX] = {0}; + //1.转换绝对路径到dir +#ifdef _WIN32 + _fullpath(full_path, path.data(), PATH_MAX); +#else + realpath(path.data(), full_path); +#endif + return string(full_path); } } // namespace OHOS::FileManagement::Backup