From 6ec001fee4e1020cfab2ba01544860c43e94b506 Mon Sep 17 00:00:00 2001 From: panqinxu Date: Fri, 30 Dec 2022 18:07:30 +0800 Subject: [PATCH] Add build_gn for mod_fs Signed-off-by: panqinxu --- file_api.gni | 5 +- interfaces/kits/js/BUILD.gn | 78 ++++++++++++------- .../js/src/mod_fs/class_file/file_entity.h | 3 +- interfaces/kits/js/src/mod_fs/common_func.h | 2 +- .../kits/js/src/mod_fs/properties/open.cpp | 2 +- .../src/mod_fs/properties/prop_n_exporter.cpp | 12 +++ interfaces/kits/js/src/mod_hash/hash.cpp | 6 +- utils/filemgmt_libn/include/n_val.h | 1 + utils/filemgmt_libn/src/n_val.cpp | 7 ++ 9 files changed, 81 insertions(+), 35 deletions(-) diff --git a/file_api.gni b/file_api.gni index 5dfea39be..5b933bd19 100644 --- a/file_api.gni +++ b/file_api.gni @@ -9,7 +9,10 @@ # 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. +# limitations under the License. aafwk_kits_path = "//foundation/ability/ability_runtime/frameworks/native" aafwk_path = "${aafwk_kits_path}/frameworks/kits" +file_api_path = "//foundation/filemanagement/file_api" +src_path = "${file_api_path}/interfaces/kits/js/src" +utils_path = "${file_api_path}/utils" diff --git a/interfaces/kits/js/BUILD.gn b/interfaces/kits/js/BUILD.gn index 18948e6db..4a67419f1 100644 --- a/interfaces/kits/js/BUILD.gn +++ b/interfaces/kits/js/BUILD.gn @@ -92,8 +92,8 @@ ohos_shared_library("fileio") { deps = [ "//foundation/arkui/napi:ace_napi", "//foundation/filemanagement/file_api/interfaces/kits/native:remote_uri_native", - "//third_party/bounds_checking_function:libsec_static", - "//third_party/openssl:libcrypto_static", + "//third_party/bounds_checking_function:libsec_shared", + "//third_party/openssl:libcrypto_shared", ] external_deps = [ "hiviewdfx_hilog_native:libhilog" ] @@ -106,26 +106,30 @@ ohos_shared_library("fs") { relative_install_dir = "module/file" include_dirs = [ - "//foundation/filemanagement/file_api/interfaces/kits/js/src/common/file_helper", - "//foundation/filemanagement/file_api/interfaces/kits/js/src/common/napi", - "//foundation/filemanagement/file_api/interfaces/kits/js/src/common/napi/n_async", + "${src_path}/common/file_helper", + "${src_path}/mod_fs", + "${utils_path}/filemgmt_libn/include", + "${utils_path}/filemgmt_libn/include/n_async", + "//third_party/libuv/include", ] - sources = file_common_src - sources += [ - "src/mod_fileio/class_file/file_n_exporter.cpp", - "src/mod_fileio/class_stat_v9/stat_n_exporter_v9.cpp", - "src/mod_fileio/common_func.cpp", - "src/mod_fileio/module_v9.cpp", - "src/mod_fileio/properties/open_v9.cpp", - "src/mod_fileio/properties/prop_n_exporter_v9.cpp", - "src/mod_fileio/properties/stat_v9.cpp", - "src/mod_fileio/properties/truncate_v9.cpp", + sources = [ + "src/common/file_helper/fd_guard.cpp", + "src/mod_fs/class_file/file_n_exporter.cpp", + "src/mod_fs/class_stat/stat_n_exporter.cpp", + "src/mod_fs/common_func.cpp", + "src/mod_fs/module.cpp", + "src/mod_fs/properties/lstat.cpp", + "src/mod_fs/properties/open.cpp", + "src/mod_fs/properties/prop_n_exporter.cpp", + "src/mod_fs/properties/stat.cpp", + "src/mod_fs/properties/symlink.cpp", + "src/mod_fs/properties/truncate.cpp", ] deps = [ - "//foundation/arkui/napi:ace_napi", - "//foundation/filemanagement/file_api/interfaces/kits/native:remote_uri_native", + "${file_api_path}/interfaces/kits/native:remote_uri_native", + "${utils_path}/filemgmt_libn:filemgmt_libn", ] external_deps = [ @@ -134,11 +138,37 @@ ohos_shared_library("fs") { "c_utils:utils", "data_share:datashare_common", "data_share:datashare_consumer", - "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", ] } +ohos_shared_library("hash") { + subsystem_name = "filemanagement" + part_name = "file_api" + + relative_install_dir = "module/file" + + include_dirs = [ + "${src_path}/common/file_helper", + "${utils_path}/filemgmt_libn/include", + "${utils_path}/filemgmt_libhilog", + ] + + sources = [ + "src/common/file_helper/fd_guard.cpp", + "src/common/file_helper/hash_file.cpp", + "src/mod_hash/hash.cpp", + "src/mod_hash/module.cpp", + ] + + deps = [ + "${utils_path}/filemgmt_libhilog:filemgmt_libhilog", + "${utils_path}/filemgmt_libn:filemgmt_libn", + "//third_party/bounds_checking_function:libsec_shared", + "//third_party/openssl:libcrypto_shared", + ] +} + ohos_shared_library("file") { subsystem_name = "filemanagement" part_name = "file_api" @@ -165,7 +195,7 @@ ohos_shared_library("file") { deps = [ "${aafwk_kits_path}/ability/native:abilitykit_native", "//foundation/arkui/napi:ace_napi", - "//third_party/bounds_checking_function:libsec_static", + "//third_party/bounds_checking_function:libsec_shared", ] external_deps = [ @@ -189,8 +219,6 @@ ohos_shared_library("statfs") { "//foundation/filemanagement/file_api/utils/filemgmt_libhilog", "//foundation/filemanagement/file_api/utils/filemgmt_libn", ] - - external_deps = [ "hiviewdfx_hilog_native:libhilog" ] } ohos_shared_library("statvfs") { @@ -208,8 +236,6 @@ ohos_shared_library("statvfs") { "//foundation/filemanagement/file_api/utils/filemgmt_libhilog", "//foundation/filemanagement/file_api/utils/filemgmt_libn", ] - - external_deps = [ "hiviewdfx_hilog_native:libhilog" ] } ohos_shared_library("environment") { @@ -218,8 +244,6 @@ ohos_shared_library("environment") { relative_install_dir = "module/file" - include_dirs = [ "//third_party/node/src" ] - sources = [ "src/mod_environment/environment_n_exporter.cpp", "src/mod_environment/environment_napi.cpp", @@ -232,7 +256,6 @@ ohos_shared_library("environment") { external_deps = [ "access_token:libtokenid_sdk", - "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", ] } @@ -255,8 +278,6 @@ ohos_shared_library("securitylabel") { "//foundation/filemanagement/file_api/utils/filemgmt_libhilog", "//foundation/filemanagement/file_api/utils/filemgmt_libn", ] - - external_deps = [ "hiviewdfx_hilog_native:libhilog" ] } ohos_shared_library("document") { @@ -294,6 +315,7 @@ group("build_kits_js") { ":file", ":fileio", ":fs", + ":hash", ":securitylabel", ":statfs", ":statvfs", diff --git a/interfaces/kits/js/src/mod_fs/class_file/file_entity.h b/interfaces/kits/js/src/mod_fs/class_file/file_entity.h index 397f6df95..6bedf0d00 100644 --- a/interfaces/kits/js/src/mod_fs/class_file/file_entity.h +++ b/interfaces/kits/js/src/mod_fs/class_file/file_entity.h @@ -16,6 +16,7 @@ #ifndef INTERFACES_KITS_JS_SRC_MOD_FS_CLASS_FILE_FILE_ENTITY_H #define INTERFACES_KITS_JS_SRC_MOD_FS_CLASS_FILE_FILE_ENTITY_H +#include #include #include "fd_guard.h" @@ -24,7 +25,7 @@ namespace OHOS { namespace FileManagement { namespace ModuleFileIO { struct FileEntity { - std::unique_ptr fd_ = { nullptr }; + std::unique_ptr fd_ = { nullptr }; std::string path_; std::string uri_; }; diff --git a/interfaces/kits/js/src/mod_fs/common_func.h b/interfaces/kits/js/src/mod_fs/common_func.h index 544c40047..91a12a41e 100644 --- a/interfaces/kits/js/src/mod_fs/common_func.h +++ b/interfaces/kits/js/src/mod_fs/common_func.h @@ -38,7 +38,7 @@ constexpr int SYNC = 04010000; struct FileInfo { bool isPath = false; std::unique_ptr path; - FDGuard fdg; + DistributedFS::FDGuard fdg; }; void InitOpenMode(napi_env env, napi_value exports); diff --git a/interfaces/kits/js/src/mod_fs/properties/open.cpp b/interfaces/kits/js/src/mod_fs/properties/open.cpp index 40acdf0af..ff16921a0 100644 --- a/interfaces/kits/js/src/mod_fs/properties/open.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/open.cpp @@ -66,7 +66,7 @@ static NVal InstantiateFile(napi_env env, int fd, string pathOrUri, bool isUri) NError(EIO).ThrowErr(env); return NVal(); } - auto fdg = make_unique(fd, false); + auto fdg = make_unique(fd, false); fileEntity->fd_.swap(fdg); if (isUri) { fileEntity->path_ = ""; diff --git a/interfaces/kits/js/src/mod_fs/properties/prop_n_exporter.cpp b/interfaces/kits/js/src/mod_fs/properties/prop_n_exporter.cpp index d3a3701e6..62baa5206 100644 --- a/interfaces/kits/js/src/mod_fs/properties/prop_n_exporter.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/prop_n_exporter.cpp @@ -27,7 +27,11 @@ #include "class_file/file_entity.h" #include "class_file/file_n_exporter.h" #include "filemgmt_libn.h" +#include "lstat.h" #include "open.h" +#include "stat.h" +#include "symlink.h" +#include "truncate.h" namespace OHOS { namespace FileManagement { @@ -266,10 +270,18 @@ napi_value PropNExporter::WriteSync(napi_env env, napi_callback_info info) bool PropNExporter::Export() { return exports_.AddProp({ + NVal::DeclareNapiFunction("lstat", Lstat::Async), + NVal::DeclareNapiFunction("lstatSync", Lstat::Sync), NVal::DeclareNapiFunction("open", Open::Async), NVal::DeclareNapiFunction("openSync", Open::Sync), NVal::DeclareNapiFunction("read", Read), NVal::DeclareNapiFunction("readSync", ReadSync), + NVal::DeclareNapiFunction("stat", Stat::Async), + NVal::DeclareNapiFunction("statSync", Stat::Sync), + NVal::DeclareNapiFunction("symlink", Symlink::Async), + NVal::DeclareNapiFunction("symlinkSync", Symlink::Sync), + NVal::DeclareNapiFunction("truncate", Truncate::Async), + NVal::DeclareNapiFunction("truncateSync", Truncate::Sync), NVal::DeclareNapiFunction("write", Write), NVal::DeclareNapiFunction("writeSync", WriteSync), }); diff --git a/interfaces/kits/js/src/mod_hash/hash.cpp b/interfaces/kits/js/src/mod_hash/hash.cpp index a8145961e..3158df16e 100644 --- a/interfaces/kits/js/src/mod_hash/hash.cpp +++ b/interfaces/kits/js/src/mod_hash/hash.cpp @@ -87,11 +87,11 @@ napi_value Hash::Async(napi_env env, napi_callback_info info) int ret = EIO; string &res = *arg; if (algType == HASH_ALGORITHM_TYPE_MD5) { - tie(ret, res) = HashFile::HashWithMD5(fpath); + tie(ret, res) = DistributedFS::HashFile::HashWithMD5(fpath); } else if (algType == HASH_ALGORITHM_TYPE_SHA1) { - tie(ret, res) = HashFile::HashWithSHA1(fpath); + tie(ret, res) = DistributedFS::HashFile::HashWithSHA1(fpath); } else if (algType == HASH_ALGORITHM_TYPE_SHA256) { - tie(ret, res) = HashFile::HashWithSHA256(fpath); + tie(ret, res) = DistributedFS::HashFile::HashWithSHA256(fpath); } return NError(ret); }; diff --git a/utils/filemgmt_libn/include/n_val.h b/utils/filemgmt_libn/include/n_val.h index 5a0d65255..c66b88a56 100644 --- a/utils/filemgmt_libn/include/n_val.h +++ b/utils/filemgmt_libn/include/n_val.h @@ -57,6 +57,7 @@ public: /* Static helpers to create js objects */ static NVal CreateUndefined(napi_env env); + static NVal CreateBigInt64(napi_env env, int64_t val); static NVal CreateInt64(napi_env env, int64_t val); static NVal CreateInt32(napi_env env, int32_t val); static NVal CreateObject(napi_env env); diff --git a/utils/filemgmt_libn/src/n_val.cpp b/utils/filemgmt_libn/src/n_val.cpp index 3204d9e62..a2d6a5912 100644 --- a/utils/filemgmt_libn/src/n_val.cpp +++ b/utils/filemgmt_libn/src/n_val.cpp @@ -237,6 +237,13 @@ NVal NVal::CreateUndefined(napi_env env) return {env, res}; } +NVal NVal::CreateBigInt64(napi_env env, int64_t val) +{ + napi_value res = nullptr; + napi_create_bigint_int64(env, val, &res); + return { env, res }; +} + NVal NVal::CreateInt64(napi_env env, int64_t val) { napi_value res = nullptr; -- Gitee