From 9539229fa195af97db6c57a6c8d12e31ec0c6c2d Mon Sep 17 00:00:00 2001 From: changleipeng Date: Wed, 15 Feb 2023 16:30:36 +0800 Subject: [PATCH] =?UTF-8?q?copyFile=20=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: changleipeng --- .../js/src/mod_fs/properties/copy_file.cpp | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/interfaces/kits/js/src/mod_fs/properties/copy_file.cpp b/interfaces/kits/js/src/mod_fs/properties/copy_file.cpp index 5a7ea7578..1219d709a 100644 --- a/interfaces/kits/js/src/mod_fs/properties/copy_file.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/copy_file.cpp @@ -107,24 +107,25 @@ static NError SendFileCore(FileInfo& srcFile, FileInfo& destFile) static tuple ParseJsModeAndProm(napi_env env, const NFuncArg& funcArg) { bool promise = false; - bool hasMode = false; + bool succ = false; int mode = 0; - if (funcArg.GetArgc() == NARG_CNT::THREE && NVal(env, funcArg[NARG_POS::THIRD]).TypeIs(napi_number)) { - promise = true; - hasMode = true; - } else if (funcArg.GetArgc() == NARG_CNT::FOUR) { - hasMode = true; + if (funcArg.GetArgc() == NARG_CNT::TWO) { + return { true, mode, true }; } - - bool succ = false; - if (hasMode) { + if (NVal(env, funcArg[NARG_POS::THIRD]).TypeIs(napi_number)) { + if (funcArg.GetArgc() == NARG_CNT::THREE) { + promise = true; + } tie(succ, mode) = NVal(env, funcArg[NARG_POS::THIRD]).ToInt32(); - if (!succ) { - return { false, mode, promise }; + if (succ && !mode) { + return { true, mode, promise }; } } + if (NVal(env, funcArg[NARG_POS::THIRD]).TypeIs(napi_function)) { + return { true, mode, promise }; + } - return { true, mode, promise }; + return { false, mode, promise }; } static tuple ParseJsOperand(napi_env env, NVal pathOrFdFromJsArg) -- Gitee