From 4fe897429e560a4b2bed5c29468e405e2bdf89d1 Mon Sep 17 00:00:00 2001 From: l30052632 Date: Sat, 21 Sep 2024 09:57:25 +0800 Subject: [PATCH] =?UTF-8?q?file=5Fapi:add=20errCode=20for=20filesystem=20?= =?UTF-8?q?=EF=BC=88cherry=20picked=20commit=20from=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kits/js/src/mod_fs/properties/copydir.cpp | 9 +++++---- interfaces/kits/js/src/mod_fs/properties/move.cpp | 3 ++- .../kits/js/src/mod_fs/properties/movedir.cpp | 14 ++++++++------ 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/interfaces/kits/js/src/mod_fs/properties/copydir.cpp b/interfaces/kits/js/src/mod_fs/properties/copydir.cpp index 493a6f1cf..9fea4356c 100644 --- a/interfaces/kits/js/src/mod_fs/properties/copydir.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/copydir.cpp @@ -48,13 +48,14 @@ static tuple, unique_ptr, int> ParseAndCheckJsO const NFuncArg &funcArg) { auto [resGetFirstArg, src, ignore] = NVal(env, funcArg[NARG_POS::FIRST]).ToUTF8StringPath(); - if (!resGetFirstArg || !filesystem::is_directory(filesystem::status(src.get()))) { - HILOGE("Invalid src"); + std::error_code errCode; + if (!resGetFirstArg || !filesystem::is_directory(filesystem::status(src.get(), errCode))) { + HILOGE("Invalid src, errCode = %{public}d", errCode.value()); return { false, nullptr, nullptr, 0 }; } auto [resGetSecondArg, dest, unused] = NVal(env, funcArg[NARG_POS::SECOND]).ToUTF8StringPath(); - if (!resGetSecondArg || !filesystem::is_directory(filesystem::status(dest.get()))) { - HILOGE("Invalid dest"); + if (!resGetSecondArg || !filesystem::is_directory(filesystem::status(dest.get(), errCode))) { + HILOGE("Invalid dest, errCode = %{public}d", errCode.value()); return { false, nullptr, nullptr, 0 }; } if (!AllowToCopy(src.get(), dest.get())) { diff --git a/interfaces/kits/js/src/mod_fs/properties/move.cpp b/interfaces/kits/js/src/mod_fs/properties/move.cpp index 59e7fb97f..f75481d88 100644 --- a/interfaces/kits/js/src/mod_fs/properties/move.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/move.cpp @@ -37,7 +37,8 @@ using namespace OHOS::FileManagement::LibN; #ifdef __MUSL__ static bool CheckDir(const string &path) { - if (!filesystem::is_directory(filesystem::status(path))) { + std::error_code errCode; + if (!filesystem::is_directory(filesystem::status(path, errCode))) { return false; } return true; diff --git a/interfaces/kits/js/src/mod_fs/properties/movedir.cpp b/interfaces/kits/js/src/mod_fs/properties/movedir.cpp index 4a6a8781c..69231819f 100644 --- a/interfaces/kits/js/src/mod_fs/properties/movedir.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/movedir.cpp @@ -41,7 +41,7 @@ static tuple JudgeExistAndEmpty(const string &path) std::error_code errCode; filesystem::path pathName(path); if (filesystem::exists(pathName, errCode)) { - if (filesystem::is_empty(pathName)) { + if (filesystem::is_empty(pathName, errCode)) { return { true, true }; } return { true, false }; @@ -81,13 +81,14 @@ static int RemovePath(const string& pathStr) static tuple, unique_ptr, int> ParseJsOperand(napi_env env, const NFuncArg& funcArg) { auto [resGetFirstArg, src, ignore] = NVal(env, funcArg[NARG_POS::FIRST]).ToUTF8StringPath(); - if (!resGetFirstArg || !filesystem::is_directory(filesystem::status(src.get()))) { - HILOGE("Invalid src"); + std::error_code errCode; + if (!resGetFirstArg || !filesystem::is_directory(filesystem::status(src.get(), errCode))) { + HILOGE("Invalid src, errCode = %{public}d", errCode.value()); return { false, nullptr, nullptr, 0 }; } auto [resGetSecondArg, dest, unused] = NVal(env, funcArg[NARG_POS::SECOND]).ToUTF8StringPath(); - if (!resGetSecondArg || !filesystem::is_directory(filesystem::status(dest.get()))) { - HILOGE("Invalid dest"); + if (!resGetSecondArg || !filesystem::is_directory(filesystem::status(dest.get(), errCode))) { + HILOGE("Invalid dest,errCode = %{public}d", errCode.value()); return { false, nullptr, nullptr, 0 }; } int mode = 0; @@ -200,7 +201,8 @@ static int RecurMoveDir(const string &srcPath, const string &destPath, const int deque &errfiles) { filesystem::path dpath(destPath); - if (!filesystem::is_directory(dpath)) { + std::error_code errCode; + if (!filesystem::is_directory(dpath, errCode)) { errfiles.emplace_front(srcPath, destPath); return ERRNO_NOERR; } -- Gitee