From e693bd7d7de8e0b2db764f5db5e1cce215a689ee Mon Sep 17 00:00:00 2001 From: h30051954 Date: Sun, 4 Feb 2024 09:31:48 +0800 Subject: [PATCH] =?UTF-8?q?fixed=209c7d667=20from=20https://gitee.com/heme?= =?UTF-8?q?nghao1996/filemanagement=5Ffile=5Fapi/pulls/534=20find=E5=80=BC?= =?UTF-8?q?=E5=88=A4=E6=96=AD=E6=B7=BB=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: h30051954 --- .../kits/js/src/mod_fs/properties/copy.cpp | 5 ++ .../test/unittest/napi_test/FsCopyTest.js | 49 ++++++++++++++----- 2 files changed, 42 insertions(+), 12 deletions(-) diff --git a/interfaces/kits/js/src/mod_fs/properties/copy.cpp b/interfaces/kits/js/src/mod_fs/properties/copy.cpp index f485c96bf..29461dfcb 100644 --- a/interfaces/kits/js/src/mod_fs/properties/copy.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/copy.cpp @@ -222,6 +222,11 @@ int Copy::CopySubDir(const string &srcPath, const string &destPath, std::shared_ return ENOMEM; } receiveInfo->path = destPath; + if (iter == Copy::jsCbMap_.end() || iter->second == nullptr) { + HILOGE("Failed to find infos, srcPath = %{public}s, destPath = %{public}s", infos->srcPath.c_str(), + infos->destPath.c_str()); + return UNKROWN_ERR; + } iter->second->wds.push_back({ newWd, receiveInfo }); } } diff --git a/interfaces/test/unittest/napi_test/FsCopyTest.js b/interfaces/test/unittest/napi_test/FsCopyTest.js index 0bbe6a57a..4e547753b 100644 --- a/interfaces/test/unittest/napi_test/FsCopyTest.js +++ b/interfaces/test/unittest/napi_test/FsCopyTest.js @@ -899,18 +899,44 @@ describe("FsCopyTest", function () { }); /* - * @tc.name:Fs_Copy_Test025 + * @tc.name:Fs_Copy_Test025 + * @tc.desc:test fs.copy dir to own directory + * @tc.type: FUNC + * @tc.require: #I8UV2F + */ + it("Fs_Copy_Test025", 0, async function (done) { + console.info(TAG, 'Fs_Copy_Test025 start.'); + try { + await fs.copy(srcDirUriLocal, srcDirUriLocal+"/", (err) => { + if (err) { + console.info(TAG, "Fs_Copy_Test025 failed, with error message: " + err.message + ", error code: " + err.code); + expect(true).assertTrue(); + } else { + console.info(TAG, "Fs_Copy_Test025 success. "); + expect().assertFail(); + } + done(); + }) + } catch (err) { + console.error("Fs_Copy_Test025 failed with invalid param: " + err.message + ", error code: " + err.code); + expect().assertFail(); + done(); + } + }); + + /* + * @tc.name:Fs_Copy_Test026 * @tc.desc:test fs.copy, same task * @tc.type: FUNC * @tc.require: #I8UV2F */ - it("Fs_Copy_Test025", 0, async function (done) { - console.info(TAG, 'Fs_Copy_Test025 start.'); + it("Fs_Copy_Test026", 0, async function (done) { + console.info(TAG, 'Fs_Copy_Test026 start.'); try { let flag1 = false; let flag2 = false; let progressListener = (progress) => { - console.info("Fs_Copy_Test025 progressListener in, progressSize: " + progress.processedSize + ", totalSize: " + progress.totalSize + + console.info("Fs_Copy_Test026 progressListener in, progressSize: " + progress.processedSize + ", totalSize: " + progress.totalSize + " progress: " + (progress.processedSize / progress.totalSize * 100).toFixed(2) + "%"); }; let options = { @@ -926,11 +952,11 @@ describe("FsCopyTest", function () { setTimeout(() => { fs.copy(srcFileUriLocal, dstFileUriLocal, options, (err) => { if (err) { - console.info(TAG, "Fs_Copy_Test025_first failed, with error message: " + err.message + ", error code: " + err.code); + console.info(TAG, "Fs_Copy_Test026_first failed, with error message: " + err.message + ", error code: " + err.code); expect().assertFail(); } else { flag1 = true; - console.info(TAG, "Fs_Copy_Test025_first success. "); + console.info(TAG, "Fs_Copy_Test026_first success. "); } }) resolve(); @@ -943,15 +969,15 @@ describe("FsCopyTest", function () { fs.copy(srcFileUriLocal, dstFileUriLocal, options, (err) => { flag2 = true; if (err) { - console.info(TAG, "Fs_Copy_Test025_second failed, with error message: " + err.message + ", error code: " + err.code); + console.info(TAG, "Fs_Copy_Test026_second failed, with error message: " + err.message + ", error code: " + err.code); } else { - console.info(TAG, "Fs_Copy_Test025_second success. ");; + console.info(TAG, "Fs_Copy_Test026_second success. ");; } expect().assertFail(); }) resolve(); } catch (err) { - console.error("Fs_Copy_Test025_second failed with invalid param: " + err.message + ", error code: " + err.code); + console.error("Fs_Copy_Test026_second failed with invalid param: " + err.message + ", error code: " + err.code); } }, 20); }); @@ -964,11 +990,10 @@ describe("FsCopyTest", function () { }); done(); } catch (err) { - console.error("Fs_Copy_Test025 failed with invalid param: " + err.message + ", error code: " + err.code); + console.error("Fs_Copy_Test026 failed with invalid param: " + err.message + ", error code: " + err.code); expect().assertFail(); done(); - } - finally { + } finally { const timerId = setTimeout(() => { fs.rmdirSync(srcDirPathLocal); fs.rmdirSync(dstDirPathLocal); -- Gitee