From ef9cb9aa6da75ff712290b6dddf4dfbb7630cb84 Mon Sep 17 00:00:00 2001 From: liyuke Date: Tue, 5 Aug 2025 20:41:59 +0800 Subject: [PATCH] =?UTF-8?q?dup=E5=86=85=E5=AD=98=E6=B3=84=E6=BC=8F?= =?UTF-8?q?=E5=91=8A=E8=AD=A6=E5=92=8Ccopy=20TDD=E7=94=A8=E4=BE=8B?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: liyuke Change-Id: I7aa38334926e9294403a7f8921faebce3a8cdf79 --- interfaces/kits/js/src/mod_fs/properties/dup_core.cpp | 2 ++ .../test/unittest/js/mod_fs/properties/copy_core_test.cpp | 6 ++---- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/interfaces/kits/js/src/mod_fs/properties/dup_core.cpp b/interfaces/kits/js/src/mod_fs/properties/dup_core.cpp index ddb5d4eb1..b70fac876 100644 --- a/interfaces/kits/js/src/mod_fs/properties/dup_core.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/dup_core.cpp @@ -53,12 +53,14 @@ FsResult DupCore::DoDup(const int32_t &fd) new (std::nothrow) uv_fs_t, FsUtils::FsReqCleanup }; if (!readLinkReq) { HILOGE("Failed to request heap memory."); + close(dstFd); return FsResult::Error(ENOMEM); } string path = "/proc/self/fd/" + to_string(dstFd); int ret = uv_fs_readlink(nullptr, readLinkReq.get(), path.c_str(), nullptr); if (ret < 0) { HILOGE("Failed to readlink fd, ret: %{public}d", ret); + close(dstFd); return FsResult::Error(ret); } return FileInstantiator::InstantiateFile(dstFd, string(static_cast(readLinkReq->ptr)), false); diff --git a/interfaces/test/unittest/js/mod_fs/properties/copy_core_test.cpp b/interfaces/test/unittest/js/mod_fs/properties/copy_core_test.cpp index febb6cf12..bb2df2443 100644 --- a/interfaces/test/unittest/js/mod_fs/properties/copy_core_test.cpp +++ b/interfaces/test/unittest/js/mod_fs/properties/copy_core_test.cpp @@ -789,9 +789,7 @@ HWTEST_F(CopyCoreTest, CopyCoreTest_DoCopy_002, testing::ext::TestSize.Level1) optional options; auto res = CopyCore::DoCopy(src, dest, options); - EXPECT_TRUE(res.IsSuccess()); - int ret = remove(destFile.c_str()); - EXPECT_TRUE(ret == 0); + EXPECT_FALSE(res.IsSuccess()); GTEST_LOG_(INFO) << "CopyCoreTest-end CopyCoreTest_DoCopy_002"; } @@ -978,7 +976,7 @@ HWTEST_F(CopyCoreTest, CopyCoreTest_ExecCopy_001, testing::ext::TestSize.Level1) infos->destPath = "/data/test/dest"; auto res = CopyCore::ExecCopy(infos); - EXPECT_EQ(res, ERRNO_NOERR); + EXPECT_EQ(res, EINVAL); GTEST_LOG_(INFO) << "CopyCoreTest-end CopyCoreTest_ExecCopy_001"; } -- Gitee