From 56e95c111c62a95384d5a8493512f16a7460408e Mon Sep 17 00:00:00 2001 From: z30054037 Date: Mon, 13 Nov 2023 11:00:43 +0000 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BD=BF=E7=94=A8c++=E6=9D=A5=E6=9B=BF?= =?UTF-8?q?=E6=8D=A2rust=E7=9A=84=E7=9B=B8=E7=AD=89=E8=B7=AF=E5=BE=84?= =?UTF-8?q?=E8=BD=AC=E6=88=90=E7=BB=9D=E5=AF=B9=E8=B7=AF=E5=BE=84=E7=9A=84?= =?UTF-8?q?=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: z30054037 Change-Id: I68276a776963398b6e372f0ad14e8a77763e0274 --- utils/src/b_error/b_excep_utils.cpp | 32 ++++++++++++++--------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/utils/src/b_error/b_excep_utils.cpp b/utils/src/b_error/b_excep_utils.cpp index 032f51b34..b6065192e 100644 --- a/utils/src/b_error/b_excep_utils.cpp +++ b/utils/src/b_error/b_excep_utils.cpp @@ -16,9 +16,10 @@ #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 { @@ -26,26 +27,23 @@ 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 -- Gitee From fe3b16b6e4892f2bcb5536463b5815160a6a386e Mon Sep 17 00:00:00 2001 From: z30054037 Date: Thu, 16 Nov 2023 12:41:20 +0000 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BD=BF=E7=94=A8c++=E6=9D=A5=E6=9B=BF?= =?UTF-8?q?=E6=8D=A2rust=E7=9A=84=E7=9B=B8=E5=AF=B9=E8=B7=AF=E5=BE=84?= =?UTF-8?q?=E8=BD=AC=E6=88=90=E7=BB=9D=E5=AF=B9=E8=B7=AF=E5=BE=84=E7=9A=84?= =?UTF-8?q?=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: z30054037 Change-Id: I15abec68208f908d21ce31c6af5b2d57fea5c518 --- utils/src/b_error/b_excep_utils.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/utils/src/b_error/b_excep_utils.cpp b/utils/src/b_error/b_excep_utils.cpp index b6065192e..8ffc30323 100644 --- a/utils/src/b_error/b_excep_utils.cpp +++ b/utils/src/b_error/b_excep_utils.cpp @@ -20,7 +20,6 @@ #include #include "b_resources/b_constants.h" -#include "lib.rs.h" namespace OHOS::FileManagement::Backup { using namespace std; -- Gitee