diff --git a/interfaces/kits/js/src/mod_fs/properties/copydir.cpp b/interfaces/kits/js/src/mod_fs/properties/copydir.cpp index 6444c2e6edc62e47905f6c1a60d3710da2ac1ed5..e61809848ec0225eda77933a219e5bcc64052400 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 59e7fb97fb501d95d604944ce86cc217279b0d5e..f0daaf0f9b3b0e5af2cb0aa8915cbcc2d56d0626 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)) && errCode.value() == 0) { return false; } return true; @@ -65,7 +66,7 @@ static tuple, unique_ptr, int> ParseJsOperand(n return { false, nullptr, nullptr, 0 }; } auto [resGetSecondArg, dest, unused] = NVal(env, funcArg[NARG_POS::SECOND]).ToUTF8StringPath(); - if (!resGetSecondArg || CheckDir(string(dest.get()))) { + if (!resGetSecondArg) { HILOGE("Invalid dest"); return { false, nullptr, nullptr, 0 }; } diff --git a/interfaces/kits/js/src/mod_fs/properties/movedir.cpp b/interfaces/kits/js/src/mod_fs/properties/movedir.cpp index dd438202a35ff59cb9ff6bf09b6b6f300bb8cb04..522626fd741ed2f3c33c60af8e02fa65d158f041 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; @@ -203,11 +204,16 @@ 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) && errCode.value() == 0) { errfiles.emplace_front(srcPath, destPath); return ERRNO_NOERR; } + if (errCode.value() != 0) { + return errCode.value(); + } + unique_ptr ptr = {new struct NameListArg, Deleter}; if (!ptr) { HILOGE("Failed to request heap memory.");