diff --git a/interfaces/kits/js/src/mod_fs/properties/copy.cpp b/interfaces/kits/js/src/mod_fs/properties/copy.cpp index 1aa3c7465abc76d673a3eda49cfd416b8059ce07..8b691efbb1b88d0b5392e3ba615c5f9073fcc715 100644 --- a/interfaces/kits/js/src/mod_fs/properties/copy.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/copy.cpp @@ -152,12 +152,7 @@ int Copy::CopyFile(const string &src, const string &dest) } auto srcFdg = CreateUniquePtr(srcFd, true); auto destFdg = CreateUniquePtr(destFd, true); - std::unique_ptr sendFileReq = { - new (nothrow) uv_fs_t, CommonFunc::fs_req_cleanup }; - if (sendFileReq == nullptr) { - HILOGE("Failed to request heap memory."); - return ENOMEM; - } + uv_fs_t sendFileReq; int64_t offset = 0; struct stat srcStat{}; if (fstat(srcFdg->GetFD(), &srcStat) < 0) { @@ -167,8 +162,9 @@ int Copy::CopyFile(const string &src, const string &dest) int64_t size = static_cast(srcStat.st_size); int ret = 0; while (size > 0) { - ret = uv_fs_sendfile(nullptr, sendFileReq.get(), destFdg->GetFD(), srcFdg->GetFD(), + ret = uv_fs_sendfile(nullptr, &sendFileReq, destFdg->GetFD(), srcFdg->GetFD(), offset, MAX_SIZE, nullptr); + uv_fs_req_cleanup(&sendFileReq); if (ret < 0) { HILOGE("Failed to sendfile by errno : %{public}d", errno); return errno; diff --git a/interfaces/test/unittest/napi_test/FsCopyTest.js b/interfaces/test/unittest/napi_test/FsCopyTest.js index 3a603315367a145d3862ca660f23e6de62ef7d74..e1095d741ffb8f629bf429a175f8b23d200d4328 100644 --- a/interfaces/test/unittest/napi_test/FsCopyTest.js +++ b/interfaces/test/unittest/napi_test/FsCopyTest.js @@ -276,15 +276,14 @@ describe("FsCopyTest", function () { console.info(TAG, "Fs_Copy_Test008 success. "); expect(true).assertTrue(); } + fs.rmdirSync(srcDirPathLocal); + fs.rmdirSync(dstDirPathLocal); done(); }) } catch (err) { console.error("Fs_Copy_Test008 failed with invalid param: " + err.message + ", error code: " + err.code); expect().assertFail(); done(); - } finally { - fs.rmdirSync(srcDirPathLocal); - fs.rmdirSync(dstDirPathLocal); } }); diff --git a/interfaces/test/unittest/napi_test/config.json b/interfaces/test/unittest/napi_test/config.json index 651407b028fe013724f7730a4c8fa7f8cd7e0be8..bc919eb1d092d00acff47b00b04b22be24bc6078 100644 --- a/interfaces/test/unittest/napi_test/config.json +++ b/interfaces/test/unittest/napi_test/config.json @@ -1,6 +1,6 @@ { "app": { - "bundleName": "com.example.myapplication", + "bundleName": "com.example.fileapitest", "vendor": "example", "version": { "code": 1, @@ -13,7 +13,7 @@ }, "deviceConfig": {}, "module": { - "package": "com.example.myapplication", + "package": "com.example.fileapitest", "name": ".MyApplication", "deviceType": [ "default", @@ -38,7 +38,7 @@ ] } ], - "name": "com.example.myapplication.MainAbility", + "name": "com.example.fileapitest.MainAbility", "icon": "$media:icon", "description": "$string:mainability_description", "label": "MyApplication", diff --git a/interfaces/test/unittest/napi_test/openharmony_sx.p7b b/interfaces/test/unittest/napi_test/openharmony_sx.p7b index 166e7985b623f7bf896e6363761bb1a331c54db7..29cbe04748143a93f2b0cf236e17080d99383b83 100644 Binary files a/interfaces/test/unittest/napi_test/openharmony_sx.p7b and b/interfaces/test/unittest/napi_test/openharmony_sx.p7b differ