From dd8fabd0f237760c0ef581b7abf52099bf4b8426 Mon Sep 17 00:00:00 2001 From: zhongning5 Date: Tue, 25 Mar 2025 17:19:39 +0800 Subject: [PATCH 01/11] =?UTF-8?q?=E6=B7=BB=E5=8A=A0platformsdk?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhongning5 --- interfaces/kits/rust/BUILD.gn | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/interfaces/kits/rust/BUILD.gn b/interfaces/kits/rust/BUILD.gn index a4cc7d698..965a4ec21 100644 --- a/interfaces/kits/rust/BUILD.gn +++ b/interfaces/kits/rust/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2023 Huawei Device Co., Ltd. +# Copyright (c) 2023-2025 Huawei Device Co., Ltd. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -26,5 +26,6 @@ ohos_rust_shared_ffi("rust_file") { rustflags = [ "-Zstack-protector=all" ] deps = [ "//third_party/rust/crates/libc:lib" ] external_deps = [ "hilog:hilog_rust" ] + innerapi_tags = [ "platformsdk" ] public_configs = [ ":public_config" ] } -- Gitee From 4dcedb85c3ce94d6a1a068762e9a56e66efa2791 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9C=E9=99=B6=E9=87=91=E6=B2=9B=E2=80=9D?= Date: Mon, 31 Mar 2025 21:04:54 +0800 Subject: [PATCH 02/11] =?UTF-8?q?tdd=E6=B5=8B=E8=AF=95=E7=94=A8=E4=BE=8B?= =?UTF-8?q?=E6=95=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: “陶金沛” --- .../test/unittest/class_file/rust_test.cpp | 68 +++++++++---------- 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/interfaces/test/unittest/class_file/rust_test.cpp b/interfaces/test/unittest/class_file/rust_test.cpp index 7b3800a8b..6c60bd3b1 100644 --- a/interfaces/test/unittest/class_file/rust_test.cpp +++ b/interfaces/test/unittest/class_file/rust_test.cpp @@ -95,10 +95,10 @@ HWTEST_F(RustTest, RustTest_ReaderIterator_0003, testing::ext::TestSize.Level1) * @tc.desc: Test function of NextLine() interface for SUCCESS. * @tc.size: MEDIUM * @tc.type: FUNC -* @tc.level Level 1 +* @tc.level Level 0 * @tc.require: AR000IGDNF */ -HWTEST_F(RustTest, RustTest_NextLine_0001, testing::ext::TestSize.Level1) +HWTEST_F(RustTest, RustTest_NextLine_0001, testing::ext::TestSize.Level0) { GTEST_LOG_(INFO) << "RustTest-begin RustTest_NextLine_0001"; @@ -119,10 +119,10 @@ HWTEST_F(RustTest, RustTest_NextLine_0001, testing::ext::TestSize.Level1) * @tc.desc: Test function of NextLine() interface for SUCCESS. * @tc.size: MEDIUM * @tc.type: FUNC -* @tc.level Level 1 +* @tc.level Level 0 * @tc.require: AR000IGDNF */ -HWTEST_F(RustTest, RustTest_NextLine_0002, testing::ext::TestSize.Level1) +HWTEST_F(RustTest, RustTest_NextLine_0002, testing::ext::TestSize.Level0) { GTEST_LOG_(INFO) << "RustTest-begin RustTest_NextLine_0002"; @@ -159,10 +159,10 @@ HWTEST_F(RustTest, RustTest_NextLine_0003, testing::ext::TestSize.Level1) * @tc.desc: Test function of Lseek() interface for SUCCESS. * @tc.size: MEDIUM * @tc.type: FUNC -* @tc.level Level 1 +* @tc.level Level 0 * @tc.require: AR000IGCS3 */ -HWTEST_F(RustTest, RustTest_Lseek_0001, testing::ext::TestSize.Level1) +HWTEST_F(RustTest, RustTest_Lseek_0001, testing::ext::TestSize.Level0) { GTEST_LOG_(INFO) << "RustTest-begin RustTest_Lseek_0001"; @@ -182,10 +182,10 @@ HWTEST_F(RustTest, RustTest_Lseek_0001, testing::ext::TestSize.Level1) * @tc.desc: Test function of Lseek() interface for SUCCESS. * @tc.size: MEDIUM * @tc.type: FUNC -* @tc.level Level 1 +* @tc.level Level 0 * @tc.require: AR000IGCS3 */ -HWTEST_F(RustTest, RustTest_Lseek_0002, testing::ext::TestSize.Level1) +HWTEST_F(RustTest, RustTest_Lseek_0002, testing::ext::TestSize.Level0) { GTEST_LOG_(INFO) << "RustTest-begin RustTest_Lseek_0002"; @@ -208,10 +208,10 @@ HWTEST_F(RustTest, RustTest_Lseek_0002, testing::ext::TestSize.Level1) * @tc.desc: Test function of Lseek() interface for SUCCESS. * @tc.size: MEDIUM * @tc.type: FUNC -* @tc.level Level 1 +* @tc.level Level 0 * @tc.require: AR000IGCS3 */ -HWTEST_F(RustTest, RustTest_Lseek_0003, testing::ext::TestSize.Level1) +HWTEST_F(RustTest, RustTest_Lseek_0003, testing::ext::TestSize.Level0) { GTEST_LOG_(INFO) << "RustTest-begin RustTest_Lseek_0003"; @@ -254,10 +254,10 @@ HWTEST_F(RustTest, RustTest_Lseek_0004, testing::ext::TestSize.Level1) * @tc.desc: Test function of Lseek() interface for SUCCESS. * @tc.size: MEDIUM * @tc.type: FUNC -* @tc.level Level 1 +* @tc.level Level 0 * @tc.require: AR000IGCS3 */ -HWTEST_F(RustTest, RustTest_Lseek_0005, testing::ext::TestSize.Level1) +HWTEST_F(RustTest, RustTest_Lseek_0005, testing::ext::TestSize.Level0) { GTEST_LOG_(INFO) << "RustTest-begin RustTest_Lseek_0005"; @@ -280,10 +280,10 @@ HWTEST_F(RustTest, RustTest_Lseek_0005, testing::ext::TestSize.Level1) * @tc.desc: Test function of Lseek() interface for SUCCESS. * @tc.size: MEDIUM * @tc.type: FUNC -* @tc.level Level 1 +* @tc.level Level 0 * @tc.require: AR000IGCS3 */ -HWTEST_F(RustTest, RustTest_Lseek_0006, testing::ext::TestSize.Level1) +HWTEST_F(RustTest, RustTest_Lseek_0006, testing::ext::TestSize.Level0) { GTEST_LOG_(INFO) << "RustTest-begin RustTest_Lseek_0006"; @@ -303,10 +303,10 @@ HWTEST_F(RustTest, RustTest_Lseek_0006, testing::ext::TestSize.Level1) * @tc.desc: Test function of Lseek() interface for SUCCESS. * @tc.size: MEDIUM * @tc.type: FUNC -* @tc.level Level 1 +* @tc.level Level 0 * @tc.require: AR000IGCS3 */ -HWTEST_F(RustTest, RustTest_Lseek_0007, testing::ext::TestSize.Level1) +HWTEST_F(RustTest, RustTest_Lseek_0007, testing::ext::TestSize.Level0) { GTEST_LOG_(INFO) << "RustTest-begin RustTest_Lseek_0007"; @@ -322,10 +322,10 @@ HWTEST_F(RustTest, RustTest_Lseek_0007, testing::ext::TestSize.Level1) * @tc.desc: Test function of Mkdirs() interface for SUCCESS. * @tc.size: MEDIUM * @tc.type: FUNC -* @tc.level Level 1 +* @tc.level Level 0 * @tc.require: AR000IGDNJ */ -HWTEST_F(RustTest, RustTest_Mkdirs_0001, testing::ext::TestSize.Level1) +HWTEST_F(RustTest, RustTest_Mkdirs_0001, testing::ext::TestSize.Level0) { GTEST_LOG_(INFO) << "RustTest-begin RustTest_Mkdirs_0001"; @@ -347,10 +347,10 @@ HWTEST_F(RustTest, RustTest_Mkdirs_0001, testing::ext::TestSize.Level1) * @tc.desc: Test function of Mkdirs() interface for SUCCESS. * @tc.size: MEDIUM * @tc.type: FUNC -* @tc.level Level 1 +* @tc.level Level 0 * @tc.require: AR000IGDNJ */ -HWTEST_F(RustTest, RustTest_Mkdirs_0002, testing::ext::TestSize.Level1) +HWTEST_F(RustTest, RustTest_Mkdirs_0002, testing::ext::TestSize.Level0) { GTEST_LOG_(INFO) << "RustTest-begin RustTest_Mkdirs_0002"; @@ -372,10 +372,10 @@ HWTEST_F(RustTest, RustTest_Mkdirs_0002, testing::ext::TestSize.Level1) * @tc.desc: Test function of Mkdirs() interface for SUCCESS. * @tc.size: MEDIUM * @tc.type: FUNC -* @tc.level Level 1 +* @tc.level Level 0 * @tc.require: AR000IGDNJ */ -HWTEST_F(RustTest, RustTest_Mkdirs_0003, testing::ext::TestSize.Level1) +HWTEST_F(RustTest, RustTest_Mkdirs_0003, testing::ext::TestSize.Level0) { GTEST_LOG_(INFO) << "RustTest-begin RustTest_Mkdirs_0003"; @@ -393,10 +393,10 @@ HWTEST_F(RustTest, RustTest_Mkdirs_0003, testing::ext::TestSize.Level1) * @tc.desc: Test function of Mkdirs() interface for SUCCESS. * @tc.size: MEDIUM * @tc.type: FUNC -* @tc.level Level 1 +* @tc.level Level 0 * @tc.require: AR000IGDNJ */ -HWTEST_F(RustTest, RustTest_Mkdirs_0004, testing::ext::TestSize.Level1) +HWTEST_F(RustTest, RustTest_Mkdirs_0004, testing::ext::TestSize.Level0) { GTEST_LOG_(INFO) << "RustTest-begin RustTest_Mkdirs_0004"; @@ -412,10 +412,10 @@ HWTEST_F(RustTest, RustTest_Mkdirs_0004, testing::ext::TestSize.Level1) * @tc.desc: Test function of Mkdirs() interface for SUCCESS. * @tc.size: MEDIUM * @tc.type: FUNC -* @tc.level Level 1 +* @tc.level Level 0 * @tc.require: AR000IGDNJ */ -HWTEST_F(RustTest, RustTest_Mkdirs_0005, testing::ext::TestSize.Level1) +HWTEST_F(RustTest, RustTest_Mkdirs_0005, testing::ext::TestSize.Level0) { GTEST_LOG_(INFO) << "RustTest-begin RustTest_Mkdirs_0005"; @@ -432,10 +432,10 @@ HWTEST_F(RustTest, RustTest_Mkdirs_0005, testing::ext::TestSize.Level1) * @tc.desc: Test function of Mkdirs() interface for SUCCESS. * @tc.size: MEDIUM * @tc.type: FUNC -* @tc.level Level 1 +* @tc.level Level 0 * @tc.require: AR000IGDNJ */ -HWTEST_F(RustTest, RustTest_Mkdirs_0006, testing::ext::TestSize.Level1) +HWTEST_F(RustTest, RustTest_Mkdirs_0006, testing::ext::TestSize.Level0) { GTEST_LOG_(INFO) << "RustTest-begin RustTest_Mkdirs_0006"; @@ -452,10 +452,10 @@ HWTEST_F(RustTest, RustTest_Mkdirs_0006, testing::ext::TestSize.Level1) * @tc.desc: Test function of Mkdirs() interface for SUCCESS. * @tc.size: MEDIUM * @tc.type: FUNC -* @tc.level Level 1 +* @tc.level Level 0 * @tc.require: AR000IGDNJ */ -HWTEST_F(RustTest, RustTest_Mkdirs_0007, testing::ext::TestSize.Level1) +HWTEST_F(RustTest, RustTest_Mkdirs_0007, testing::ext::TestSize.Level0) { GTEST_LOG_(INFO) << "RustTest-begin RustTest_Mkdirs_0007"; @@ -472,10 +472,10 @@ HWTEST_F(RustTest, RustTest_Mkdirs_0007, testing::ext::TestSize.Level1) * @tc.desc: Test function of Mkdirs() interface for SUCCESS. * @tc.size: MEDIUM * @tc.type: FUNC -* @tc.level Level 1 +* @tc.level Level 0 * @tc.require: AR000IGDNJ */ -HWTEST_F(RustTest, RustTest_Mkdirs_0008, testing::ext::TestSize.Level1) +HWTEST_F(RustTest, RustTest_Mkdirs_0008, testing::ext::TestSize.Level0) { GTEST_LOG_(INFO) << "RustTest-begin RustTest_Mkdirs_0008"; @@ -492,10 +492,10 @@ HWTEST_F(RustTest, RustTest_Mkdirs_0008, testing::ext::TestSize.Level1) * @tc.desc: Test function of GetParent() interface for SUCCESS. * @tc.size: MEDIUM * @tc.type: FUNC -* @tc.level Level 1 +* @tc.level Level 0 * @tc.require: AR000IGDNL */ -HWTEST_F(RustTest, RustTest_GetParent_0001, testing::ext::TestSize.Level1) +HWTEST_F(RustTest, RustTest_GetParent_0001, testing::ext::TestSize.Level0) { GTEST_LOG_(INFO) << "RustTest-begin RustTest_GetParent_0001"; -- Gitee From 1dd0d213f40b9082e741fee31e76ec9b22a5bfce Mon Sep 17 00:00:00 2001 From: repo sync -c Date: Thu, 10 Apr 2025 15:48:31 +0800 Subject: [PATCH 03/11] =?UTF-8?q?=E4=B8=AD=E9=80=94=E5=BC=82=E5=B8=B8?= =?UTF-8?q?=E9=80=80=E5=87=BA=E5=A2=9E=E5=8A=A0scope=E5=85=B3=E9=97=AD?= =?UTF-8?q?=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 周鑫 Change-Id: Iea71514be018757f3c0c6dfc1222bfbb3ac21553 --- utils/filemgmt_libn/src/n_async/n_async_work_callback.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/utils/filemgmt_libn/src/n_async/n_async_work_callback.cpp b/utils/filemgmt_libn/src/n_async/n_async_work_callback.cpp index 9cad32c85..ff421fc03 100644 --- a/utils/filemgmt_libn/src/n_async/n_async_work_callback.cpp +++ b/utils/filemgmt_libn/src/n_async/n_async_work_callback.cpp @@ -120,6 +120,7 @@ static void CallbackComplete(napi_env env, napi_status status, void *data) napi_value callback = ctx->cb_.Deref(env).val_; if (!bool(ctx->cb_)) { HILOGE("failed to get ref."); + napi_close_handle_scope(env, scope); return; } -- Gitee From 88e347e81679f6daee49d7e7f31a695a08cc8b78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=A8=E9=91=AB?= Date: Thu, 10 Apr 2025 09:27:08 +0000 Subject: [PATCH 04/11] update utils/filemgmt_libn/src/n_async/n_async_work_callback.cpp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 周鑫 --- utils/filemgmt_libn/src/n_async/n_async_work_callback.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/filemgmt_libn/src/n_async/n_async_work_callback.cpp b/utils/filemgmt_libn/src/n_async/n_async_work_callback.cpp index ff421fc03..4f2e88a80 100644 --- a/utils/filemgmt_libn/src/n_async/n_async_work_callback.cpp +++ b/utils/filemgmt_libn/src/n_async/n_async_work_callback.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * Copyright (c) 2022-2025 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at -- Gitee From 19f00b93a29d54f77ba9eecab58f2c1b17a69e45 Mon Sep 17 00:00:00 2001 From: y30045862 Date: Sat, 12 Apr 2025 23:52:41 +0800 Subject: [PATCH 05/11] fix randomaccess write async Signed-off-by: yangjingbo10 Change-Id: I8b01907ff6b349514d4cd01448b0d43711170448 --- .../randomaccessfile_n_exporter.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/interfaces/kits/js/src/mod_fs/class_randomaccessfile/randomaccessfile_n_exporter.cpp b/interfaces/kits/js/src/mod_fs/class_randomaccessfile/randomaccessfile_n_exporter.cpp index 3a620f1fc..bbe140fbb 100644 --- a/interfaces/kits/js/src/mod_fs/class_randomaccessfile/randomaccessfile_n_exporter.cpp +++ b/interfaces/kits/js/src/mod_fs/class_randomaccessfile/randomaccessfile_n_exporter.cpp @@ -275,8 +275,10 @@ napi_value RandomAccessFileNExporter::WriteSync(napi_env env, napi_callback_info struct AsyncIORafWriteArg { NRef rafRefWriteArrayBuf; + std::unique_ptr guardWriteStr_ = nullptr; int actLen = 0; explicit AsyncIORafWriteArg(NVal refWriteArrayBuf) : rafRefWriteArrayBuf(refWriteArrayBuf) {} + explicit AsyncIORafWriteArg(std::unique_ptr &&guardWriteStr) : guardWriteStr_(move(guardWriteStr)) {} ~AsyncIORafWriteArg() = default; }; @@ -286,7 +288,8 @@ static napi_value WriteExec(napi_env env, NFuncArg &funcArg, RandomAccessFileEnt void *buf = nullptr; size_t len = 0; int64_t offset = 0; - tie(succ, ignore, buf, len, offset) = + unique_ptr bufGuard = nullptr; + tie(succ, bufGuard, buf, len, offset) = CommonFunc::GetWriteArg(env, funcArg[NARG_POS::FIRST], funcArg[NARG_POS::SECOND]); if (!succ) { HILOGE("Invalid buffer/options"); @@ -294,7 +297,7 @@ static napi_value WriteExec(napi_env env, NFuncArg &funcArg, RandomAccessFileEnt return nullptr; } - auto arg = CreateSharedPtr(NVal(env, funcArg[NARG_POS::FIRST])); + auto arg = CreateSharedPtr(move(bufGuard)); if (arg == nullptr) { HILOGE("Failed to request heap memory."); NError(ENOMEM).ThrowErr(env); @@ -319,9 +322,8 @@ static napi_value WriteExec(napi_env env, NFuncArg &funcArg, RandomAccessFileEnt auto cbCompl = [arg](napi_env env, NError err) -> NVal { if (err) { return { env, err.GetNapiErr(env) }; - } else { - return { NVal::CreateInt64(env, arg->actLen) }; } + return { NVal::CreateInt64(env, arg->actLen) }; }; NVal thisVar(env, funcArg.GetThisVar()); -- Gitee From 1123c589d22f465a484f1cf04e10f399711166f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=AD=8F=E5=AD=90=E6=81=92?= Date: Mon, 14 Apr 2025 11:08:34 +0800 Subject: [PATCH 06/11] bugfix MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 魏子恒 --- bundle.json | 4 +++- file_api.gni | 4 ++++ interfaces/kits/js/BUILD.gn | 4 ++++ .../kits/js/src/mod_file/class_file/file_n_exporter.cpp | 4 ++++ interfaces/kits/js/src/mod_file/class_file/file_n_exporter.h | 4 ++++ 5 files changed, 19 insertions(+), 1 deletion(-) diff --git a/bundle.json b/bundle.json index 78b145b37..ded14f6a7 100644 --- a/bundle.json +++ b/bundle.json @@ -19,7 +19,9 @@ "SystemCapability.FileManagement.File.DistributedFile", "SystemCapability.FileManagement.File.Environment.FolderObtain" ], - "features": [], + "features": [ + "file_api_read_optimize" + ], "adapted_system_type": [ "mini","small","standard" ], "rom": "4096KB", "ram": "4096KB", diff --git a/file_api.gni b/file_api.gni index 7fc94ace6..16a290623 100644 --- a/file_api.gni +++ b/file_api.gni @@ -23,3 +23,7 @@ utils_path = "${file_api_path}/utils" use_mac = "${current_os}_${current_cpu}" == "mac_x64" || "${current_os}_${current_cpu}" == "mac_arm64" use_mingw_win = "${current_os}_${current_cpu}" == "mingw_x86_64" + +declare_args() { + file_api_read_optimize = false +} diff --git a/interfaces/kits/js/BUILD.gn b/interfaces/kits/js/BUILD.gn index e06a5cece..9fc445f9a 100644 --- a/interfaces/kits/js/BUILD.gn +++ b/interfaces/kits/js/BUILD.gn @@ -377,6 +377,10 @@ ohos_shared_library("file") { "hilog:libhilog", "napi:ace_napi", ] + + if (file_api_read_optimize) { + defines = [ "WEARABLE_PRODUCT" ] + } } ohos_shared_library("statfs") { diff --git a/interfaces/kits/js/src/mod_file/class_file/file_n_exporter.cpp b/interfaces/kits/js/src/mod_file/class_file/file_n_exporter.cpp index 972c56b50..01f591e74 100644 --- a/interfaces/kits/js/src/mod_file/class_file/file_n_exporter.cpp +++ b/interfaces/kits/js/src/mod_file/class_file/file_n_exporter.cpp @@ -905,7 +905,11 @@ void ReadArrayBufferExec(napi_env env, void *data) if (read(fdg.GetFD(), buffer.get(), len) != FAILED) { asyncCallbackInfo->result = SUCCESS; asyncCallbackInfo->len = len; +#ifdef WEARABLE_PRODUCT + asyncCallbackInfo->contents = std::move(buffer); +#else asyncCallbackInfo->contents = std::string(buffer.get()); +#endif } } } else if (statPath == ENOENT) { diff --git a/interfaces/kits/js/src/mod_file/class_file/file_n_exporter.h b/interfaces/kits/js/src/mod_file/class_file/file_n_exporter.h index b9760b8a5..f39a8069e 100644 --- a/interfaces/kits/js/src/mod_file/class_file/file_n_exporter.h +++ b/interfaces/kits/js/src/mod_file/class_file/file_n_exporter.h @@ -172,7 +172,11 @@ struct AsyncReadBufferCallbackInfo { int result = DEFAULT_RESULT; int errorType = -1; int32_t len = 0; +#ifdef WEARABLE_PRODUCT + std::unique_ptr contents = nullptr; +#else std::string contents = ""; +#endif }; class FileNExporter final : public NExporter { -- Gitee From 376b7f2111e682fd26766177d6e06656c79c1202 Mon Sep 17 00:00:00 2001 From: y30045862 Date: Thu, 24 Apr 2025 18:45:19 +0800 Subject: [PATCH 07/11] Fix ambiguous internal error Signed-off-by: yangjingbo10 Change-Id: I4fc65b4e830aeb39063ad09c3d63e48a3c25781c --- .../atomicfile_n_exporter.cpp | 42 +++++++++---------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/interfaces/kits/js/src/mod_fs/class_atomicfile/atomicfile_n_exporter.cpp b/interfaces/kits/js/src/mod_fs/class_atomicfile/atomicfile_n_exporter.cpp index 456a2f8f0..6958df62b 100644 --- a/interfaces/kits/js/src/mod_fs/class_atomicfile/atomicfile_n_exporter.cpp +++ b/interfaces/kits/js/src/mod_fs/class_atomicfile/atomicfile_n_exporter.cpp @@ -73,7 +73,7 @@ static napi_value CreateStream(napi_env env, napi_callback_info info, const std: napi_status status = napi_load_module(env, moduleName, &streamrw); if (status != napi_ok) { HILOGE("Failed to load module"); - NError(UNKROWN_ERR).ThrowErr(env, "Internal error"); + NError(UNKROWN_ERR).ThrowErr(env, "Failed to load module"); return nullptr; } @@ -81,7 +81,7 @@ static napi_value CreateStream(napi_env env, napi_callback_info info, const std: status = napi_get_named_property(env, streamrw, streamName.c_str(), &constructor); if (status != napi_ok) { HILOGE("Failed to get named property"); - NError(UNKROWN_ERR).ThrowErr(env, "Internal error"); + NError(UNKROWN_ERR).ThrowErr(env, "Failed to get named property"); return nullptr; } @@ -92,7 +92,7 @@ static napi_value CreateStream(napi_env env, napi_callback_info info, const std: status = napi_new_instance(env, constructor, argc, argv, &streamObj); if (status != napi_ok) { HILOGE("Failed to create napi new instance"); - NError(UNKROWN_ERR).ThrowErr(env, "Internal error"); + NError(UNKROWN_ERR).ThrowErr(env, "Failed to create napi new instance"); return nullptr; } @@ -135,7 +135,7 @@ static NVal InstantiateFile(napi_env env, int fd, std::string path, bool isUri) if (!objFile) { close(fd); HILOGE("Failed to instantiate class"); - NError(UNKROWN_ERR).ThrowErr(env, "Internal error"); + NError(UNKROWN_ERR).ThrowErr(env, "Failed to instantiate class"); return NVal(); } @@ -143,7 +143,7 @@ static NVal InstantiateFile(napi_env env, int fd, std::string path, bool isUri) if (fileEntity == nullptr) { close(fd); HILOGE("Failed to get fileEntity"); - NError(UNKROWN_ERR).ThrowErr(env, "Internal error"); + NError(UNKROWN_ERR).ThrowErr(env, "Failed to get fileEntity"); return NVal(); } auto fdg = CreateUniquePtr(fd, false); @@ -186,7 +186,7 @@ napi_value AtomicFileNExporter::GetBaseFile(napi_env env, napi_callback_info inf auto [rafEntity, errcode] = GetAtomicFileEntity(env, info); if (errcode != 0) { if (errcode == UNKROWN_ERR) { - NError(errcode).ThrowErr(env, "Internal error"); + NError(errcode).ThrowErr(env, "Failed to get atomicFile"); } else { NError(errcode).ThrowErr(env); } @@ -195,7 +195,7 @@ napi_value AtomicFileNExporter::GetBaseFile(napi_env env, napi_callback_info inf if (rafEntity->baseFileName.size() >= PATH_MAX) { HILOGE("Base file name is too long"); - NError(UNKROWN_ERR).ThrowErr(env, "Internal error"); + NError(UNKROWN_ERR).ThrowErr(env, "Base file name is too long"); return nullptr; } @@ -221,7 +221,7 @@ napi_value AtomicFileNExporter::OpenRead(napi_env env, napi_callback_info info) auto [rafEntity, errcode] = GetAtomicFileEntity(env, info); if (errcode != 0) { if (errcode == UNKROWN_ERR) { - NError(errcode).ThrowErr(env, "Internal error"); + NError(errcode).ThrowErr(env, "Failed to get atomicFile"); } else { NError(errcode).ThrowErr(env); } @@ -273,7 +273,7 @@ napi_value AtomicFileNExporter::ReadFully(napi_env env, napi_callback_info info) auto [rafEntity, errcode] = GetAtomicFileEntity(env, info); if (errcode != 0) { if (errcode == UNKROWN_ERR) { - NError(errcode).ThrowErr(env, "Internal error"); + NError(errcode).ThrowErr(env, "Failed to get atomicFile"); } else { NError(errcode).ThrowErr(env); } @@ -299,7 +299,7 @@ napi_value AtomicFileNExporter::ReadFully(napi_env env, napi_callback_info info) auto [bufferData, readErrcode] = ReadFileToBuffer(env, file.get()); if (readErrcode != 0) { if (readErrcode == UNKROWN_ERR) { - NError(readErrcode).ThrowErr(env, "Internal error"); + NError(readErrcode).ThrowErr(env, "Failed to read file to buffer"); } else { NError(readErrcode).ThrowErr(env); } @@ -311,14 +311,14 @@ napi_value AtomicFileNExporter::ReadFully(napi_env env, napi_callback_info info) napi_status status = napi_create_external_arraybuffer( env, bufferData->buffer, bufferData->length, FinalizeCallback, bufferData.release(), &externalBuffer); if (status != napi_ok) { - NError(UNKROWN_ERR).ThrowErr(env, "Internal error"); + NError(UNKROWN_ERR).ThrowErr(env, "Failed to create external arraybuffer"); return nullptr; } napi_value outputArray = nullptr; status = napi_create_typedarray(env, napi_int8_array, length, externalBuffer, 0, &outputArray); if (status != napi_ok) { - NError(UNKROWN_ERR).ThrowErr(env, "Internal error"); + NError(UNKROWN_ERR).ThrowErr(env, "Failed to create typedarray"); return nullptr; } @@ -330,7 +330,7 @@ napi_value AtomicFileNExporter::StartWrite(napi_env env, napi_callback_info info auto [rafEntity, errcode] = GetAtomicFileEntity(env, info); if (errcode != 0) { if (errcode == UNKROWN_ERR) { - NError(errcode).ThrowErr(env, "Internal error"); + NError(errcode).ThrowErr(env, "Failed to get atomicFile"); } else { NError(errcode).ThrowErr(env); } @@ -360,7 +360,7 @@ napi_value AtomicFileNExporter::StartWrite(napi_env env, napi_callback_info info napi_status status = napi_create_reference(env, writeStream, 1, &rafEntity->writeStreamObj); if (status != napi_ok) { HILOGE("Failed to create reference"); - NError(UNKROWN_ERR).ThrowErr(env, "Internal error"); + NError(UNKROWN_ERR).ThrowErr(env, "Failed to create reference"); return nullptr; } return writeStream; @@ -371,7 +371,7 @@ napi_value AtomicFileNExporter::FinishWrite(napi_env env, napi_callback_info inf auto [rafEntity, errcode] = GetAtomicFileEntity(env, info); if (errcode != 0) { if (errcode == UNKROWN_ERR) { - NError(errcode).ThrowErr(env, "Internal error"); + NError(errcode).ThrowErr(env, "Failed to get atomicFile"); } else { NError(errcode).ThrowErr(env); } @@ -382,7 +382,7 @@ napi_value AtomicFileNExporter::FinishWrite(napi_env env, napi_callback_info inf napi_status status = napi_get_reference_value(env, rafEntity->writeStreamObj, &writeStream); if (status != napi_ok) { HILOGE("Failed to get reference value"); - NError(UNKROWN_ERR).ThrowErr(env, "Internal error"); + NError(UNKROWN_ERR).ThrowErr(env, "Failed to get reference value"); return nullptr; } @@ -394,7 +394,7 @@ napi_value AtomicFileNExporter::FinishWrite(napi_env env, napi_callback_info inf status = napi_delete_reference(env, rafEntity->writeStreamObj); if (status != napi_ok) { HILOGE("Failed to delete reference"); - NError(UNKROWN_ERR).ThrowErr(env, "Internal error"); + NError(UNKROWN_ERR).ThrowErr(env, "Failed to delete reference"); return nullptr; } return nullptr; @@ -405,7 +405,7 @@ napi_value AtomicFileNExporter::FailWrite(napi_env env, napi_callback_info info) auto [rafEntity, errcode] = GetAtomicFileEntity(env, info); if (errcode != 0) { if (errcode == UNKROWN_ERR) { - NError(errcode).ThrowErr(env, "Internal error"); + NError(errcode).ThrowErr(env, "Failed to get atomicFile"); } else { NError(errcode).ThrowErr(env); } @@ -416,7 +416,7 @@ napi_value AtomicFileNExporter::FailWrite(napi_env env, napi_callback_info info) napi_status status = napi_get_reference_value(env, rafEntity->writeStreamObj, &writeStream); if (status != napi_ok) { HILOGE("Failed to get reference value"); - NError(UNKROWN_ERR).ThrowErr(env, "Internal error"); + NError(UNKROWN_ERR).ThrowErr(env, "Failed to get reference value"); return nullptr; } @@ -430,7 +430,7 @@ napi_value AtomicFileNExporter::FailWrite(napi_env env, napi_callback_info info) status = napi_delete_reference(env, rafEntity->writeStreamObj); if (status != napi_ok) { HILOGE("Failed to delete reference"); - NError(UNKROWN_ERR).ThrowErr(env, "Internal error"); + NError(UNKROWN_ERR).ThrowErr(env, "Failed to delete reference"); } return nullptr; } @@ -440,7 +440,7 @@ napi_value AtomicFileNExporter::Delete(napi_env env, napi_callback_info info) auto [rafEntity, errcode] = GetAtomicFileEntity(env, info); if (errcode != 0) { if (errcode == UNKROWN_ERR) { - NError(errcode).ThrowErr(env, "Internal error"); + NError(errcode).ThrowErr(env, "Failed to get atomicFile"); } else { NError(errcode).ThrowErr(env); } -- Gitee From 25863077af924a0966c8234bf490b7a5ec9e146d Mon Sep 17 00:00:00 2001 From: renguang1116 Date: Sun, 27 Apr 2025 10:26:57 +0800 Subject: [PATCH 08/11] =?UTF-8?q?=E4=BF=AE=E5=A4=8DMTP=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E6=8B=B7=E8=B4=9D=E8=BF=87=E7=A8=8B=E4=B8=AD=E5=8F=96=E6=B6=88?= =?UTF-8?q?=E6=8B=B7=E8=B4=9D=E5=8A=9F=E8=83=BDbug=20Signed-off-by:=20reng?= =?UTF-8?q?uang1116=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- interfaces/kits/js/src/mod_fs/properties/copy.cpp | 13 +++++++++++++ interfaces/kits/js/src/mod_fs/properties/copy.h | 1 + interfaces/kits/native/task_signal/task_signal.cpp | 11 +++++++++++ 3 files changed, 25 insertions(+) diff --git a/interfaces/kits/js/src/mod_fs/properties/copy.cpp b/interfaces/kits/js/src/mod_fs/properties/copy.cpp index ffd87bebc..2fb408fc6 100644 --- a/interfaces/kits/js/src/mod_fs/properties/copy.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/copy.cpp @@ -97,6 +97,10 @@ static int OpenSrcFile(const string &srcPth, std::shared_ptr infos, i srcFd = open(srcPth.c_str(), O_RDONLY); if (srcFd < 0) { HILOGE("Error opening src file descriptor. errno = %{public}d", errno); + bool isCanceled = (infos->taskSignal != nullptr) && (infos->taskSignal->CheckCancelIfNeed(srcPth)); + if (isCanceled && Copy::IsMtpDeviceFilePath(srcPth)) { + return ECANCELED; + } return errno; } } @@ -850,6 +854,9 @@ tuple> Copy::CreateFileInfos( auto taskSignalEntity = NClass::GetEntityOf(infos->env, infos->copySignal.val_); if (taskSignalEntity != nullptr) { infos->taskSignal = taskSignalEntity->taskSignal_; + if (IsMtpDeviceFilePath(infos->srcPath)) { + infos->taskSignal->SetFileInfoOfRemoteTask("", infos->srcPath); + } } } return { ERRNO_NOERR, infos }; @@ -974,6 +981,12 @@ napi_value Copy::Async(napi_env env, napi_callback_info info) return NAsyncWorkCallback(env, thisVar, cb).Schedule(PROCEDURE_COPY_NAME, cbExec, cbCompl).val_; } } + +bool Copy::IsMtpDeviceFilePath(const std::string &path) +{ + const std::string MTP_PATH_PREFIX = "/storage/External/mtp"; + return path.rfind(MTP_PATH_PREFIX, 0) != std::string::npos; +} } // namespace ModuleFileIO } // namespace FileManagement } // namespace OHOS \ No newline at end of file diff --git a/interfaces/kits/js/src/mod_fs/properties/copy.h b/interfaces/kits/js/src/mod_fs/properties/copy.h index b08fd68f6..1c2a2f913 100644 --- a/interfaces/kits/js/src/mod_fs/properties/copy.h +++ b/interfaces/kits/js/src/mod_fs/properties/copy.h @@ -130,6 +130,7 @@ public: static std::map> jsCbMap_; static void UnregisterListener(std::shared_ptr fileInfos); static std::recursive_mutex mutex_; + static bool IsMtpDeviceFilePath(const std::string &path); private: // operator of napi diff --git a/interfaces/kits/native/task_signal/task_signal.cpp b/interfaces/kits/native/task_signal/task_signal.cpp index 4700448d2..c87de7055 100644 --- a/interfaces/kits/native/task_signal/task_signal.cpp +++ b/interfaces/kits/native/task_signal/task_signal.cpp @@ -17,12 +17,16 @@ #include "distributed_file_daemon_manager.h" #include "filemgmt_libhilog.h" +#include namespace OHOS { namespace DistributedFS { namespace ModuleTaskSignal { using namespace FileManagement; constexpr int CANCEL_ERR = -3; +const char CANCEL_XATTR_KEY[] = {"user.cancelcopy"}; +const std::string MTP_PATH_PREFIX = "/storage/External/mtp"; + int32_t TaskSignal::Cancel() { HILOGD("TaskSignal Cancel in."); @@ -40,6 +44,13 @@ int32_t TaskSignal::Cancel() } OnCancel(); return ret; + } else { + if (filePath_.rfind(MTP_PATH_PREFIX, 0) != std::string::npos) { + std::string value; + if (setxattr(filePath_.c_str(), CANCEL_XATTR_KEY, value.c_str(), value.size(), 0) < 0) { + HILOGE("cancelcopy setxattr fail, errno is %{public}d", errno); + } + } } needCancel_.store(true); return 0; -- Gitee From 385bcfa8a5be10a81f8b147a0f59dee2a8da8589 Mon Sep 17 00:00:00 2001 From: renguang1116 Date: Sun, 27 Apr 2025 03:18:13 +0000 Subject: [PATCH 09/11] update interfaces/kits/js/src/mod_fs/properties/copy.cpp. Signed-off-by: renguang1116 --- interfaces/kits/js/src/mod_fs/properties/copy.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interfaces/kits/js/src/mod_fs/properties/copy.cpp b/interfaces/kits/js/src/mod_fs/properties/copy.cpp index 2fb408fc6..ba09491ce 100644 --- a/interfaces/kits/js/src/mod_fs/properties/copy.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/copy.cpp @@ -53,6 +53,7 @@ const std::string NETWORK_PARA = "?networkid="; const string PROCEDURE_COPY_NAME = "FileFSCopy"; const std::string MEDIALIBRARY_DATA_URI = "datashare:///media"; const std::string MEDIA = "media"; +const std::string MTP_PATH_PREFIX = "/storage/External/mtp"; const int SLEEP_TIME = 100000; constexpr int DISMATCH = 0; constexpr int MATCH = 1; @@ -984,7 +985,6 @@ napi_value Copy::Async(napi_env env, napi_callback_info info) bool Copy::IsMtpDeviceFilePath(const std::string &path) { - const std::string MTP_PATH_PREFIX = "/storage/External/mtp"; return path.rfind(MTP_PATH_PREFIX, 0) != std::string::npos; } } // namespace ModuleFileIO -- Gitee From c9a381cefd4f2205548a7ad36b240901bc8b25af Mon Sep 17 00:00:00 2001 From: renguang1116 Date: Sun, 27 Apr 2025 12:36:01 +0000 Subject: [PATCH 10/11] update interfaces/kits/native/task_signal/task_signal.cpp. Signed-off-by: renguang1116 --- interfaces/kits/native/task_signal/task_signal.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interfaces/kits/native/task_signal/task_signal.cpp b/interfaces/kits/native/task_signal/task_signal.cpp index c87de7055..e8c72d3bb 100644 --- a/interfaces/kits/native/task_signal/task_signal.cpp +++ b/interfaces/kits/native/task_signal/task_signal.cpp @@ -46,7 +46,7 @@ int32_t TaskSignal::Cancel() return ret; } else { if (filePath_.rfind(MTP_PATH_PREFIX, 0) != std::string::npos) { - std::string value; + std::string value = ""; if (setxattr(filePath_.c_str(), CANCEL_XATTR_KEY, value.c_str(), value.size(), 0) < 0) { HILOGE("cancelcopy setxattr fail, errno is %{public}d", errno); } -- Gitee From 471efa4678741925da7afab4c1ae2f23c95d6263 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=AB=E5=BF=B5?= Date: Thu, 8 May 2025 22:40:34 +0800 Subject: [PATCH 11/11] hyperaio MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 别念 --- interfaces/test/unittest/BUILD.gn | 1 + interfaces/test/unittest/hyperaio/BUILD.gn | 42 ++++++++ .../test/unittest/hyperaio/hyperaio_test.cpp | 98 +++++++++++++++++++ 3 files changed, 141 insertions(+) create mode 100644 interfaces/test/unittest/hyperaio/BUILD.gn create mode 100644 interfaces/test/unittest/hyperaio/hyperaio_test.cpp diff --git a/interfaces/test/unittest/BUILD.gn b/interfaces/test/unittest/BUILD.gn index 95f924b84..b14741b2d 100644 --- a/interfaces/test/unittest/BUILD.gn +++ b/interfaces/test/unittest/BUILD.gn @@ -18,5 +18,6 @@ group("unittest") { "filemgmt_libn_test:filemgmt_libn_test", "remote_uri:remote_uri_test", "task_signal:task_signal_test", + "hyperaio:hyperaio_test" ] } diff --git a/interfaces/test/unittest/hyperaio/BUILD.gn b/interfaces/test/unittest/hyperaio/BUILD.gn new file mode 100644 index 000000000..7eac1d8db --- /dev/null +++ b/interfaces/test/unittest/hyperaio/BUILD.gn @@ -0,0 +1,42 @@ +# Copyright (c) 2025 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/test.gni") +import("//foundation/filemanagement/file_api/file_api.gni") + +ohos_unittest("hyperaio_test") { + module_out_path = "file_api/file_api" + + resource_config_file = "../resource/ohos_test.xml" + + sources = [ "hyperaio_test.cpp" ] + + include_dirs = [ + "include", + "${file_api_path}/interfaces/kits/hyperaio/include", + ] + + deps = [ + "${file_api_path}/interfaces/kits/hyperaio:HyperAio", + ] + + external_deps = [ + "ability_base:zuri", + "access_token:libaccesstoken_sdk", + "c_utils:utils", + "c_utils:utilsbase", + "ipc:ipc_core", + "googletest:gtest_main", + "liburing:liburing", + ] +} diff --git a/interfaces/test/unittest/hyperaio/hyperaio_test.cpp b/interfaces/test/unittest/hyperaio/hyperaio_test.cpp new file mode 100644 index 000000000..bfe94002e --- /dev/null +++ b/interfaces/test/unittest/hyperaio/hyperaio_test.cpp @@ -0,0 +1,98 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include + +#include "hyperaio.h" + +namespace { + using namespace std; + using namespace OHOS::HyperAio; + + class HyperAioTest : public testing::Test { + public: + static void SetUpTestCase(void) {}; + static void TearDownTestCase() {}; + void SetUp() {}; + void TearDown() {}; + }; + + /** + * @tc.name: HyperAio_StartOpenReqs_0000 + * @tc.desc: Test function of StartOpenReqs() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: AR000HG8M4 + */ + HWTEST_F(HyperAioTest, HyperAio_StartReadReqs_0000, testing::ext::TestSize.Level1) + { + GTEST_LOG_(INFO) << "HyperAioTest-begin HyperAio_StartReadReqs_0000"; + std::unique_ptr hyperAio = std::make_unique(); + int32_t result = hyperAio->CtxInit(nullptr); + EXPECT_EQ(result, EOK); + ReadInfo readInfo = {0, 1024, 0, nullptr, 12345}; + ReadReqs readReqs = {1, &readInfo}; + result = hyperAio->StartReadReqs(&readReqs); + EXPECT_EQ(result, EOK); + GTEST_LOG_(INFO) << "HyperAioTest-end HyperAio_StartReadReqs_0000"; + } + + /** + * @tc.name: HyperAio_StartReadReqs_0000 + * @tc.desc: Test function of StartReadReqs() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: AR000HG8M4 + */ + HWTEST_F(HyperAioTest, HyperAio_StartReadReqs_0000, testing::ext::TestSize.Level1) + { + GTEST_LOG_(INFO) << "HyperAioTest-begin HyperAio_StartReadReqs_0000"; + std::unique_ptr hyperAio = std::make_unique(); + int32_t result = hyperAio->CtxInit(nullptr); + EXPECT_EQ(result, EOK); + ReadInfo readInfo = {0, 1024, 0, nullptr, 12345}; + ReadReqs readReqs = {1, &readInfo}; + result = hyperAio->StartReadReqs(&readReqs); + EXPECT_EQ(result, EOK); + GTEST_LOG_(INFO) << "HyperAioTest-end HyperAio_StartReadReqs_0000"; + } + + /** + * @tc.name: HyperAio_StartReadReqs_0000 + * @tc.desc: Test function of StartReadReqs() interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + * @tc.require: AR000HG8M4 + */ + HWTEST_F(HyperAioTest, HyperAio_StartReadReqs_0000, testing::ext::TestSize.Level1) + { + GTEST_LOG_(INFO) << "HyperAioTest-begin HyperAio_StartReadReqs_0000"; + std::unique_ptr hyperAio = std::make_unique(); + int32_t result = hyperAio->CtxInit(nullptr); + EXPECT_EQ(result, EOK); + ReadInfo readInfo = {0, 1024, 0, nullptr, 12345}; + ReadReqs readReqs = {1, &readInfo}; + result = hyperAio->StartReadReqs(&readReqs); + EXPECT_EQ(result, EOK); + GTEST_LOG_(INFO) << "HyperAioTest-end HyperAio_StartReadReqs_0000"; + } + +} -- Gitee