diff --git a/interfaces/kits/js/src/mod_fs/properties/copy.cpp b/interfaces/kits/js/src/mod_fs/properties/copy.cpp index 1aa3c7465abc76d673a3eda49cfd416b8059ce07..119c9045ae855e17f2c550e48051bb17bcd92a58 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) { @@ -171,6 +166,7 @@ int Copy::CopyFile(const string &src, const string &dest) offset, MAX_SIZE, nullptr); if (ret < 0) { HILOGE("Failed to sendfile by errno : %{public}d", errno); + uv_fs_req_cleanup(&sendFileReq); return errno; } offset += static_cast(ret); @@ -179,6 +175,7 @@ int Copy::CopyFile(const string &src, const string &dest) break; } } + uv_fs_req_cleanup(&sendFileReq); if (size != 0) { HILOGE("The execution of the sendfile task was terminated, remaining file size %{public}" PRIu64, size); return E_IO; 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..44ea389131964466987601324eaf0f52837cf462 100644 Binary files a/interfaces/test/unittest/napi_test/openharmony_sx.p7b and b/interfaces/test/unittest/napi_test/openharmony_sx.p7b differ