From 99027fe50470e596e28d138dd63b0a56214e6da6 Mon Sep 17 00:00:00 2001 From: zhuhongtao66 Date: Wed, 15 Feb 2023 16:56:22 +0800 Subject: [PATCH] bugfix for copyFile Signed-off-by: zhuhongtao66 --- .../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 21251406f..a651f0878 100755 --- 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