From 626c25b391ae57ef526b06b24e25ec9ebdae021c Mon Sep 17 00:00:00 2001 From: fengjq Date: Tue, 23 Jan 2024 17:46:33 +0800 Subject: [PATCH] Clear the warning from code check Signed-off-by: fengjq --- .../src/mod_fs/properties/prop_n_exporter.cpp | 66 +++++++++++-------- .../src/mod_fs/properties/prop_n_exporter.h | 3 + .../kits/js/src/mod_fs/properties/stat.cpp | 35 +++++----- 3 files changed, 61 insertions(+), 43 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 542aaea07..7cc695fcf 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 @@ -605,9 +605,43 @@ napi_value PropNExporter::WriteSync(napi_env env, napi_callback_info info) return NVal::CreateInt64(env, static_cast(ret)).val_; } -bool PropNExporter::Export() +#if !defined(WIN_PLATFORM) && !defined(IOS_PLATFORM) +bool PropNExporter::ExportAdvance() { return exports_.AddProp({ + NVal::DeclareNapiFunction("copyDir", CopyDir::Async), + NVal::DeclareNapiFunction("copyDirSync", CopyDir::Sync), + NVal::DeclareNapiFunction("copyFile", CopyFile::Async), + NVal::DeclareNapiFunction("copyFileSync", CopyFile::Sync), + NVal::DeclareNapiFunction("copy", Copy::Async), + NVal::DeclareNapiFunction("createRandomAccessFile", CreateRandomAccessFile::Async), + NVal::DeclareNapiFunction("createRandomAccessFileSync", CreateRandomAccessFile::Sync), + NVal::DeclareNapiFunction("createStream", CreateStream::Async), + NVal::DeclareNapiFunction("createStreamSync", CreateStream::Sync), + NVal::DeclareNapiFunction("dup", Dup::Sync), + NVal::DeclareNapiFunction("fdopenStream", FdopenStream::Async), + NVal::DeclareNapiFunction("fdopenStreamSync", FdopenStream::Sync), + NVal::DeclareNapiFunction("listFile", ListFile::Async), + NVal::DeclareNapiFunction("listFileSync", ListFile::Sync), + NVal::DeclareNapiFunction("lseek", Lseek::Sync), + NVal::DeclareNapiFunction("moveDir", MoveDir::Async), + NVal::DeclareNapiFunction("moveDirSync", MoveDir::Sync), + NVal::DeclareNapiFunction("moveFile", Move::Async), + NVal::DeclareNapiFunction("moveFileSync", Move::Sync), + NVal::DeclareNapiFunction("readLines", ReadLines::Async), + NVal::DeclareNapiFunction("readLinesSync", ReadLines::Sync), + NVal::DeclareNapiFunction("readText", ReadText::Async), + NVal::DeclareNapiFunction("readTextSync", ReadText::Sync), + NVal::DeclareNapiFunction("symlink", Symlink::Async), + NVal::DeclareNapiFunction("symlinkSync", Symlink::Sync), + NVal::DeclareNapiFunction("createWatcher", Watcher::CreateWatcher), + }); +} +#endif + +bool PropNExporter::Export() +{ + int ret = exports_.AddProp({ NVal::DeclareNapiFunction("access", Access), NVal::DeclareNapiFunction("accessSync", AccessSync), NVal::DeclareNapiFunction("close", Close::Async), @@ -639,35 +673,11 @@ bool PropNExporter::Export() NVal::DeclareNapiFunction("utimes", Utimes::Sync), NVal::DeclareNapiFunction("write", Write), NVal::DeclareNapiFunction("writeSync", WriteSync), + }); #if !defined(WIN_PLATFORM) && !defined(IOS_PLATFORM) - NVal::DeclareNapiFunction("copyDir", CopyDir::Async), - NVal::DeclareNapiFunction("copyDirSync", CopyDir::Sync), - NVal::DeclareNapiFunction("copyFile", CopyFile::Async), - NVal::DeclareNapiFunction("copyFileSync", CopyFile::Sync), - NVal::DeclareNapiFunction("copy", Copy::Async), - NVal::DeclareNapiFunction("createRandomAccessFile", CreateRandomAccessFile::Async), - NVal::DeclareNapiFunction("createRandomAccessFileSync", CreateRandomAccessFile::Sync), - NVal::DeclareNapiFunction("createStream", CreateStream::Async), - NVal::DeclareNapiFunction("createStreamSync", CreateStream::Sync), - NVal::DeclareNapiFunction("dup", Dup::Sync), - NVal::DeclareNapiFunction("fdopenStream", FdopenStream::Async), - NVal::DeclareNapiFunction("fdopenStreamSync", FdopenStream::Sync), - NVal::DeclareNapiFunction("listFile", ListFile::Async), - NVal::DeclareNapiFunction("listFileSync", ListFile::Sync), - NVal::DeclareNapiFunction("lseek", Lseek::Sync), - NVal::DeclareNapiFunction("moveDir", MoveDir::Async), - NVal::DeclareNapiFunction("moveDirSync", MoveDir::Sync), - NVal::DeclareNapiFunction("moveFile", Move::Async), - NVal::DeclareNapiFunction("moveFileSync", Move::Sync), - NVal::DeclareNapiFunction("readLines", ReadLines::Async), - NVal::DeclareNapiFunction("readLinesSync", ReadLines::Sync), - NVal::DeclareNapiFunction("readText", ReadText::Async), - NVal::DeclareNapiFunction("readTextSync", ReadText::Sync), - NVal::DeclareNapiFunction("symlink", Symlink::Async), - NVal::DeclareNapiFunction("symlinkSync", Symlink::Sync), - NVal::DeclareNapiFunction("createWatcher", Watcher::CreateWatcher), + ret = ExportAdvance(); #endif - }); + return ret; } #ifdef WIN_PLATFORM diff --git a/interfaces/kits/js/src/mod_fs/properties/prop_n_exporter.h b/interfaces/kits/js/src/mod_fs/properties/prop_n_exporter.h index 7333185a4..e38af3a53 100755 --- a/interfaces/kits/js/src/mod_fs/properties/prop_n_exporter.h +++ b/interfaces/kits/js/src/mod_fs/properties/prop_n_exporter.h @@ -60,6 +60,9 @@ public: static napi_value Read(napi_env env, napi_callback_info info); static napi_value Write(napi_env env, napi_callback_info info); bool Export() override; +#if !defined(WIN_PLATFORM) && !defined(IOS_PLATFORM) + bool ExportAdvance(); +#endif #ifdef WIN_PLATFORM std::string GetNExporterName() override; #else diff --git a/interfaces/kits/js/src/mod_fs/properties/stat.cpp b/interfaces/kits/js/src/mod_fs/properties/stat.cpp index 0bd0b8451..8fa6a0535 100644 --- a/interfaces/kits/js/src/mod_fs/properties/stat.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/stat.cpp @@ -110,6 +110,25 @@ napi_value Stat::Sync(napi_env env, napi_callback_info info) return stat; } +static NError StatCore(shared_ptr arg, shared_ptr fileInfo) +{ + std::unique_ptr stat_req = { + new (std::nothrow) uv_fs_t, CommonFunc::fs_req_cleanup }; + if (!stat_req) { + HILOGE("Failed to request heap memory."); + return NError(ENOMEM); + } + auto err = CheckFsStat(*fileInfo, stat_req.get()); + if (err) { + return err; + } + arg->stat_ = stat_req->statbuf; +#if !defined(WIN_PLATFORM) && !defined(IOS_PLATFORM) + arg->fileInfo_ = fileInfo; +#endif + return NError(ERRNO_NOERR); +} + napi_value Stat::Async(napi_env env, napi_callback_info info) { NFuncArg funcArg(env, info); @@ -129,21 +148,7 @@ napi_value Stat::Async(napi_env env, napi_callback_info info) return nullptr; } auto cbExec = [arg, fileInfo = make_shared(move(fileInfo))]() -> NError { - std::unique_ptr stat_req = { - new (std::nothrow) uv_fs_t, CommonFunc::fs_req_cleanup }; - if (!stat_req) { - HILOGE("Failed to request heap memory."); - return NError(ENOMEM); - } - auto err = CheckFsStat(*fileInfo, stat_req.get()); - if (err) { - return err; - } - arg->stat_ = stat_req->statbuf; -#if !defined(WIN_PLATFORM) && !defined(IOS_PLATFORM) - arg->fileInfo_ = fileInfo; -#endif - return NError(ERRNO_NOERR); + return StatCore(arg, fileInfo); }; auto cbCompl = [arg](napi_env env, NError err) -> NVal { if (err) { -- Gitee