diff --git a/interfaces/kits/js/BUILD.gn b/interfaces/kits/js/BUILD.gn index 4924df5ca4554cad8fa16a86df447adfbc61a4a1..3189321612d37b7013da20a8bb7c2629109ca481 100644 --- a/interfaces/kits/js/BUILD.gn +++ b/interfaces/kits/js/BUILD.gn @@ -109,7 +109,6 @@ ohos_shared_library("fs") { relative_install_dir = "module/file" include_dirs = [ - "${file_api_path}/interfaces/kits/rust/include", "${src_path}/common", "${src_path}/common/file_helper", "${src_path}/mod_fs", @@ -139,7 +138,6 @@ ohos_shared_library("fs") { cflags_cc = [ "-std=c++17" ] deps = [ - "${file_api_path}/interfaces/kits/rust:rust_file", "${utils_path}/filemgmt_libhilog:filemgmt_libhilog", "${utils_path}/filemgmt_libn:filemgmt_libn", ] @@ -159,8 +157,10 @@ ohos_shared_library("fs") { ] if (!use_mingw_win && !use_mac) { + include_dirs += [ "${file_api_path}/interfaces/kits/rust/include" ] sources += [ "src/mod_fs/class_randomaccessfile/randomaccessfile_n_exporter.cpp", + "src/mod_fs/class_readeriterator/readeriterator_n_exporter.cpp", "src/mod_fs/class_stream/flush.cpp", "src/mod_fs/class_stream/stream_n_exporter.cpp", "src/mod_fs/class_watcher/watcher_entity.cpp", @@ -190,11 +190,13 @@ ohos_shared_library("fs") { "c_utils:utils", "data_share:datashare_common", "data_share:datashare_consumer", - "hilog:hilog_rust", "ipc:ipc_core", "samgr:samgr_proxy", ] - deps += [ "${file_api_path}/interfaces/kits/native:remote_uri_native" ] + deps += [ + "${file_api_path}/interfaces/kits/native:remote_uri_native", + "${file_api_path}/interfaces/kits/rust:rust_file", + ] } } diff --git a/interfaces/kits/js/src/mod_fs/class_file/file_n_exporter.cpp b/interfaces/kits/js/src/mod_fs/class_file/file_n_exporter.cpp index 2dd5ac74432d781d990391ccc2cf8445a179cf53..bfa6855f2976ca6cc2f3da52f8d782da3f1d581a 100644 --- a/interfaces/kits/js/src/mod_fs/class_file/file_n_exporter.cpp +++ b/interfaces/kits/js/src/mod_fs/class_file/file_n_exporter.cpp @@ -23,11 +23,13 @@ #include #include -#include "file_uri.h" #include "file_utils.h" #include "filemgmt_libhilog.h" #include "filemgmt_libn.h" #include "../common_func.h" +#if !defined(WIN_PLATFORM) && !defined(IOS_PLATFORM) +#include "file_uri.h" +#endif namespace OHOS { namespace FileManagement { @@ -147,6 +149,43 @@ napi_value FileNExporter::GetName(napi_env env, napi_callback_info info) return NVal::CreateUTF8String(env, path.substr(pos + 1)).val_; } +napi_value FileNExporter::GetParent(napi_env env, napi_callback_info info) +{ + NFuncArg funcArg(env, info); + if (!funcArg.InitArgs(NARG_CNT::ZERO)) { + HILOGE("Number of arguments unmatched"); + NError(EINVAL).ThrowErr(env); + return nullptr; + } + auto fileEntity = GetFileEntity(env, funcArg.GetThisVar()); + if (!fileEntity) { + HILOGE("Failed to get file entity"); + NError(EINVAL).ThrowErr(env); + return nullptr; + } + + string path(fileEntity->path_); +#ifndef IOS_PLATFORM + if (fileEntity->uri_.length() != 0) { + AppFileService::ModuleFileUri::FileUri fileUri(fileEntity->uri_); + path = fileUri.GetRealPath(); + } +#endif + auto [realPathRes, realPath] = RealPathCore(path); + if (realPathRes != ERRNO_NOERR) { + NError(realPathRes).ThrowErr(env); + return nullptr; + } + path = string(static_cast(realPath->ptr)); + auto pos = path.find_last_of('/'); + if (pos == string::npos) { + HILOGE("Failed to split filename from path"); + NError(ENOENT).ThrowErr(env); + return nullptr; + } + return NVal::CreateUTF8String(env, path.substr(0, pos)).val_; +} + napi_value FileNExporter::Lock(napi_env env, napi_callback_info info) { NFuncArg funcArg(env, info); @@ -283,43 +322,6 @@ napi_value FileNExporter::Constructor(napi_env env, napi_callback_info info) return funcArg.GetThisVar(); } -napi_value FileNExporter::GetParent(napi_env env, napi_callback_info info) -{ - NFuncArg funcArg(env, info); - if (!funcArg.InitArgs(NARG_CNT::ZERO)) { - HILOGE("Number of arguments unmatched"); - NError(EINVAL).ThrowErr(env); - return nullptr; - } - auto fileEntity = GetFileEntity(env, funcArg.GetThisVar()); - if (!fileEntity) { - HILOGE("Failed to get file entity"); - return nullptr; - } - - string path = ""; - if (fileEntity->path_.length() != 0) { - auto [realPathRes, realPath] = RealPathCore(fileEntity->path_); - if (realPathRes != ERRNO_NOERR) { - NError(realPathRes).ThrowErr(env); - return nullptr; - } - path = string(static_cast(realPath->ptr)); - } else { - AppFileService::ModuleFileUri::FileUri fileUri(fileEntity->uri_); - string path = fileUri.GetRealPath(); - } - auto pos = path.find_last_of('/'); - if (pos == string::npos) { - HILOGE("Failed to split filename from path, path: %{public}s", path.c_str()); - NError(ENOENT).ThrowErr(env); - return nullptr; - } - string parentPath = path.substr(0, pos); - HILOGE("parentPath is : %{public}s", parentPath.c_str()); - return NVal::CreateUTF8String(env, parentPath).val_; -} - bool FileNExporter::Export() { vector props = { diff --git a/interfaces/kits/js/src/mod_fs/class_file/file_n_exporter.h b/interfaces/kits/js/src/mod_fs/class_file/file_n_exporter.h index 6b2ce05cb49960aee8caaf5b925d52fb77e17d1f..789ebc08398b883fda07509303e44e3d78688df6 100644 --- a/interfaces/kits/js/src/mod_fs/class_file/file_n_exporter.h +++ b/interfaces/kits/js/src/mod_fs/class_file/file_n_exporter.h @@ -33,10 +33,10 @@ public: std::string GetClassName() override; static napi_value GetPath(napi_env env, napi_callback_info info); static napi_value GetName(napi_env env, napi_callback_info info); + static napi_value GetParent(napi_env env, napi_callback_info info); static napi_value Lock(napi_env env, napi_callback_info info); static napi_value TryLock(napi_env env, napi_callback_info info); static napi_value UnLock(napi_env env, napi_callback_info info); - static napi_value GetParent(napi_env env, napi_callback_info info); #endif static napi_value Constructor(napi_env env, napi_callback_info info); static napi_value GetFD(napi_env env, napi_callback_info info);