From e9309b9ef863bf51b08f8a7946764dd578a63470 Mon Sep 17 00:00:00 2001 From: liyuke Date: Tue, 15 Apr 2025 20:53:20 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E8=A7=84=E8=8C=83=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: liyuke --- interfaces/kits/js/src/mod_fs/properties/ani/mkdir_ani.cpp | 2 ++ .../kits/js/src/mod_fs/properties/ani/movedir_ani.cpp | 3 ++- .../kits/js/src/mod_fs/properties/ani/read_lines_ani.cpp | 5 ++++- .../kits/js/src/mod_fs/properties/ani/unlink_ani.cpp | 2 +- interfaces/kits/js/src/mod_fs/properties/ani/xattr_ani.cpp | 6 +++--- .../kits/js/src/mod_fs/properties/fdatasync_core.cpp | 1 - interfaces/kits/js/src/mod_fs/properties/fdatasync_core.h | 1 - interfaces/kits/js/src/mod_fs/properties/mkdir_core.h | 2 +- interfaces/kits/js/src/mod_fs/properties/mkdtemp_core.h | 2 +- .../kits/js/src/mod_fs/properties/read_lines_core.cpp | 6 +----- interfaces/kits/js/src/mod_fs/properties/unlink_core.cpp | 7 +++---- interfaces/kits/js/src/mod_fs/properties/unlink_core.h | 2 +- 12 files changed, 19 insertions(+), 20 deletions(-) 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 a5cd88374..737b53f47 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 @@ -33,6 +33,7 @@ void MkdirkAni::MkdirSync0(ani_env *env, [[maybe_unused]] ani_class clazz, ani_s ErrorHandler::Throw(env, EINVAL); return; } + auto ret = MkdirCore::DoMkdir(pathStr); if (!ret.IsSuccess()) { HILOGE("Mkdir failed"); @@ -50,6 +51,7 @@ void MkdirkAni::MkdirSync1(ani_env *env, [[maybe_unused]] ani_class clazz, ani_s ErrorHandler::Throw(env, EINVAL); return; } + auto ret = MkdirCore::DoMkdir(pathStr, recursion); if (!ret.IsSuccess()) { HILOGE("DoMkdir failed"); diff --git a/interfaces/kits/js/src/mod_fs/properties/ani/movedir_ani.cpp b/interfaces/kits/js/src/mod_fs/properties/ani/movedir_ani.cpp index e1239cfca..62281a917 100644 --- a/interfaces/kits/js/src/mod_fs/properties/ani/movedir_ani.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/ani/movedir_ani.cpp @@ -121,7 +121,7 @@ void MoveDirAni::MoveDirSync( auto [succMode, optMode] = TypeConverter::ToOptionalInt32(env, mode); if (!succMode) { - HILOGE("Failed to convert mode to int32"); + HILOGE("Invalid mode"); ErrorHandler::Throw(env, EINVAL); return; } @@ -140,6 +140,7 @@ void MoveDirAni::MoveDirSync( return; } } + } // namespace ANI } // namespace ModuleFileIO } // namespace FileManagement diff --git a/interfaces/kits/js/src/mod_fs/properties/ani/read_lines_ani.cpp b/interfaces/kits/js/src/mod_fs/properties/ani/read_lines_ani.cpp index 49b26f784..10c3ce394 100644 --- a/interfaces/kits/js/src/mod_fs/properties/ani/read_lines_ani.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/ani/read_lines_ani.cpp @@ -53,7 +53,7 @@ ani_object ReadLinesAni::ReadLinesSync( { auto [succPath, filePath] = TypeConverter::ToUTF8String(env, path); if (!succPath) { - HILOGE("Invalid path"); + HILOGE("Invalid path from ETS first argument"); ErrorHandler::Throw(env, EINVAL); return nullptr; } @@ -64,6 +64,7 @@ ani_object ReadLinesAni::ReadLinesSync( ErrorHandler::Throw(env, EINVAL); return nullptr; } + FsResult ret = ReadLinesCore::DoReadLines(filePath, opt); if (!ret.IsSuccess()) { HILOGE("Readlines failed"); @@ -71,6 +72,7 @@ ani_object ReadLinesAni::ReadLinesSync( ErrorHandler::Throw(env, err); return nullptr; } + const FsReaderIterator *readerIterator = ret.GetData().value(); auto result = ReaderIteratorAni::Wrap(env, move(readerIterator)); if (result == nullptr) { @@ -79,6 +81,7 @@ ani_object ReadLinesAni::ReadLinesSync( } return result; } + } // namespace ANI } // namespace ModuleFileIO } // namespace FileManagement 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 91a929d13..763d6e72e 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 @@ -29,7 +29,7 @@ void UnlinkAni::UnlinkSync(ani_env *env, [[maybe_unused]] ani_class clazz, ani_s { auto [succ, pathStr] = TypeConverter::ToUTF8String(env, path); if (!succ) { - HILOGE("Invalid path"); + HILOGE("Invalid path from ETS first argument"); ErrorHandler::Throw(env, EINVAL); return; } diff --git a/interfaces/kits/js/src/mod_fs/properties/ani/xattr_ani.cpp b/interfaces/kits/js/src/mod_fs/properties/ani/xattr_ani.cpp index 47e6d92a5..2a69e0bd2 100644 --- a/interfaces/kits/js/src/mod_fs/properties/ani/xattr_ani.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/ani/xattr_ani.cpp @@ -37,14 +37,14 @@ void XattrAni::SetXattrSync( auto [keySucc, keyStr] = TypeConverter::ToUTF8String(env, key); if (!keySucc) { - HILOGE("Invalid key"); + HILOGE("Invalid xattr key"); ErrorHandler::Throw(env, EINVAL); return; } auto [valueSucc, valueStr] = TypeConverter::ToUTF8String(env, value); if (!valueSucc) { - HILOGE("Invalid value"); + HILOGE("Invalid xattr value"); ErrorHandler::Throw(env, EINVAL); return; } @@ -69,7 +69,7 @@ ani_string XattrAni::GetXattrSync(ani_env *env, [[maybe_unused]] ani_class clazz auto [keySucc, keyStr] = TypeConverter::ToUTF8String(env, key); if (!keySucc) { - HILOGE("Invalid key"); + HILOGE("Invalid xattr key"); ErrorHandler::Throw(env, EINVAL); return nullptr; } diff --git a/interfaces/kits/js/src/mod_fs/properties/fdatasync_core.cpp b/interfaces/kits/js/src/mod_fs/properties/fdatasync_core.cpp index 57b479f2b..38996fda0 100644 --- a/interfaces/kits/js/src/mod_fs/properties/fdatasync_core.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/fdatasync_core.cpp @@ -24,7 +24,6 @@ #include "filemgmt_libhilog.h" namespace OHOS::FileManagement::ModuleFileIO { -using namespace std; FsResult FDataSyncCore::DoFDataSync(const int32_t &fd) { diff --git a/interfaces/kits/js/src/mod_fs/properties/fdatasync_core.h b/interfaces/kits/js/src/mod_fs/properties/fdatasync_core.h index 8efb6f907..7f568834b 100644 --- a/interfaces/kits/js/src/mod_fs/properties/fdatasync_core.h +++ b/interfaces/kits/js/src/mod_fs/properties/fdatasync_core.h @@ -24,6 +24,5 @@ class FDataSyncCore final { public: static FsResult DoFDataSync(const int32_t &fd); }; -const std::string PROCEDURE_FDATASYNC_NAME = "FileIOFdatasync"; } // namespace OHOS::FileManagement::ModuleFileIO #endif // INTERFACES_KITS_JS_SRC_MOD_FS_PROPERTIES_FDATASYNC_CORE_H \ No newline at end of file diff --git a/interfaces/kits/js/src/mod_fs/properties/mkdir_core.h b/interfaces/kits/js/src/mod_fs/properties/mkdir_core.h index cc6793693..46bc81a70 100644 --- a/interfaces/kits/js/src/mod_fs/properties/mkdir_core.h +++ b/interfaces/kits/js/src/mod_fs/properties/mkdir_core.h @@ -28,7 +28,7 @@ public: static FsResult DoMkdir(const std::string& path, std::optional recursion = std::nullopt); }; constexpr int DIR_DEFAULT_PERM = 0770; -const std::string PROCEDURE_READTEXT_NAME = "FileIOMkdir"; + } // namespace ModuleFileIO } // namespace FileManagement } // namespace OHOS diff --git a/interfaces/kits/js/src/mod_fs/properties/mkdtemp_core.h b/interfaces/kits/js/src/mod_fs/properties/mkdtemp_core.h index e638655ba..df936597f 100644 --- a/interfaces/kits/js/src/mod_fs/properties/mkdtemp_core.h +++ b/interfaces/kits/js/src/mod_fs/properties/mkdtemp_core.h @@ -27,7 +27,7 @@ class MkdtempCore final { public: static FsResult DoMkdtemp(const std::string &path); }; -const std::string PROCEDURE_MKDTEMP_NAME = "FileIOMkdtemp"; + } // namespace ModuleFileIO } // namespace FileManagement } // namespace OHOS diff --git a/interfaces/kits/js/src/mod_fs/properties/read_lines_core.cpp b/interfaces/kits/js/src/mod_fs/properties/read_lines_core.cpp index 819215c30..def348544 100644 --- a/interfaces/kits/js/src/mod_fs/properties/read_lines_core.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/read_lines_core.cpp @@ -98,11 +98,7 @@ FsResult ReadLinesCore::DoReadLines(const string &path, opti HILOGE("Failed to get size of the file"); return FsResult::Error(ret); } - auto readeriterator = InstantiateReaderIterator(iterator, offset); - if (!readeriterator.IsSuccess()) { - return FsResult::Error(ENOMEM); - } - return FsResult::Success(readeriterator.GetData().value()); + return InstantiateReaderIterator(iterator, offset); } } // namespace ModuleFileIO diff --git a/interfaces/kits/js/src/mod_fs/properties/unlink_core.cpp b/interfaces/kits/js/src/mod_fs/properties/unlink_core.cpp index ecb92452e..42e87cd0b 100644 --- a/interfaces/kits/js/src/mod_fs/properties/unlink_core.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/unlink_core.cpp @@ -24,17 +24,16 @@ namespace OHOS { namespace FileManagement { namespace ModuleFileIO { -using namespace std; FsResult UnlinkCore::DoUnlink(const std::string &src) { - std::unique_ptr unlink_req = { + std::unique_ptr unlinkReq = { new uv_fs_t, FsUtils::FsReqCleanup }; - if (!unlink_req) { + if (!unlinkReq) { HILOGE("Failed to request heap memory."); return FsResult::Error(ENOMEM); } - int ret = uv_fs_unlink(nullptr, unlink_req.get(), src.c_str(), nullptr); + int ret = uv_fs_unlink(nullptr, unlinkReq.get(), src.c_str(), nullptr); if (ret < 0) { HILOGD("Failed to unlink with path"); return FsResult::Error(ret); diff --git a/interfaces/kits/js/src/mod_fs/properties/unlink_core.h b/interfaces/kits/js/src/mod_fs/properties/unlink_core.h index b2ea553f4..5989bbda2 100755 --- a/interfaces/kits/js/src/mod_fs/properties/unlink_core.h +++ b/interfaces/kits/js/src/mod_fs/properties/unlink_core.h @@ -27,7 +27,7 @@ class UnlinkCore final { public: static FsResult DoUnlink(const std::string &src); }; -const std::string PROCEDURE_READTEXT_NAME = "FileIOUnlink"; + } // namespace ModuleFileIO } // namespace FileManagement } // namespace OHOS -- Gitee From 143c91e485a4612b7a209986c9e4a58cc739037e Mon Sep 17 00:00:00 2001 From: liyuke Date: Thu, 17 Apr 2025 11:33:07 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E8=A7=84=E8=8C=83=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: liyuke --- interfaces/kits/js/src/mod_fs/properties/movedir_core.h | 1 - interfaces/kits/js/src/mod_fs/properties/read_lines_core.h | 1 - 2 files changed, 2 deletions(-) diff --git a/interfaces/kits/js/src/mod_fs/properties/movedir_core.h b/interfaces/kits/js/src/mod_fs/properties/movedir_core.h index e4db3553d..f10eaa532 100755 --- a/interfaces/kits/js/src/mod_fs/properties/movedir_core.h +++ b/interfaces/kits/js/src/mod_fs/properties/movedir_core.h @@ -58,7 +58,6 @@ public: const std::string &src, const std::string &dest, std::optional mode = std::nullopt); }; -const std::string PROCEDURE_MOVEDIR_NAME = "FileIOMoveDir"; } // namespace ModuleFileIO } // namespace FileManagement } // namespace OHOS diff --git a/interfaces/kits/js/src/mod_fs/properties/read_lines_core.h b/interfaces/kits/js/src/mod_fs/properties/read_lines_core.h index a450cc431..67cae2c52 100644 --- a/interfaces/kits/js/src/mod_fs/properties/read_lines_core.h +++ b/interfaces/kits/js/src/mod_fs/properties/read_lines_core.h @@ -37,7 +37,6 @@ public: const std::string &path, std::optional option = std::nullopt); }; -const std::string PROCEDURE_READLINES_NAME = "FileIOReadLines"; } // namespace ModuleFileIO } // namespace FileManagement } // namespace OHOS -- Gitee From b9578436c4609a5ffb8077806c09488873d99d2d Mon Sep 17 00:00:00 2001 From: liyuke Date: Mon, 12 May 2025 19:53:57 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E8=A7=84=E8=8C=83=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: liyuke --- interfaces/kits/js/src/mod_fs/properties/ani/mkdir_ani.h | 6 +++--- .../kits/js/src/mod_fs/properties/ani/read_lines_ani.h | 6 +++--- interfaces/kits/js/src/mod_fs/properties/ani/unlink_ani.h | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/interfaces/kits/js/src/mod_fs/properties/ani/mkdir_ani.h b/interfaces/kits/js/src/mod_fs/properties/ani/mkdir_ani.h index 8ed780e96..195d0db00 100644 --- a/interfaces/kits/js/src/mod_fs/properties/ani/mkdir_ani.h +++ b/interfaces/kits/js/src/mod_fs/properties/ani/mkdir_ani.h @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef INTERFACES_KITS_JS_SRC_MOD_FS_MKDIR_ANI_H -#define INTERFACES_KITS_JS_SRC_MOD_FS_MKDIR_ANI_H +#ifndef INTERFACES_KITS_JS_SRC_MOD_FS_PROPERTIES_ANI_MKDIR_ANI_H +#define INTERFACES_KITS_JS_SRC_MOD_FS_PROPERTIES_ANI_MKDIR_ANI_H #include @@ -34,4 +34,4 @@ public: } // namespace FileManagement } // namespace OHOS -#endif // INTERFACES_KITS_JS_SRC_MOD_FS_MKDIR_ANI_H +#endif // INTERFACES_KITS_JS_SRC_MOD_FS_PROPERTIES_ANI_MKDIR_ANI_H diff --git a/interfaces/kits/js/src/mod_fs/properties/ani/read_lines_ani.h b/interfaces/kits/js/src/mod_fs/properties/ani/read_lines_ani.h index 387298f81..3f1bfeb72 100644 --- a/interfaces/kits/js/src/mod_fs/properties/ani/read_lines_ani.h +++ b/interfaces/kits/js/src/mod_fs/properties/ani/read_lines_ani.h @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef INTERFACES_KITS_JS_SRC_MOD_FS_READ_LINES_ANI_H -#define INTERFACES_KITS_JS_SRC_MOD_FS_READ_LINES_ANI_H +#ifndef INTERFACES_KITS_JS_SRC_MOD_FS_PROPERTIES_ANI_READ_LINES_ANI_H +#define INTERFACES_KITS_JS_SRC_MOD_FS_PROPERTIES_ANI_READ_LINES_ANI_H #include @@ -33,4 +33,4 @@ public: } // namespace FileManagement } // namespace OHOS -#endif // INTERFACES_KITS_JS_SRC_MOD_FS_READ_LINES_ANI_H \ No newline at end of file +#endif // INTERFACES_KITS_JS_SRC_MOD_FS_PROPERTIES_ANI_READ_LINES_ANI_H \ No newline at end of file diff --git a/interfaces/kits/js/src/mod_fs/properties/ani/unlink_ani.h b/interfaces/kits/js/src/mod_fs/properties/ani/unlink_ani.h index 817b25800..64aee8bd1 100644 --- a/interfaces/kits/js/src/mod_fs/properties/ani/unlink_ani.h +++ b/interfaces/kits/js/src/mod_fs/properties/ani/unlink_ani.h @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef INTERFACES_KITS_JS_SRC_MOD_FS_UNLINK_ANI_H -#define INTERFACES_KITS_JS_SRC_MOD_FS_UNLINK_ANI_H +#ifndef INTERFACES_KITS_JS_SRC_MOD_FS_PROPERTIES_ANI_UNLINK_ANI_H +#define INTERFACES_KITS_JS_SRC_MOD_FS_PROPERTIES_ANI_UNLINK_ANI_H #include @@ -33,4 +33,4 @@ public: } // namespace FileManagement } // namespace OHOS -#endif // INTERFACES_KITS_JS_SRC_MOD_FS_UNLINK_ANI_H \ No newline at end of file +#endif // INTERFACES_KITS_JS_SRC_MOD_FS_PROPERTIES_ANI_UNLINK_ANI_H \ No newline at end of file -- Gitee