From 5985ec3366b5867648c8259db2bbc83350a175a5 Mon Sep 17 00:00:00 2001 From: y30045862 Date: Wed, 30 Aug 2023 15:18:55 +0800 Subject: [PATCH] =?UTF-8?q?fs=20access=20=E6=94=AF=E6=8C=81uri=20Signed-of?= =?UTF-8?q?f-by:=20yangjingbo10=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I46c28e5662a1ea435720daa9b1b6928434b2ecda --- .../src/mod_fs/properties/prop_n_exporter.cpp | 29 ++++++++++++------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/interfaces/kits/js/src/mod_fs/properties/prop_n_exporter.cpp b/interfaces/kits/js/src/mod_fs/properties/prop_n_exporter.cpp index 4bcccb9e4..8fad6aa9f 100644 --- a/interfaces/kits/js/src/mod_fs/properties/prop_n_exporter.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/prop_n_exporter.cpp @@ -46,6 +46,7 @@ #include "create_randomaccessfile.h" #include "create_stream.h" #include "dup.h" +#include "file_uri.h" #include "fdopen_stream.h" #include "listfile.h" #include "move.h" @@ -77,7 +78,12 @@ napi_value PropNExporter::AccessSync(napi_env env, napi_callback_info info) return nullptr; } - bool isAccess = false; + string pathStr = string(path.get()); +#if !defined(WIN_PLATFORM) && !defined(IOS_PLATFORM) + AppFileService::ModuleFileUri::FileUri fileUri(pathStr); + pathStr = fileUri.GetRealPath(); +#endif + std::unique_ptr access_req = { new uv_fs_t, CommonFunc::fs_req_cleanup }; if (!access_req) { @@ -85,15 +91,13 @@ napi_value PropNExporter::AccessSync(napi_env env, napi_callback_info info) NError(ENOMEM).ThrowErr(env); return nullptr; } - int ret = uv_fs_access(nullptr, access_req.get(), path.get(), 0, nullptr); + int ret = uv_fs_access(nullptr, access_req.get(), pathStr.c_str(), 0, nullptr); if (ret < 0 && (string_view(uv_err_name(ret)) != "ENOENT")) { HILOGE("Failed to access file by path"); NError(ret).ThrowErr(env); return nullptr; } - if (ret == 0) { - isAccess = true; - } + bool isAccess = (ret == 0) ? true : false; return NVal::CreateBool(env, isAccess).val_; } @@ -113,23 +117,28 @@ napi_value PropNExporter::Access(napi_env env, napi_callback_info info) return nullptr; } + string pathStr = string(tmp.get()); +#if !defined(WIN_PLATFORM) && !defined(IOS_PLATFORM) + AppFileService::ModuleFileUri::FileUri fileUri(pathStr); + pathStr = fileUri.GetRealPath(); +#endif + auto result = CreateSharedPtr(); if (result == nullptr) { HILOGE("Failed to request heap memory."); NError(ENOMEM).ThrowErr(env); return nullptr; } - auto cbExec = [path = string(tmp.get()), result]() -> NError { + auto cbExec = [pathStr, result]() -> NError { std::unique_ptr access_req = { new uv_fs_t, CommonFunc::fs_req_cleanup }; if (!access_req) { HILOGE("Failed to request heap memory."); return NError(ENOMEM); } - int ret = uv_fs_access(nullptr, access_req.get(), path.c_str(), 0, nullptr); - if (ret == 0) { - result->isAccess = true; - } + int ret = uv_fs_access(nullptr, access_req.get(), pathStr.c_str(), 0, nullptr); + result->isAccess = (ret == 0) ? true : false; + return (ret < 0 && (string_view(uv_err_name(ret)) != "ENOENT")) ? NError(ret) : NError(ERRNO_NOERR); }; -- Gitee