From 45661da8ef0ad4f3e32384b4647ba151d1fa828a Mon Sep 17 00:00:00 2001 From: zhangxiaoliang25 Date: Sat, 8 Mar 2025 19:59:34 +0800 Subject: [PATCH] =?UTF-8?q?gn=E6=96=87=E4=BB=B6=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhangxiaoliang25 Change-Id: I419852533f17eed6e2c65f770cea6ef6ca94f47a --- bundle.json | 16 +- interfaces/kits/js/BUILD.gn | 270 ++++++++++++++++++ .../kits/js/src/mod_fs/ani/arktsconfig.json | 19 ++ .../js/src/mod_fs/ani/bind_function_class.cpp | 78 +++++ .../src/mod_fs/properties/ani/access_ani.cpp | 10 +- .../src/mod_fs/properties/ani/mkdir_ani.cpp | 4 +- .../src/mod_fs/properties/ani/unlink_ani.cpp | 2 +- 7 files changed, 389 insertions(+), 10 deletions(-) create mode 100644 interfaces/kits/js/src/mod_fs/ani/arktsconfig.json create mode 100644 interfaces/kits/js/src/mod_fs/ani/bind_function_class.cpp diff --git a/bundle.json b/bundle.json index 60c317e0e..34a4f196e 100644 --- a/bundle.json +++ b/bundle.json @@ -41,9 +41,11 @@ "ipc", "init", "napi", + "runtime_core", "samgr", "app_file_service", - "os_account" + "os_account", + "libuv" ], "third_party": [ "e2fsprogs", @@ -56,7 +58,8 @@ "fwk_group": [ "//foundation/filemanagement/file_api/interfaces/kits/js:build_kits_js", "//foundation/filemanagement/file_api/interfaces/kits/ts/streamrw:streamrw_packages", - "//foundation/filemanagement/file_api/interfaces/kits/ts/streamhash:streamhash_packages" + "//foundation/filemanagement/file_api/interfaces/kits/ts/streamhash:streamhash_packages", + "//foundation/filemanagement/file_api/interfaces/kits/js:ani_file_api" ], "service_group": [] }, @@ -97,6 +100,15 @@ "header_base": "//foundation/filemanagement/file_api/interfaces/kits/rust/include" } }, + { + "name": "//foundation/filemanagement/file_api/utils/filemgmt_libfs:filemgmt_libfs", + "header": { + "header_files": [ + "filemgmt_libfs.h" + ], + "header_base": "//foundation/filemanagement/file_api/utils/filemgmt_libfs/include" + } + }, { "name": "//foundation/filemanagement/file_api/utils/filemgmt_libn:filemgmt_libn", "header": { diff --git a/interfaces/kits/js/BUILD.gn b/interfaces/kits/js/BUILD.gn index 3c9b376ee..8e0e86004 100644 --- a/interfaces/kits/js/BUILD.gn +++ b/interfaces/kits/js/BUILD.gn @@ -11,6 +11,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +import("//build/config/components/ets_frontend/ets2abc_config.gni") import("//build/ohos.gni") import("//foundation/filemanagement/file_api/file_api.gni") @@ -618,3 +619,272 @@ group("build_kits_js") { ":statvfs", ] } + +group("ani_file_api") { + deps = [ + ":ani_fs_class", + ":ani_hash_class", + ":ani_securitylabel_class", + ] +} + +config("ani_config") { + include_dirs = [ + "./include", + "${file_api_path}/interfaces/kits/rust/include", + "${utils_path}/common/include", + "${utils_path}/filemgmt_libfs/include", + "${utils_path}/filemgmt_libhilog", + "src/common", + "src/common/ani_helper", + "src/common/file_helper", + "src/mod_fs", + "//third_party/libuv/include", + "${filemanagement_service_path}/distributedfiledaemon/include/ipc", + ] + + cflags = [ + "-fvisibility=hidden", + "-fdata-sections", + "-ffunction-sections", + "-Oz", + ] + cflags_cc = [ + "-std=c++17", + "-fvisibility-inlines-hidden", + "-Oz", + "-Wno-unused-function", + ] +} + +ohos_shared_library("ani_fs_class") { + public_configs = [ ":ani_config" ] + include_dirs = [ + "src/mod_fs/ani", + "src/mod_fs/class_stat", + "src/mod_fs/properties", + "src/mod_fs/properties/ani", + "${src_path}/mod_fs/properties/copy_listener", + ] + sources = [ + "src/common/ani_helper/bind_function.cpp", + "src/common/ani_helper/type_converter.cpp", + "src/common/file_helper/fd_guard.cpp", + "src/mod_fs/ani/bind_function_class.cpp", + "src/mod_fs/class_stat/fs_stat.cpp", + "src/mod_fs/fs_utils.cpp", + "src/mod_fs/properties/access_core.cpp", + "src/mod_fs/properties/ani/access_ani.cpp", + "src/mod_fs/properties/ani/copy_file_ani.cpp", + "src/mod_fs/properties/ani/mkdir_ani.cpp", + "src/mod_fs/properties/ani/move_ani.cpp", + "src/mod_fs/properties/ani/rmdir_ani.cpp", + "src/mod_fs/properties/ani/stat_ani.cpp", + "src/mod_fs/properties/ani/unlink_ani.cpp", + "src/mod_fs/properties/copy_file_core.cpp", + "src/mod_fs/properties/mkdir_core.cpp", + "src/mod_fs/properties/move_core.cpp", + "src/mod_fs/properties/rmdir_core.cpp", + "src/mod_fs/properties/stat_core.cpp", + "src/mod_fs/properties/unlink_core.cpp", + ] + deps = [ + ":ani_fs_abc_etc", + "${file_api_path}/interfaces/kits/rust:rust_file", + "${utils_path}/filemgmt_libfs:filemgmt_libfs", + "${utils_path}/filemgmt_libhilog:filemgmt_libhilog", + ] + use_exceptions = true + external_deps = [ + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", + "c_utils:utils", + "hilog:libhilog", + "ipc:ipc_core", + "libuv:uv", + "runtime_core:ani", + "runtime_core:libarkruntime", + "samgr:samgr_proxy", + ] + + cflags = [ + "-fvisibility=hidden", + "-fdata-sections", + "-ffunction-sections", + "-Oz", + ] + cflags_cc = [ + "-std=c++17", + "-fvisibility-inlines-hidden", + "-Oz", + "-Wno-unused-function", + ] + branch_protector_ret = "pac_ret" + sanitize = { + integer_overflow = true + ubsan = true + boundary_sanitize = true + cfi = true + cfi_cross_dso = true + debug = false + } + subsystem_name = "filemanagement" + part_name = "file_api" +} + +generate_static_abc("ani_fs_abc") { + arktsconfig = "src/mod_fs/ani/arktsconfig.json" + dst_file = "$target_out_dir/ani_fs.abc" + out_puts = [ "$target_out_dir/ani_fs.abc" ] + is_boot_abc = "True" + device_dst_file = "/system/framework/ani_fs.abc" + cache_path = "$target_out_dir/cache" +} + +ohos_prebuilt_etc("ani_fs_abc_etc") { + source = "$target_out_dir/ani_fs.abc" + module_install_dir = "fs" + subsystem_name = "filemanagement" + part_name = "file_api" + deps = [ ":ani_fs_abc" ] +} + +ohos_shared_library("ani_hash_class") { + public_configs = [ ":ani_config" ] + include_dirs = [ + "src/mod_hash", + "src/mod_hash/ani", + ] + sources = [ + "src/common/ani_helper/bind_function.cpp", + "src/common/ani_helper/type_converter.cpp", + "src/common/file_helper/fd_guard.cpp", + "src/common/file_helper/hash_file.cpp", + "src/mod_fs/fs_utils.cpp", + "src/mod_hash/ani/bind_function_class.cpp", + "src/mod_hash/ani/hash_ani.cpp", + "src/mod_hash/hash_core.cpp", + ] + + deps = [ + ":ani_hash_abc_etc", + "${file_api_path}/interfaces/kits/rust:rust_file", + "${utils_path}/filemgmt_libfs:filemgmt_libfs", + "${utils_path}/filemgmt_libhilog:filemgmt_libhilog", + "//third_party/openssl:libcrypto_shared", + ] + external_deps = [ + "hilog:libhilog", + "libuv:uv", + "runtime_core:ani", + "runtime_core:libarkruntime", + ] + use_exceptions = true + cflags = [ + "-fvisibility=hidden", + "-fdata-sections", + "-ffunction-sections", + "-Oz", + ] + cflags_cc = [ + "-fvisibility-inlines-hidden", + "-Oz", + ] + branch_protector_ret = "pac_ret" + sanitize = { + integer_overflow = true + ubsan = true + boundary_sanitize = true + cfi = true + cfi_cross_dso = true + debug = false + } + subsystem_name = "filemanagement" + part_name = "file_api" +} + +generate_static_abc("ani_hash_abc") { + arktsconfig = "src/mod_hash/ani/arktsconfig.json" + dst_file = "$target_out_dir/ani_hash.abc" + out_puts = [ "$target_out_dir/ani_hash.abc" ] + is_boot_abc = "True" + device_dst_file = "/system/framework/ani_hash.abc" + cache_path = "$target_out_dir/cache" +} + +ohos_prebuilt_etc("ani_hash_abc_etc") { + source = "$target_out_dir/ani_hash.abc" + module_install_dir = "hash" + subsystem_name = "filemanagement" + part_name = "file_api" + deps = [ ":ani_hash_abc" ] +} + +ohos_shared_library("ani_securitylabel_class") { + public_configs = [ ":ani_config" ] + include_dirs = [ + "src/mod_securitylabel/ani", + "src/mod_securitylabel", + ] + sources = [ + "src/common/ani_helper/bind_function.cpp", + "src/common/ani_helper/type_converter.cpp", + "src/common/file_helper/fd_guard.cpp", + "src/mod_fs/fs_utils.cpp", + "src/mod_securitylabel/ani/bind_function_class.cpp", + "src/mod_securitylabel/ani/securitylabel_ani.cpp", + "src/mod_securitylabel/securitylabel_core.cpp", + ] + + deps = [ + ":ani_securitylabel_abc_etc", + "${file_api_path}/interfaces/kits/rust:rust_file", + "${utils_path}/filemgmt_libfs:filemgmt_libfs", + "${utils_path}/filemgmt_libhilog:filemgmt_libhilog", + ] + external_deps = [ + "hilog:libhilog", + "libuv:uv", + "runtime_core:ani", + "runtime_core:libarkruntime", + ] + use_exceptions = true + cflags = [ + "-fvisibility=hidden", + "-fdata-sections", + "-ffunction-sections", + "-Oz", + ] + cflags_cc = [ + "-fvisibility-inlines-hidden", + "-Oz", + ] + branch_protector_ret = "pac_ret" + sanitize = { + integer_overflow = true + ubsan = true + boundary_sanitize = true + cfi = true + cfi_cross_dso = true + debug = false + } + subsystem_name = "filemanagement" + part_name = "file_api" +} + +generate_static_abc("ani_securitylabel_abc") { + arktsconfig = "src/mod_securitylabel/ani/arktsconfig.json" + dst_file = "$target_out_dir/ani_securitylabel.abc" + out_puts = [ "$target_out_dir/ani_securitylabel.abc" ] + is_boot_abc = "True" + device_dst_file = "/system/framework/ani_securitylabel.abc" + cache_path = "$target_out_dir/cache" +} + +ohos_prebuilt_etc("ani_securitylabel_abc_etc") { + source = "$target_out_dir/ani_securitylabel.abc" + module_install_dir = "securitylabel" + subsystem_name = "filemanagement" + part_name = "file_api" + deps = [ ":ani_securitylabel_abc" ] +} diff --git a/interfaces/kits/js/src/mod_fs/ani/arktsconfig.json b/interfaces/kits/js/src/mod_fs/ani/arktsconfig.json new file mode 100644 index 000000000..748c90571 --- /dev/null +++ b/interfaces/kits/js/src/mod_fs/ani/arktsconfig.json @@ -0,0 +1,19 @@ + +{ + "compilerOptions": { + "package": "", + "baseUrl": ".", + "outDir": "./dist", + "paths": { + "std": [ + "../../../../../../../../../arkcompiler/runtime_core/static_core/plugins/ets/stdlib/std" + ], + "escompat": [ + "../../../../../../../../../arkcompiler/runtime_core/static_core/plugins/ets/stdlib/escompat" + ] + } + }, + "include": [ + "*.ets" + ] +} diff --git a/interfaces/kits/js/src/mod_fs/ani/bind_function_class.cpp b/interfaces/kits/js/src/mod_fs/ani/bind_function_class.cpp new file mode 100644 index 000000000..9498f8479 --- /dev/null +++ b/interfaces/kits/js/src/mod_fs/ani/bind_function_class.cpp @@ -0,0 +1,78 @@ +/* + * 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 "access_ani.h" +#include "bind_function.h" +#include "copy_file_ani.h" +#include "mkdir_ani.h" +#include "move_ani.h" +#include "stat_ani.h" +#include "unlink_ani.h" +#include "rmdir_ani.h" + +using namespace OHOS::FileManagement::ModuleFileIO::ANI; + +static ani_status BindStatMethods(ani_vm *vm) +{ + static const char *className = "Lfile_fs_class/StatInner;"; + + std::vector methods = { + ani_native_function { "isBlockDevice", ":Z", reinterpret_cast(StatAni::IsBlockDevice) }, + ani_native_function { "isCharacterDevice", ":Z", reinterpret_cast(StatAni::IsCharacterDevice) }, + ani_native_function { "isDirectory", ":Z", reinterpret_cast(StatAni::IsDirectory) }, + ani_native_function { "isFIFO", ":Z", reinterpret_cast(StatAni::IsFIFO) }, + ani_native_function { "isFile", ":Z", reinterpret_cast(StatAni::IsFile) }, + ani_native_function { "isSocket", ":Z", reinterpret_cast(StatAni::IsSocket) }, + ani_native_function { "isSymbolicLink", ":Z", reinterpret_cast(StatAni::IsSymbolicLink) }, + }; + + return BindClass(vm, className, methods); +} + +static ani_status BindFileFs(ani_vm *vm) +{ + static const char *className = "Lfile_fs_class/fileIo;"; + + std::vector functions = { + ani_native_function { "doAccessSync", nullptr, reinterpret_cast(AccessAni::AccessSync3) }, + ani_native_function { "unlinkSync", "Lstd/core/String;:I", reinterpret_cast(UnlinkAni::UnlinkSync) }, + ani_native_function { "mkdirSync", "Lstd/core/String;:I", reinterpret_cast(MkdirkAni::MkdirSync0) }, + ani_native_function { "mkdirSync", "Lstd/core/String;Z:I", reinterpret_cast(MkdirkAni::MkdirSync1) }, + ani_native_function { "moveFileSync", "Lstd/core/String;Lstd/core/String;Lstd/core/Int;:V", + reinterpret_cast(MoveAni::MoveFileSync) }, + ani_native_function { "copyFileSync", nullptr, reinterpret_cast(CopyFileAni::CopyFileSync) }, + ani_native_function { "statSync", nullptr, reinterpret_cast(StatAni::StatSync) }, + ani_native_function { "rmdirSync", "Lstd/core/String;:V", reinterpret_cast(RmdirAni::RmdirSync) }, + }; + + return BindClass(vm, className, functions); +} + +ANI_EXPORT ani_status ANI_Constructor(ani_vm *vm, uint32_t *result) +{ + *result = ANI_VERSION_1; + ani_status ret = ANI_OK; + if (ANI_OK != (ret = BindStatMethods(vm))) { + return ret; + }; + + if (ANI_OK != (ret = BindFileFs(vm))) { + return ret; + }; + return ret; +} diff --git a/interfaces/kits/js/src/mod_fs/properties/ani/access_ani.cpp b/interfaces/kits/js/src/mod_fs/properties/ani/access_ani.cpp index e80311d0f..854a8407d 100644 --- a/interfaces/kits/js/src/mod_fs/properties/ani/access_ani.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/ani/access_ani.cpp @@ -57,17 +57,17 @@ std::optional OptToAccessModeType(const std::optional& mode return ToAccessModeType(mode_index.value()); } -AccessFlagType ToAccessFlagType(int32_t flag_index) +AccessFlag ToAccessFlagType(int32_t flag_index) { switch (flag_index) { case LOCAL_INDEX: - return AccessFlagType::LOCAL_FLAG; + return AccessFlag::LOCAL_FLAG; default: - return AccessFlagType::DEFAULT_FLAG; + return AccessFlag::DEFAULT_FLAG; } } -std::optional OptToAccessFlagType(const std::optional &flag_index) +std::optional OptToAccessFlagType(const std::optional &flag_index) { if (!flag_index.has_value()) { return std::nullopt; @@ -79,7 +79,7 @@ ani_boolean AccessAni::AccessSync3(ani_env *env, [[maybe_unused]] ani_class claz ani_enum_item mode, ani_enum_item flag) { ani_boolean ret = 0; - auto [succPath, pathStr] = TypeConverter::ToUTF8StringPath(env, path); + auto [succPath, pathStr] = TypeConverter::ToUTF8String(env, path); if (! succPath) { HILOGE("Invalid path"); return ret; diff --git a/interfaces/kits/js/src/mod_fs/properties/ani/mkdir_ani.cpp b/interfaces/kits/js/src/mod_fs/properties/ani/mkdir_ani.cpp index e2a6bc6ef..ca260b2d2 100644 --- a/interfaces/kits/js/src/mod_fs/properties/ani/mkdir_ani.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/ani/mkdir_ani.cpp @@ -28,7 +28,7 @@ namespace ANI { ani_int MkdirkAni::MkdirSync0(ani_env *env, [[maybe_unused]] ani_class clazz, ani_string path) { - auto [succ, pathStr] = TypeConverter::ToUTF8StringPath(env, path); + auto [succ, pathStr] = TypeConverter::ToUTF8String(env, path); if (!succ) { HILOGE("Invalid path"); return -1; @@ -43,7 +43,7 @@ ani_int MkdirkAni::MkdirSync0(ani_env *env, [[maybe_unused]] ani_class clazz, an ani_int MkdirkAni::MkdirSync1(ani_env *env, [[maybe_unused]] ani_class clazz, ani_string path, ani_boolean recursion) { - auto [succ, pathStr] = ANI::TypeConverter::ToUTF8StringPath(env, path); + auto [succ, pathStr] = ANI::TypeConverter::ToUTF8String(env, path); if (!succ) { HILOGE("Invalid path"); return -1; diff --git a/interfaces/kits/js/src/mod_fs/properties/ani/unlink_ani.cpp b/interfaces/kits/js/src/mod_fs/properties/ani/unlink_ani.cpp index 13ded3282..cfca74539 100644 --- a/interfaces/kits/js/src/mod_fs/properties/ani/unlink_ani.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/ani/unlink_ani.cpp @@ -28,7 +28,7 @@ namespace ANI { ani_int UnlinkAni::UnlinkSync(ani_env *env, [[maybe_unused]] ani_class clazz, ani_string path) { - auto [succ, pathStr] = TypeConverter::ToUTF8StringPath(env, path); + auto [succ, pathStr] = TypeConverter::ToUTF8String(env, path); if (!succ) { HILOGE("Invalid path"); return -1; -- Gitee