From 7485f49ace34acef5c0fc1bc4e2d489ba2667cf7 Mon Sep 17 00:00:00 2001 From: 18721213663 Date: Wed, 15 Nov 2023 09:32:26 +0800 Subject: [PATCH] fileapi_remove_chmod&symlink Signed-off-by: 18721213663 --- .../js/src/mod_fileio/properties/chmod.cpp | 66 +--------------- .../js/src/mod_fileio/properties/chown.cpp | 75 +----------------- .../js/src/mod_fileio/properties/fchmod.cpp | 68 +--------------- .../js/src/mod_fileio/properties/fchown.cpp | 79 +------------------ .../js/src/mod_fileio/properties/lchown.cpp | 74 +---------------- 5 files changed, 5 insertions(+), 357 deletions(-) diff --git a/interfaces/kits/js/src/mod_fileio/properties/chmod.cpp b/interfaces/kits/js/src/mod_fileio/properties/chmod.cpp index cf8b348de..bfef7ca25 100644 --- a/interfaces/kits/js/src/mod_fileio/properties/chmod.cpp +++ b/interfaces/kits/js/src/mod_fileio/properties/chmod.cpp @@ -31,76 +31,12 @@ using namespace std; napi_value Chmod::Sync(napi_env env, napi_callback_info info) { - NFuncArg funcArg(env, info); - if (!funcArg.InitArgs(NARG_CNT::TWO)) { - UniError(EINVAL).ThrowErr(env, "Number of arguments unmatched"); - return nullptr; - } - - auto [resGetFirstArg, path, unused] = NVal(env, funcArg[NARG_POS::FIRST]).ToUTF8String(); - if (!resGetFirstArg) { - UniError(EINVAL).ThrowErr(env, "Invalid path"); - return nullptr; - } - - auto [resGetSecondArg, mode] = NVal(env, funcArg[NARG_POS::SECOND]).ToInt32(); - if (!resGetSecondArg) { - UniError(EINVAL).ThrowErr(env, "Invalid mode"); - return nullptr; - } - - if (chmod(path.get(), mode) == -1) { - UniError(errno).ThrowErr(env); - return nullptr; - } - return NVal::CreateUndefined(env).val_; } napi_value Chmod::Async(napi_env env, napi_callback_info info) { - NFuncArg funcArg(env, info); - if (!funcArg.InitArgs(NARG_CNT::TWO, NARG_CNT::THREE)) { - UniError(EINVAL).ThrowErr(env, "Number of arguments unmatched"); - return nullptr; - } - - auto [resGetFirstArg, tmp, unused] = NVal(env, funcArg[NARG_POS::FIRST]).ToUTF8String(); - if (!resGetFirstArg) { - UniError(EINVAL).ThrowErr(env, "Invalid path"); - return nullptr; - } - - auto [resGetSecondArg, mode] = NVal(env, funcArg[NARG_POS::SECOND]).ToInt32(); - if (!resGetSecondArg) { - UniError(EINVAL).ThrowErr(env, "Invalid mode"); - } - - string path = tmp.get(); - auto cbExec = [path = path, mode = mode](napi_env env) -> UniError { - if (chmod(path.c_str(), mode) == -1) { - return UniError(errno); - } else { - return UniError(ERRNO_NOERR); - } - }; - - auto cbComplete = [](napi_env env, UniError err) -> NVal { - if (err) { - return { env, err.GetNapiErr(env) }; - } - return { NVal::CreateUndefined(env) }; - }; - - size_t argc = funcArg.GetArgc(); - NVal thisVar(env, funcArg.GetThisVar()); - const string procedureName = "FileIOChmod"; - if (argc == NARG_CNT::TWO) { - return NAsyncWorkPromise(env, thisVar).Schedule(procedureName, cbExec, cbComplete).val_; - } else { - NVal cb(env, funcArg[NARG_POS::THIRD]); - return NAsyncWorkCallback(env, thisVar, cb).Schedule(procedureName, cbExec, cbComplete).val_; - } + return NVal::CreateUndefined(env).val_; } } // namespace ModuleFileIO } // namespace DistributedFS diff --git a/interfaces/kits/js/src/mod_fileio/properties/chown.cpp b/interfaces/kits/js/src/mod_fileio/properties/chown.cpp index 12d0edd04..8cac52c70 100644 --- a/interfaces/kits/js/src/mod_fileio/properties/chown.cpp +++ b/interfaces/kits/js/src/mod_fileio/properties/chown.cpp @@ -28,87 +28,14 @@ namespace DistributedFS { namespace ModuleFileIO { using namespace std; -static tuple GetChownArg(napi_env env, const NFuncArg &funcArg) -{ - auto [resGetFirstArg, path, unused] = NVal(env, funcArg[NARG_POS::FIRST]).ToUTF8String(); - if (!resGetFirstArg) { - UniError(EINVAL).ThrowErr(env, "Invalid path"); - return { false, "", -1, -1 }; - } - - auto [resGetSecondArg, owner] = NVal(env, funcArg[NARG_POS::SECOND]).ToInt32(); - if (!resGetSecondArg) { - UniError(EINVAL).ThrowErr(env, "Invalid owner"); - return { false, "", -1, -1 }; - } - - auto [resGetThirdArg, group] = NVal(env, funcArg[NARG_POS::THIRD]).ToInt32(); - if (!resGetThirdArg) { - UniError(EINVAL).ThrowErr(env, "Invalid group"); - return { false, "", -1, -1 }; - } - - return { true, path.get(), owner, group }; -} - napi_value Chown::Sync(napi_env env, napi_callback_info info) { - NFuncArg funcArg(env, info); - if (!funcArg.InitArgs(NARG_CNT::THREE)) { - UniError(EINVAL).ThrowErr(env, "Number of arguments unmatched"); - return nullptr; - } - - auto [resGetChownArg, path, owner, group] = GetChownArg(env, funcArg); - if (!resGetChownArg) { - return nullptr; - } - - if (chown(path.c_str(), owner, group) == -1) { - UniError(errno).ThrowErr(env); - return nullptr; - } - return NVal::CreateUndefined(env).val_; } napi_value Chown::Async(napi_env env, napi_callback_info info) { - NFuncArg funcArg(env, info); - if (!funcArg.InitArgs(NARG_CNT::THREE, NARG_CNT::FOUR)) { - UniError(EINVAL).ThrowErr(env, "Number of arguments unmatched"); - return nullptr; - } - - auto [resGetChownArg, path, owner, group] = GetChownArg(env, funcArg); - if (!resGetChownArg) { - return nullptr; - } - - auto cbExec = [path = path, owner = owner, group = group](napi_env env) -> UniError { - if (chown(path.c_str(), owner, group) == -1) { - return UniError(errno); - } else { - return UniError(ERRNO_NOERR); - } - }; - - auto cbCompl = [](napi_env env, UniError err) -> NVal { - if (err) { - return { env, err.GetNapiErr(env) }; - } - return { NVal::CreateUndefined(env) }; - }; - - const string procedureName = "FileIOChown"; - NVal thisVar(env, funcArg.GetThisVar()); - if (funcArg.GetArgc() == NARG_CNT::THREE) { - return NAsyncWorkPromise(env, thisVar).Schedule(procedureName, cbExec, cbCompl).val_; - } else { - int cbIdx = NARG_POS::FOURTH; - NVal cb(env, funcArg[cbIdx]); - return NAsyncWorkCallback(env, thisVar, cb).Schedule(procedureName, cbExec, cbCompl).val_; - } + return NVal::CreateUndefined(env).val_; } } // namespace ModuleFileIO } // namespace DistributedFS diff --git a/interfaces/kits/js/src/mod_fileio/properties/fchmod.cpp b/interfaces/kits/js/src/mod_fileio/properties/fchmod.cpp index 8715b994c..159ef1b40 100644 --- a/interfaces/kits/js/src/mod_fileio/properties/fchmod.cpp +++ b/interfaces/kits/js/src/mod_fileio/properties/fchmod.cpp @@ -30,79 +30,13 @@ using namespace std; napi_value Fchmod::Sync(napi_env env, napi_callback_info info) { - NFuncArg funcArg(env, info); - if (!funcArg.InitArgs(NARG_CNT::TWO)) { - UniError(EINVAL).ThrowErr(env, "Number of arguments unmatched"); - return nullptr; - } - - auto [resGetFirstArg, fd] = NVal(env, funcArg[NARG_POS::FIRST]).ToInt32(); - if (!resGetFirstArg) { - UniError(EINVAL).ThrowErr(env, "Invalid fd"); - return nullptr; - } - - auto [resGetSecondArg, mode] = NVal(env, funcArg[NARG_POS::SECOND]).ToInt32(); - if (!resGetSecondArg) { - UniError(EINVAL).ThrowErr(env, "Invalid mode"); - return nullptr; - } - - int ret = fchmod(fd, mode); - if (ret == -1) { - UniError(errno).ThrowErr(env); - return nullptr; - } - return NVal::CreateUndefined(env).val_; } napi_value Fchmod::Async(napi_env env, napi_callback_info info) { - NFuncArg funcArg(env, info); - if (!funcArg.InitArgs(NARG_CNT::TWO, NARG_CNT::THREE)) { - UniError(EINVAL).ThrowErr(env, "Number of arguments unmatched"); - return nullptr; - } - - auto [resGetFirstArg, fd] = NVal(env, funcArg[NARG_POS::FIRST]).ToInt32(); - if (!resGetFirstArg) { - UniError(EINVAL).ThrowErr(env, "Invalid fd"); - return nullptr; - } - - auto [resGetSecondArg, mode] = NVal(env, funcArg[NARG_POS::SECOND]).ToInt32(); - if (!resGetSecondArg) { - UniError(EINVAL).ThrowErr(env, "Invalid owner"); - return nullptr; - } - - auto cbExec = [fd = fd, mode = mode](napi_env env) -> UniError { - int ret = fchmod(fd, mode); - if (ret == -1) { - return UniError(errno); - } else { - return UniError(ERRNO_NOERR); - } - }; - - auto cbComplCallback = [](napi_env env, UniError err) -> NVal { - if (err) { - return { env, err.GetNapiErr(env) }; - } - return { NVal::CreateUndefined(env) }; - }; - - const string procedureName = "FileIOFchmod"; - NVal thisVar(env, funcArg.GetThisVar()); - size_t argc = funcArg.GetArgc(); - if (argc == NARG_CNT::TWO) { - return NAsyncWorkPromise(env, thisVar).Schedule(procedureName, cbExec, cbComplCallback).val_; - } else { - NVal cb(env, funcArg[NARG_POS::THIRD]); - return NAsyncWorkCallback(env, thisVar, cb).Schedule(procedureName, cbExec, cbComplCallback).val_; - } + return NVal::CreateUndefined(env).val_; } } // namespace ModuleFileIO } // namespace DistributedFS diff --git a/interfaces/kits/js/src/mod_fileio/properties/fchown.cpp b/interfaces/kits/js/src/mod_fileio/properties/fchown.cpp index 073269629..a3295b092 100644 --- a/interfaces/kits/js/src/mod_fileio/properties/fchown.cpp +++ b/interfaces/kits/js/src/mod_fileio/properties/fchown.cpp @@ -29,89 +29,12 @@ using namespace std; napi_value Fchown::Sync(napi_env env, napi_callback_info info) { - NFuncArg funcArg(env, info); - if (!funcArg.InitArgs(NARG_CNT::THREE)) { - UniError(EINVAL).ThrowErr(env, "Number of arguments unmatched"); - return nullptr; - } - - auto [resGetFirstArg, fd] = NVal(env, funcArg[NARG_POS::FIRST]).ToInt32(); - if (!resGetFirstArg) { - UniError(EINVAL).ThrowErr(env, "Invalid fd"); - return nullptr; - } - - auto [resGetSecondArg, owner] = NVal(env, funcArg[NARG_POS::SECOND]).ToInt32(); - if (!resGetSecondArg) { - UniError(EINVAL).ThrowErr(env, "Invalid owner"); - return nullptr; - } - - auto [resGetThirdArg, group] = NVal(env, funcArg[NARG_POS::THIRD]).ToInt32(); - if (!resGetThirdArg) { - UniError(EINVAL).ThrowErr(env, "Invalid group"); - return nullptr; - } - - int ret = fchown(fd, owner, group); - if (ret == -1) { - UniError(errno).ThrowErr(env); - return nullptr; - } - return NVal::CreateUndefined(env).val_; } napi_value Fchown::Async(napi_env env, napi_callback_info info) { - NFuncArg funcArg(env, info); - if (!funcArg.InitArgs(NARG_CNT::THREE, NARG_CNT::FOUR)) { - UniError(EINVAL).ThrowErr(env, "Number of arguments unmatched"); - return nullptr; - } - - auto [resGetFirstArg, fd] = NVal(env, funcArg[NARG_POS::FIRST]).ToInt32(); - if (!resGetFirstArg) { - UniError(EINVAL).ThrowErr(env, "Invalid fd"); - return nullptr; - } - - auto [resGetSecondArg, owner] = NVal(env, funcArg[NARG_POS::SECOND]).ToInt32(); - if (!resGetSecondArg) { - UniError(EINVAL).ThrowErr(env, "Invalid owner"); - return nullptr; - } - - auto [resGetThirdArg, group] = NVal(env, funcArg[NARG_POS::THIRD]).ToInt32(); - if (!resGetThirdArg) { - UniError(EINVAL).ThrowErr(env, "Invalid group"); - return nullptr; - } - - auto cbExec = [fd = fd, owner = owner, group = group](napi_env env) -> UniError { - int ret = fchown(fd, owner, group); - if (ret == -1) { - return UniError(errno); - } else { - return UniError(ERRNO_NOERR); - } - }; - - auto cbComplCallback = [](napi_env env, UniError err) -> NVal { - if (err) { - return { env, err.GetNapiErr(env) }; - } - return { NVal::CreateUndefined(env) }; - }; - - const string procedureName = "FileIOFchown"; - NVal thisVar(env, funcArg.GetThisVar()); - if (funcArg.GetArgc() == NARG_CNT::THREE) { - return NAsyncWorkPromise(env, thisVar).Schedule(procedureName, cbExec, cbComplCallback).val_; - } else { - NVal cb(env, funcArg[NARG_POS::FOURTH]); - return NAsyncWorkCallback(env, thisVar, cb).Schedule(procedureName, cbExec, cbComplCallback).val_; - } + return NVal::CreateUndefined(env).val_; } } // namespace ModuleFileIO } // namespace DistributedFS diff --git a/interfaces/kits/js/src/mod_fileio/properties/lchown.cpp b/interfaces/kits/js/src/mod_fileio/properties/lchown.cpp index fe3511ee5..2113bdfc2 100644 --- a/interfaces/kits/js/src/mod_fileio/properties/lchown.cpp +++ b/interfaces/kits/js/src/mod_fileio/properties/lchown.cpp @@ -27,86 +27,14 @@ namespace DistributedFS { namespace ModuleFileIO { using namespace std; -static tuple GetLchownArg(napi_env env, const NFuncArg &funcArg) -{ - auto [resGetFirstArg, path, unused] = NVal(env, funcArg[NARG_POS::FIRST]).ToUTF8String(); - if (!resGetFirstArg) { - UniError(EINVAL).ThrowErr(env, "Invalid path"); - return { false, "", -1, -1 }; - } - - auto [resGetSecondArg, owner] = NVal(env, funcArg[NARG_POS::SECOND]).ToInt32(); - if (!resGetSecondArg) { - UniError(EINVAL).ThrowErr(env, "Invalid owner"); - return { false, "", -1, -1 }; - } - - auto [resGetThirdArg, group] = NVal(env, funcArg[NARG_POS::THIRD]).ToInt32(); - if (!resGetThirdArg) { - UniError(EINVAL).ThrowErr(env, "Invalid group"); - return { false, "", -1, -1 }; - } - - return { true, path.get(), owner, group }; -} - napi_value Lchown::Sync(napi_env env, napi_callback_info info) { - NFuncArg funcArg(env, info); - if (!funcArg.InitArgs(NARG_CNT::THREE)) { - UniError(EINVAL).ThrowErr(env, "Number of arguments unmatched"); - return nullptr; - } - - auto [resGetLchownArg, path, owner, group] = GetLchownArg(env, funcArg); - if (!resGetLchownArg) { - return nullptr; - } - - if (lchown(path.c_str(), owner, group) == -1) { - UniError(errno).ThrowErr(env); - return nullptr; - } - return NVal::CreateUndefined(env).val_; } napi_value Lchown::Async(napi_env env, napi_callback_info info) { - NFuncArg funcArg(env, info); - if (!funcArg.InitArgs(NARG_CNT::THREE, NARG_CNT::FOUR)) { - UniError(EINVAL).ThrowErr(env, "Number of arguments unmatched"); - return nullptr; - } - - auto [resGetLchownArg, path, owner, group] = GetLchownArg(env, funcArg); - if (!resGetLchownArg) { - return nullptr; - } - - auto cbExec = [path = path, owner = owner, group = group](napi_env env) -> UniError { - if (lchown(path.c_str(), owner, group) == -1) { - return UniError(errno); - } else { - return UniError(ERRNO_NOERR); - } - }; - - auto cbCompl = [](napi_env env, UniError err) -> NVal { - if (err) { - return { env, err.GetNapiErr(env) }; - } - return { NVal::CreateUndefined(env) }; - }; - - const string procedureName = "FileIOLchown"; - NVal thisVar(env, funcArg.GetThisVar()); - if (funcArg.GetArgc() == NARG_CNT::THREE) { - return NAsyncWorkPromise(env, thisVar).Schedule(procedureName, cbExec, cbCompl).val_; - } else { - NVal cb(env, funcArg[NARG_POS::FOURTH]); - return NAsyncWorkCallback(env, thisVar, cb).Schedule(procedureName, cbExec, cbCompl).val_; - } + return NVal::CreateUndefined(env).val_; } } // namespace ModuleFileIO } // namespace DistributedFS -- Gitee