diff --git a/file_api.gni b/file_api.gni index 5dfea39befa94dc3c84586eff0ff45fc49cbb47b..5b933bd19f9131ab1dc1ad8e10a3b87e5e63579d 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 18948e6db2ce20f5a0ca258ef4f0beaf347e12d0..4a67419f1e2341ca5d763664d10ce895e60c4c66 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 397f6df95b0162c220f9207bcaf0024adbc73722..6bedf0d00a7e0ac82e9ca7cf65196a9adb721dae 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 544c400471b215d8b83352b64f382bbcae624d66..91a12a41eaf71853a6ad97d4fabd884bb97f75a5 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 40acdf0af95f46f98fd91a5fdf88624334637fba..ff16921a08348dd2286a5baf9bd805a918457ac6 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 d3a3701e6dcc1ab28c6d303319661c34c43c34f6..62baa52067ffbbf08b400a343c9282244a52a6db 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 a8145961e129b8cde602dbe059d7bc290bb44d65..3158df16e7f027fbf02ef7c99e2c3d2edc2f2e65 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 5a0d652555eee288019dd32be8d6158f760ef939..c66b88a56b398ea86bbd5f6285baa0306e43545a 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 3204d9e6215887047c94cbb5de2d9ebcdd3d8692..a2d6a591272fc084f06551b6a52fb99350366bd5 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;