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 3a620f1fc2176403c9ee555e54225e1b4b016c85..bbe140fbb1839681212fdc407395cf9bcccac6c8 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()); diff --git a/interfaces/kits/js/src/mod_fs/common_func.cpp b/interfaces/kits/js/src/mod_fs/common_func.cpp index 6193013a3afc892ae12f1afa3babee85bd964689..46e0cf65305ec9d29ceae31af6eab067bb7b5480 100644 --- a/interfaces/kits/js/src/mod_fs/common_func.cpp +++ b/interfaces/kits/js/src/mod_fs/common_func.cpp @@ -78,6 +78,55 @@ void InitAccessModeType(napi_env env, napi_value exports) } } +void InitAccessFlagType(napi_env env, napi_value exports) +{ + char propertyName[] = "AccessFlagType"; + napi_property_descriptor desc[] = { + DECLARE_NAPI_STATIC_PROPERTY("LOCAL", NVal::CreateInt32(env, MODE_LOCAL).val_), + }; + napi_value obj = nullptr; + napi_status status = napi_create_object(env, &obj); + if (status != napi_ok) { + HILOGE("Failed to create object at initializing AccessFlagType"); + return; + } + status = napi_define_properties(env, obj, sizeof(desc) / sizeof(desc[0]), desc); + if (status != napi_ok) { + HILOGE("Failed to set properties of character at initializing AccessFlagType"); + return; + } + status = napi_set_named_property(env, exports, propertyName, obj); + if (status != napi_ok) { + HILOGE("Failed to set direction property at initializing AccessFlagType"); + return; + } +} + +void InitLocationType(napi_env env, napi_value exports) +{ + char propertyName[] = "LocationType"; + napi_property_descriptor desc[] = { + DECLARE_NAPI_STATIC_PROPERTY("LOCAl", NVal::CreateInt32(env, MODE_LOCATION_LOCAL).val_), + DECLARE_NAPI_STATIC_PROPERTY("CLOUD", NVal::CreateInt32(env, MODE_LOCATION_CLOUD).val_), + }; + napi_value obj = nullptr; + napi_status status = napi_create_object(env, &obj); + if (status != napi_ok) { + HILOGE("Failed to create object at initializing LocationType"); + return; + } + status = napi_define_properties(env, obj, sizeof(desc) / sizeof(desc[0]), desc); + if (status != napi_ok) { + HILOGE("Failed to set properties of character at initializing LocationType"); + return; + } + status = napi_set_named_property(env, exports, propertyName, obj); + if (status != napi_ok) { + HILOGE("Failed to set direction property at initializing LocationType"); + return; + } +} + void InitOpenMode(napi_env env, napi_value exports) { char propertyName[] = "OpenMode"; diff --git a/interfaces/kits/js/src/mod_fs/common_func.h b/interfaces/kits/js/src/mod_fs/common_func.h index 567cf26b4b167d3da00d1a439b8bfc469babbefa..7b6a2052b1e4609c855e8e40e8b9840519b2b821 100644 --- a/interfaces/kits/js/src/mod_fs/common_func.h +++ b/interfaces/kits/js/src/mod_fs/common_func.h @@ -44,6 +44,10 @@ constexpr unsigned int MODE_WRITE = 02; constexpr unsigned int MODE_READ = 04; constexpr unsigned int MODE_READ_WRITE = 06; +constexpr unsigned int MODE_LOCAL = 00; +constexpr unsigned int MODE_LOCATION_LOCAL = 01; +constexpr unsigned int MODE_LOCATION_CLOUD = 02; + constexpr unsigned int USR_READ_ONLY = 00; constexpr unsigned int USR_WRITE_ONLY = 01; constexpr unsigned int USR_RDWR = 02; @@ -75,6 +79,8 @@ public: #endif void InitAccessModeType(napi_env env, napi_value exports); +void InitAccessFlagType(napi_env env, napi_value exports); +void InitLocationType(napi_env env, napi_value exports); void InitOpenMode(napi_env env, napi_value exports); void InitWhenceType(napi_env env, napi_value exports); diff --git a/interfaces/kits/js/src/mod_fs/module.cpp b/interfaces/kits/js/src/mod_fs/module.cpp index 8944c27a6c2d0b4b08a0ef60459c607e182d13ac..cdbc61f85d1979a590f671887061240364399c5a 100644 --- a/interfaces/kits/js/src/mod_fs/module.cpp +++ b/interfaces/kits/js/src/mod_fs/module.cpp @@ -39,6 +39,8 @@ namespace ModuleFileIO { static napi_value Export(napi_env env, napi_value exports) { InitAccessModeType(env, exports); + InitAccessFlagType(env, exports); + InitLocationType(env, exports); InitOpenMode(env, exports); InitWhenceType(env, exports); std::vector> products; diff --git a/interfaces/kits/rust/BUILD.gn b/interfaces/kits/rust/BUILD.gn index a4cc7d69884cbd02fb53601c148ad8a0643bd072..965a4ec2138a9353e605c806118cb3e4eadf85d5 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" ] } diff --git a/interfaces/test/unittest/class_file/rust_test.cpp b/interfaces/test/unittest/class_file/rust_test.cpp index 7b3800a8be0d056e7503b540fc5c3047296a46c0..6c60bd3b1abccf5fcc9f39c3118d3d5342604f40 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"; diff --git a/interfaces/test/unittest/napi_test/BUILD.gn b/interfaces/test/unittest/napi_test/BUILD.gn index d0dbea092a180fc3e1186c50ad25448b58189bc2..40c83b511a39d4404a1e184e47ca702a71988991 100644 --- a/interfaces/test/unittest/napi_test/BUILD.gn +++ b/interfaces/test/unittest/napi_test/BUILD.gn @@ -13,7 +13,7 @@ import("//build/test.gni") -module_output_path = "file_api/napi" +module_output_path = "file_api/file_api" ohos_js_unittest("file_api_js_test") { module_out_path = module_output_path hap_profile = "./config.json" 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 9cad32c850d274ac7fcb7dfee9a9bcfa2141d77c..4f2e88a80ff631e5d08e328337710a53c6a5783e 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 @@ -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; }