From 3641d01cf53f05fe911e53204d60ba0988e22718 Mon Sep 17 00:00:00 2001 From: tianp Date: Sat, 26 Jul 2025 11:29:27 +0800 Subject: [PATCH 1/2] =?UTF-8?q?lstat=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: tianp Change-Id: I6dad5d2fd3f3ec9509cd53bac421c7415bc5d447 --- .../js/src/common/ani_helper/ani_helper.h | 8 +- .../src/common/ani_helper/ani_signature.cpp | 17 +++ .../js/src/common/ani_helper/ani_signature.h | 30 +++++ .../src/common/ani_helper/type_converter.cpp | 22 ++-- interfaces/kits/js/src/common/fs_filefiter.h | 117 ++++++++++++++++++ .../src/mod_fs/class_stat/ani/lstat_ani.cpp | 66 ++++++++++ .../js/src/mod_fs/class_stat/ani/lstat_ani.h | 33 +++++ .../mod_fs/class_stat/ani/stat_wrapper.cpp | 9 +- .../src/mod_fs/properties/ani/close_ani.cpp | 2 +- .../src/mod_fs/properties/ani/rename_ani.cpp | 54 ++++++++ .../js/src/mod_fs/properties/ani/rename_ani.h | 35 ++++++ .../js/src/mod_fs/properties/lstat_core.cpp | 68 ++++++++++ .../js/src/mod_fs/properties/lstat_core.h | 30 +++++ .../js/src/mod_fs/properties/rename_core.cpp | 46 +++++++ .../js/src/mod_fs/properties/rename_core.h | 35 ++++++ .../js/mod_fs/properties/close_core_test.cpp | 61 ++++++++- .../properties/lstat_core_mock_test.cpp | 79 ++++++++++++ .../js/mod_fs/properties/lstat_core_test.cpp | 94 ++++++++++++++ .../properties/rename_core_mock_test.cpp | 102 +++++++++++++++ 19 files changed, 883 insertions(+), 25 deletions(-) create mode 100644 interfaces/kits/js/src/common/fs_filefiter.h create mode 100644 interfaces/kits/js/src/mod_fs/class_stat/ani/lstat_ani.cpp create mode 100644 interfaces/kits/js/src/mod_fs/class_stat/ani/lstat_ani.h create mode 100644 interfaces/kits/js/src/mod_fs/properties/ani/rename_ani.cpp create mode 100644 interfaces/kits/js/src/mod_fs/properties/ani/rename_ani.h create mode 100644 interfaces/kits/js/src/mod_fs/properties/lstat_core.cpp create mode 100644 interfaces/kits/js/src/mod_fs/properties/lstat_core.h create mode 100644 interfaces/kits/js/src/mod_fs/properties/rename_core.cpp create mode 100644 interfaces/kits/js/src/mod_fs/properties/rename_core.h create mode 100644 interfaces/test/unittest/js/mod_fs/properties/lstat_core_mock_test.cpp create mode 100644 interfaces/test/unittest/js/mod_fs/properties/lstat_core_test.cpp create mode 100644 interfaces/test/unittest/js/mod_fs/properties/rename_core_mock_test.cpp diff --git a/interfaces/kits/js/src/common/ani_helper/ani_helper.h b/interfaces/kits/js/src/common/ani_helper/ani_helper.h index f19c8f041..49a1d22f7 100644 --- a/interfaces/kits/js/src/common/ani_helper/ani_helper.h +++ b/interfaces/kits/js/src/common/ani_helper/ani_helper.h @@ -33,10 +33,7 @@ namespace OHOS::FileManagement::ModuleFileIO::ANI { using namespace std; using namespace OHOS::FileManagement::ModuleFileIO::ANI::AniSignature; -inline shared_ptr& GetMainHandler() { - thread_local shared_ptr mainHandler; - return mainHandler; -} +static thread_local shared_ptr mainHandler; class AniHelper { public: @@ -116,7 +113,7 @@ public: static const string longValueSig = Builder::BuildSignatureDescriptor({}, BasicTypes::longType); ani_long value; status = env->Object_CallMethodByName_Long( - static_cast(property), "longValue", longValueSig.c_str(), &value); + static_cast(property), "toLong", longValueSig.c_str(), &value); if (status != ANI_OK) { return { false, nullopt }; } @@ -186,7 +183,6 @@ public: return false; } - auto& mainHandler = GetMainHandler(); if (mainHandler == nullptr) { shared_ptr runner = OHOS::AppExecFwk::EventRunner::GetMainEventRunner(); if (!runner) { diff --git a/interfaces/kits/js/src/common/ani_helper/ani_signature.cpp b/interfaces/kits/js/src/common/ani_helper/ani_signature.cpp index 4a683a783..f8a2a92de 100644 --- a/interfaces/kits/js/src/common/ani_helper/ani_signature.cpp +++ b/interfaces/kits/js/src/common/ani_helper/ani_signature.cpp @@ -60,6 +60,7 @@ const string BuiltInTypes::Array::objectSetterSig = // BuiltInTypes::ArrayBuffer const Type BuiltInTypes::ArrayBuffer::classType = Builder::BuildClass("escompat.ArrayBuffer"); const string BuiltInTypes::ArrayBuffer::classDesc = BuiltInTypes::ArrayBuffer::classType.Descriptor(); +const string BuiltInTypes::ArrayBuffer::ctorSig = Builder::BuildSignatureDescriptor({ BasicTypes::intType }); // BuiltInTypes::BigInt const Type BuiltInTypes::BigInt::classType = Builder::BuildClass("escompat.BigInt"); const string BuiltInTypes::BigInt::classDesc = BuiltInTypes::BigInt::classType.Descriptor(); @@ -115,6 +116,18 @@ const Type FS::WatchEventInner::classType = Builder::BuildClass("@ohos.file.fs.W const string FS::WatchEventInner::classDesc = FS::WatchEventInner::classType.Descriptor(); const string FS::WatchEventInner::ctorSig = Builder::BuildSignatureDescriptor({ BuiltInTypes::stringType, BasicTypes::doubleType, BasicTypes::doubleType }); +// FS::ReadStream +const Type FS::ReadStream::classType = Builder::BuildClass("@ohos.file.fs.fileIo.ReadStream"); +const string FS::ReadStream::classDesc = FS::ReadStream::classType.Descriptor(); +const string FS::ReadStream::ctorSig = Builder::BuildSignatureDescriptor({ BuiltInTypes::stringType }); +// FS::WriteStream +const Type FS::WriteStream::classType = Builder::BuildClass("@ohos.file.fs.fileIo.WriteStream"); +const string FS::WriteStream::classDesc = FS::WriteStream::classType.Descriptor(); +const string FS::WriteStream::ctorSig = Builder::BuildSignatureDescriptor({ BuiltInTypes::stringType }); +// FS::AtomicFile +const Type FS::AtomicFile::classType = Builder::BuildClass("@ohos.file.fs.fileIo.AtomicFile"); +const string FS::AtomicFile::classDesc = FS::AtomicFile::classType.Descriptor(); +const string FS::AtomicFile::ctorSig = Builder::BuildSignatureDescriptor({ BuiltInTypes::stringType }); // FS::LocationType const Type FS::LocationType::classType = Builder::BuildClass("@ohos.file.fs.fileIo.LocationType"); const string FS::LocationType::classDesc = FS::LocationType::classType.Descriptor(); @@ -133,5 +146,9 @@ const string Impl::SecurityLabelImpl::classDesc = Impl::SecurityLabelImpl::class // Impl::StatvfsImpl const Type Impl::StatvfsImpl::classType = Builder::BuildClass("@ohos.file.statvfs.StatvfsImpl"); const string Impl::StatvfsImpl::classDesc = Impl::StatvfsImpl::classType.Descriptor(); +// HASH::HashStreamImpl +const Type HASH::HashStreamImpl::classType = Builder::BuildClass("@ohos.file.hash.HashStreamImpl"); +const string HASH::HashStreamImpl::classDesc = HASH::HashStreamImpl::classType.Descriptor(); +const string HASH::HashStreamImpl::ctorSig = Builder::BuildSignatureDescriptor({ BuiltInTypes::stringType }); } // namespace OHOS::FileManagement::ModuleFileIO::ANI::AniSignature \ No newline at end of file diff --git a/interfaces/kits/js/src/common/ani_helper/ani_signature.h b/interfaces/kits/js/src/common/ani_helper/ani_signature.h index 8b7e43281..3dd55d2c2 100644 --- a/interfaces/kits/js/src/common/ani_helper/ani_signature.h +++ b/interfaces/kits/js/src/common/ani_helper/ani_signature.h @@ -41,6 +41,7 @@ struct BasicTypes { struct BaseType { static const string ctorDesc; static const string ctorSig0; + static const string ctorSig; }; namespace BoxedTypes { @@ -93,6 +94,7 @@ struct Array : public BaseType { struct ArrayBuffer : public BaseType { static const Type classType; static const string classDesc; + static const string ctorSig; }; struct BigInt : public BaseType { @@ -181,6 +183,24 @@ struct LocationType : public BaseType { static const string classDesc; }; +struct ReadStream : public BaseType { + static const Type classType; + static const string classDesc; + static const string ctorSig; +}; + +struct WriteStream : public BaseType { + static const Type classType; + static const string classDesc; + static const string ctorSig; +}; + +struct AtomicFile : public BaseType { + static const Type classType; + static const string classDesc; + static const string ctorSig; +}; + } // namespace FS namespace Impl { @@ -212,6 +232,16 @@ struct StatvfsImpl : public BaseType { } // namespace Impl +namespace HASH { + +struct HashStreamImpl : public BaseType { + static const Type classType; + static const string classDesc; + static const string ctorSig; +}; + +} // namespace HASH + } // namespace OHOS::FileManagement::ModuleFileIO::ANI::AniSignature #endif // INTERFACES_KITS_JS_SRC_COMMON_ANI_HELPER_ANI_SIGNATURE_H \ No newline at end of file diff --git a/interfaces/kits/js/src/common/ani_helper/type_converter.cpp b/interfaces/kits/js/src/common/ani_helper/type_converter.cpp index d794b727d..ba640a84c 100644 --- a/interfaces/kits/js/src/common/ani_helper/type_converter.cpp +++ b/interfaces/kits/js/src/common/ani_helper/type_converter.cpp @@ -59,7 +59,7 @@ std::tuple> TypeConverter::ToOptionalInt32(ani_env } ani_int intValue; - if (ANI_OK == env->Object_CallMethodByName_Int(value, "intValue", nullptr, &intValue)) { + if (ANI_OK == env->Object_CallMethodByName_Int(value, "toInt", nullptr, &intValue)) { return { true, std::make_optional(intValue) }; } @@ -79,7 +79,7 @@ std::tuple> TypeConverter::ToOptionalInt64(ani_env } ani_long longValue; - if (ANI_OK == env->Object_CallMethodByName_Long(value, "longValue", nullptr, &longValue)) { + if (ANI_OK == env->Object_CallMethodByName_Long(value, "toLong", nullptr, &longValue)) { return { true, std::make_optional(longValue) }; } @@ -114,7 +114,7 @@ std::tuple TypeConverter::ToAniString(ani_env *env, std::strin std::tuple TypeConverter::ToAniString(ani_env *env, const char *str) { - if (env == nullptr || str == nullptr) { + if (env == nullptr) { return { false, {} }; } @@ -152,7 +152,7 @@ static std::tuple ParseFd(ani_env *env, const ani_object &pathOrF env->Object_InstanceOf(pathOrFd, cls, &isFd); if (isFd) { ani_int fd; - if (ANI_OK != env->Object_CallMethodByName_Int(pathOrFd, "intValue", nullptr, &fd)) { + if (ANI_OK != env->Object_CallMethodByName_Int(pathOrFd, "toInt", nullptr, &fd)) { HILOGE("Parse file path failed"); return { false, 0 }; } @@ -225,23 +225,25 @@ std::tuple TypeConverter::ToAniArrayBuffer(ani_env *env, return { false, nullptr }; } - static const char *className = "Lescompat/ArrayBuffer;"; + auto classDesc = BuiltInTypes::ArrayBuffer::classDesc.c_str(); ani_status ret; ani_class cls; - if ((ret = env->FindClass(className, &cls)) != ANI_OK) { - HILOGE("Not found %{private}s, err: %{public}d", className, ret); + if ((ret = env->FindClass(classDesc, &cls)) != ANI_OK) { + HILOGE("Not found %{private}s, err: %{private}d", classDesc, ret); return { false, nullptr }; } + auto ctorDesc = BuiltInTypes::ArrayBuffer::ctorDesc.c_str(); + auto ctorSig = BuiltInTypes::ArrayBuffer::ctorSig.c_str(); ani_method ctor; - if ((ret = env->Class_FindMethod(cls, "", "I:V", &ctor)) != ANI_OK) { - HILOGE("Not found ctor, err: %{public}d", ret); + if ((ret = env->Class_FindMethod(cls, ctorDesc, ctorSig, &ctor)) != ANI_OK) { + HILOGE("Not found ctor, err: %{private}d", ret); return { false, nullptr }; } ani_object obj; if ((ret = env->Object_New(cls, ctor, &obj, length)) != ANI_OK) { - HILOGE("New Uint8Array err: %{public}d", ret); + HILOGE("New Uint8Array err: %{private}d", ret); return { false, nullptr }; } diff --git a/interfaces/kits/js/src/common/fs_filefiter.h b/interfaces/kits/js/src/common/fs_filefiter.h new file mode 100644 index 000000000..f16c17821 --- /dev/null +++ b/interfaces/kits/js/src/common/fs_filefiter.h @@ -0,0 +1,117 @@ +/* + * 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. + */ +#ifndef FS_FILE_FILTER_H +#define FS_FILE_FILTER_H + +#include +#include +#include + +namespace OHOS { +namespace FileManagement { +namespace ModuleFileIO { + +class FsFileFilter { +public: + FsFileFilter() = default; + ~FsFileFilter() = default; + + FsFileFilter(const FsFileFilter &filter) = default; + FsFileFilter &operator=(const FsFileFilter &filter) = default; + + void SetSuffix(const std::optional> &suffix) + { + suffix_ = std::move(suffix); + } + + const std::optional> &GetSuffix() const + { + return suffix_; + } + + void SetDisplayName(const std::optional> &displayName) + { + displayName_ = std::move(displayName); + } + + const std::optional> &GetDisplayName() const + { + return displayName_; + } + + void SetMimeType(const std::optional> &mimeType) + { + mimeType_ = std::move(mimeType); + } + + const std::optional> &GetMimeType() const + { + return mimeType_; + } + + void SetFileSizeOver(const std::optional &fileSizeOver) + { + fileSizeOver_ = std::move(fileSizeOver); + } + + const std::optional &GetFileSizeOver() const + { + return fileSizeOver_; + } + + void SetLastModifiedAfter(const std::optional &lastModifiedAfter) + { + lastModifiedAfter_ = std::move(lastModifiedAfter); + } + + const std::optional &GetLastModifiedAfter() const + { + return lastModifiedAfter_; + } + + void SetExcludeMedia(const bool &excludeMedia) + { + excludeMedia_ = excludeMedia; + } + + bool GetExcludeMedia() const + { + return excludeMedia_; + } + + void SetHasFilter(const bool &hasFilter) + { + hasFilter_ = hasFilter; + } + + bool GetHasFilter() const + { + return hasFilter_; + } + +private: + std::optional> suffix_ = std::nullopt; + std::optional> displayName_ = std::nullopt; + std::optional> mimeType_ = std::nullopt; + std::optional fileSizeOver_ = std::nullopt; + std::optional lastModifiedAfter_ = std::nullopt; + bool excludeMedia_ = false; + bool hasFilter_ = false; +}; + +} // namespace ModuleFileIO +} // namespace FileManagement +} // namespace OHOS +#endif // FS_FILE_FILTER_H \ No newline at end of file diff --git a/interfaces/kits/js/src/mod_fs/class_stat/ani/lstat_ani.cpp b/interfaces/kits/js/src/mod_fs/class_stat/ani/lstat_ani.cpp new file mode 100644 index 000000000..deb3052c5 --- /dev/null +++ b/interfaces/kits/js/src/mod_fs/class_stat/ani/lstat_ani.cpp @@ -0,0 +1,66 @@ +/* + * 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 "lstat_ani.h" + +#include +#include + +#include "error_handler.h" +#include "filemgmt_libhilog.h" +#include "lstat_core.h" +#include "stat_wrapper.h" +#include "type_converter.h" + +namespace OHOS { +namespace FileManagement { +namespace ModuleFileIO { +namespace ANI { +using namespace std; +using namespace OHOS::FileManagement::ModuleFileIO; + +ani_object LstatAni::LstatSync(ani_env *env, [[maybe_unused]] ani_class clazz, ani_string path) +{ + auto [succPath, filePath] = TypeConverter::ToUTF8String(env, path); + if (!succPath) { + HILOGE("The first argument requires filepath"); + ErrorHandler::Throw(env, EINVAL); + return {}; + } + + auto ret = LstatCore::DoLstat(filePath); + if (!ret.IsSuccess()) { + HILOGE("DoStat failed!"); + const FsError &err = ret.GetError(); + ErrorHandler::Throw(env, err); + return {}; + } + + auto fsStat = ret.GetData().value(); + auto statObject = StatWrapper::Wrap(env, fsStat); + if (statObject == nullptr) { + delete fsStat; + fsStat = nullptr; + HILOGE("Wrap stat object failed!"); + ErrorHandler::Throw(env, UNKNOWN_ERR); + return {}; + } + + return statObject; +} +} // namespace ANI +} // namespace ModuleFileIO +} // namespace FileManagement +} // namespace OHOS \ No newline at end of file diff --git a/interfaces/kits/js/src/mod_fs/class_stat/ani/lstat_ani.h b/interfaces/kits/js/src/mod_fs/class_stat/ani/lstat_ani.h new file mode 100644 index 000000000..140d92807 --- /dev/null +++ b/interfaces/kits/js/src/mod_fs/class_stat/ani/lstat_ani.h @@ -0,0 +1,33 @@ +/* + * 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. + */ + +#ifndef INTERFACES_KITS_JS_SRC_MOD_FS_PROPERTIES_ANI_LSTAT_ANI_H +#define INTERFACES_KITS_JS_SRC_MOD_FS_PROPERTIES_ANI_LSTAT_ANI_H + +#include + +namespace OHOS { +namespace FileManagement { +namespace ModuleFileIO { +namespace ANI { +class LstatAni final { +public: + static ani_object LstatSync(ani_env *env, [[maybe_unused]] ani_class clazz, ani_string path); +}; +} // namespace ANI +} // namespace ModuleFileIO +} // namespace FileManagement +} // namespace OHOS +#endif // INTERFACES_KITS_JS_SRC_MOD_FS_PROPERTIES_ANI_LSTAT_ANI_H \ No newline at end of file diff --git a/interfaces/kits/js/src/mod_fs/class_stat/ani/stat_wrapper.cpp b/interfaces/kits/js/src/mod_fs/class_stat/ani/stat_wrapper.cpp index 0bb2e6653..0f460e507 100644 --- a/interfaces/kits/js/src/mod_fs/class_stat/ani/stat_wrapper.cpp +++ b/interfaces/kits/js/src/mod_fs/class_stat/ani/stat_wrapper.cpp @@ -185,15 +185,14 @@ static ani_status SetProperties(ani_env *env, const ani_class &cls, ani_object & ani_object StatWrapper::Wrap(ani_env *env, FsStat *fsStat) { - auto classDesc = FS::StatInner::classDesc.c_str(); - ani_object statObject = {}; - ani_class cls; - ani_status ret; - if (fsStat == nullptr) { HILOGE("FsStat pointer is null!"); return nullptr; } + auto classDesc = FS::StatInner::classDesc.c_str(); + ani_object statObject = {}; + ani_class cls; + ani_status ret; if ((ret = env->FindClass(classDesc, &cls)) != ANI_OK) { HILOGE("Not found %{private}s, err: %{private}d", classDesc, ret); diff --git a/interfaces/kits/js/src/mod_fs/properties/ani/close_ani.cpp b/interfaces/kits/js/src/mod_fs/properties/ani/close_ani.cpp index ed652a742..6bdd170fb 100644 --- a/interfaces/kits/js/src/mod_fs/properties/ani/close_ani.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/ani/close_ani.cpp @@ -44,7 +44,7 @@ tuple ParseFdOrFile(ani_env *env, ani_object obj) if (isDouble) { ani_int fd; - if (ANI_OK != env->Object_CallMethodByName_Int(obj, "intValue", nullptr, &fd)) { + if (ANI_OK != env->Object_CallMethodByName_Int(obj, "toInt", nullptr, &fd)) { HILOGE("Get fd value failed"); return { false, result, nullptr }; } diff --git a/interfaces/kits/js/src/mod_fs/properties/ani/rename_ani.cpp b/interfaces/kits/js/src/mod_fs/properties/ani/rename_ani.cpp new file mode 100644 index 000000000..0b4d762a0 --- /dev/null +++ b/interfaces/kits/js/src/mod_fs/properties/ani/rename_ani.cpp @@ -0,0 +1,54 @@ +/* + * 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 "rename_ani.h" + +#include "error_handler.h" +#include "filemgmt_libhilog.h" +#include "rename_core.h" +#include "type_converter.h" + +namespace OHOS { +namespace FileManagement { +namespace ModuleFileIO { +namespace ANI { +using namespace OHOS::FileManagement::ModuleFileIO; + +void RenameAni::RenameSync(ani_env *env, [[maybe_unused]] ani_class clazz, ani_string oldPath, ani_string newPath) +{ + auto [succSrcPath, srcPath] = TypeConverter::ToUTF8String(env, oldPath); + if (!succSrcPath) { + HILOGE("Invalid src"); + ErrorHandler::Throw(env, EINVAL); + return; + } + auto [succDestPath, destPath] = TypeConverter::ToUTF8String(env, newPath); + if (!succDestPath) { + HILOGE("Invalid dest"); + ErrorHandler::Throw(env, EINVAL); + return; + } + auto ret = RenameCore::DoRename(srcPath, destPath); + if (!ret.IsSuccess()) { + HILOGE("DoRename failed!"); + const auto &err = ret.GetError(); + ErrorHandler::Throw(env, err); + return; + } +} +} // namespace ANI +} // namespace ModuleFileIO +} // namespace FileManagement +} // namespace OHOS \ No newline at end of file diff --git a/interfaces/kits/js/src/mod_fs/properties/ani/rename_ani.h b/interfaces/kits/js/src/mod_fs/properties/ani/rename_ani.h new file mode 100644 index 000000000..f2c39cbb0 --- /dev/null +++ b/interfaces/kits/js/src/mod_fs/properties/ani/rename_ani.h @@ -0,0 +1,35 @@ +/* + * 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. + */ + +#ifndef INTERFACES_KITS_JS_SRC_MOD_FS_PROPERTIES_ANI_RENAME_ANI_H +#define INTERFACES_KITS_JS_SRC_MOD_FS_PROPERTIES_ANI_RENAME_ANI_H + +#include + +namespace OHOS { +namespace FileManagement { +namespace ModuleFileIO { +namespace ANI { + +class RenameAni final { +public: + static void RenameSync(ani_env *env, [[maybe_unused]] ani_class clazz, ani_string oldPath, ani_string newPath); +}; +} // namespace ANI +} // namespace ModuleFileIO +} // namespace FileManagement +} // namespace OHOS + +#endif // INTERFACES_KITS_JS_SRC_MOD_FS_PROPERTIES_ANI_RENAME_ANI_H \ No newline at end of file diff --git a/interfaces/kits/js/src/mod_fs/properties/lstat_core.cpp b/interfaces/kits/js/src/mod_fs/properties/lstat_core.cpp new file mode 100644 index 000000000..cef683a91 --- /dev/null +++ b/interfaces/kits/js/src/mod_fs/properties/lstat_core.cpp @@ -0,0 +1,68 @@ +/* + * 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 "lstat_core.h" + +#include +#include + +#include + +#include "file_utils.h" +#include "filemgmt_libhilog.h" +#include "stat_instantiator.h" + +namespace OHOS::FileManagement::ModuleFileIO { +using namespace std; + +FsResult LstatCore::DoLstat(const string &path) +{ + std::unique_ptr lstat_req = { new (std::nothrow) uv_fs_t, + FsUtils::FsReqCleanup }; + if (!lstat_req) { + HILOGE("Failed to request heap memory."); + return FsResult::Error(ENOMEM); + } + int ret = uv_fs_lstat(nullptr, lstat_req.get(), path.c_str(), nullptr); + if (ret < 0) { + HILOGE("Failed to get stat of file, ret: %{public}d", ret); + return FsResult::Error(ret); + } + +#if !defined(WIN_PLATFORM) && !defined(IOS_PLATFORM) + size_t length = path.length() + 1; + auto chars = std::make_unique(length); + ret = strncpy_s(chars.get(), length, path.c_str(), length - 1); + if (ret != EOK) { + HILOGE("Copy file path failed!"); + return FsResult::Error(ret); + } + struct FileInfo info = { true, move(chars), {} }; + auto arg = CreateSharedPtr(move(info)); + if (arg == nullptr) { + HILOGE("Failed to request heap memory."); + return FsResult::Error(ENOMEM); + } + auto stat = StatInstantiator::InstantiateStat(lstat_req->statbuf, arg); +#else + auto stat = StatInstantiator::InstantiateStat(lstat_req->statbuf); +#endif + if (stat == nullptr) { + return FsResult::Error(ENOMEM); + } + return FsResult::Success(stat); +} + +} // namespace OHOS::FileManagement::ModuleFileIO \ No newline at end of file diff --git a/interfaces/kits/js/src/mod_fs/properties/lstat_core.h b/interfaces/kits/js/src/mod_fs/properties/lstat_core.h new file mode 100644 index 000000000..8f95142b8 --- /dev/null +++ b/interfaces/kits/js/src/mod_fs/properties/lstat_core.h @@ -0,0 +1,30 @@ +/* + * 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. + */ + +#ifndef INTERFACES_KITS_JS_SRC_MOD_FS_PROPERTIES_LSTAT_CORE_H +#define INTERFACES_KITS_JS_SRC_MOD_FS_PROPERTIES_LSTAT_CORE_H + +#include "filemgmt_libfs.h" +#include "fs_stat.h" +#include "fs_utils.h" + +namespace OHOS::FileManagement::ModuleFileIO { +class LstatCore final { +public: + static FsResult DoLstat(const string &path); +}; +const std::string PROCEDURE_LSTAT_NAME = "FileIOLstat"; +} // namespace OHOS::FileManagement::ModuleFileIO +#endif // INTERFACES_KITS_JS_SRC_MOD_FS_PROPERTIES_LSTAT_CORE_H \ No newline at end of file diff --git a/interfaces/kits/js/src/mod_fs/properties/rename_core.cpp b/interfaces/kits/js/src/mod_fs/properties/rename_core.cpp new file mode 100644 index 000000000..1edff30a2 --- /dev/null +++ b/interfaces/kits/js/src/mod_fs/properties/rename_core.cpp @@ -0,0 +1,46 @@ +/* + * 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 "rename_core.h" + +#include +#include +#include + +#include "filemgmt_libhilog.h" +#include "fs_utils.h" + +namespace OHOS { +namespace FileManagement { +namespace ModuleFileIO { +using namespace std; + +FsResult RenameCore::DoRename(const string &src, const string &dest) +{ + std::unique_ptr renameReq = { new uv_fs_t, FsUtils::FsReqCleanup }; + if (!renameReq) { + HILOGE("Failed to request heap memory."); + return FsResult::Error(ENOMEM); + } + int ret = uv_fs_rename(nullptr, renameReq.get(), src.c_str(), dest.c_str(), nullptr); + if (ret < 0) { + HILOGE("Failed to rename file with path"); + return FsResult::Error(ret); + } + return FsResult::Success(); +} +} // namespace ModuleFileIO +} // namespace FileManagement +} // namespace OHOS \ No newline at end of file diff --git a/interfaces/kits/js/src/mod_fs/properties/rename_core.h b/interfaces/kits/js/src/mod_fs/properties/rename_core.h new file mode 100644 index 000000000..0eded1168 --- /dev/null +++ b/interfaces/kits/js/src/mod_fs/properties/rename_core.h @@ -0,0 +1,35 @@ +/* + * 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. + */ + +#ifndef INTERFACES_KITS_JS_SRC_MOD_FS_PROPERTIES_RENAME_CORE_H +#define INTERFACES_KITS_JS_SRC_MOD_FS_PROPERTIES_RENAME_CORE_H + +#include "filemgmt_libfs.h" + +namespace OHOS { +namespace FileManagement { +namespace ModuleFileIO { +using namespace std; + +class RenameCore { +public: + static FsResult DoRename(const string &src, const string &dest); +}; + +const string PROCEDURE_RENAME_NAME = "FileIORename"; +} // namespace ModuleFileIO +} // namespace FileManagement +} // namespace OHOS +#endif // INTERFACES_KITS_JS_SRC_MOD_FS_PROPERTIES_RENAME_CORE_H \ No newline at end of file diff --git a/interfaces/test/unittest/js/mod_fs/properties/close_core_test.cpp b/interfaces/test/unittest/js/mod_fs/properties/close_core_test.cpp index 866d9cbe0..f61b20fcb 100644 --- a/interfaces/test/unittest/js/mod_fs/properties/close_core_test.cpp +++ b/interfaces/test/unittest/js/mod_fs/properties/close_core_test.cpp @@ -44,7 +44,6 @@ public: * @tc.size: MEDIUM * @tc.type: FUNC * @tc.level Level 1 -* @tc.require: AR000IGDNF */ HWTEST_F(CloseCoreTest, DoCloseTestFd_0001, testing::ext::TestSize.Level1) { @@ -59,13 +58,70 @@ HWTEST_F(CloseCoreTest, DoCloseTestFd_0001, testing::ext::TestSize.Level1) GTEST_LOG_(INFO) << "CloseCoreTest-end DoCloseTestFd_0001"; } +/** +* @tc.name: DoCloseTestFd_0002 +* @tc.desc: Test function of DoClose() interface for sucess. +* @tc.size: MEDIUM +* @tc.type: FUNC +* @tc.level Level 1 +*/ +HWTEST_F(CloseCoreTest, DoCloseTestFd_0002, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "CloseCoreTest-begin DoCloseTestFd_0002"; + int32_t fd = open(FILE_PATH, O_RDWR); + if (fd <= 0) { + close(fd); + ASSERT_TRUE(false); + } + + auto ret = CloseCore::DoClose(fd); + EXPECT_TRUE(ret.IsSuccess()); + + int32_t fdEnd = open(FILE_PATH, O_RDWR); + if (fdEnd <= 0) { + close(fdEnd); + ASSERT_TRUE(false); + } + EXPECT_EQ(fdEnd, fd); + + ret = CloseCore::DoClose(fd); + EXPECT_TRUE(ret.IsSuccess()); + + GTEST_LOG_(INFO) << "CloseCoreTest-end DoCloseTestFd_0002"; +} + +/** +* @tc.name: DoCloseTestFd_0003 +* @tc.desc: Test function of DoClose() interface for failed. +* @tc.size: MEDIUM +* @tc.type: FUNC +* @tc.level Level 1 +*/ +HWTEST_F(CloseCoreTest, DoCloseTestFd_0003, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "CloseCoreTest-begin DoCloseTestFd_0003"; + int32_t fd = open(FILE_PATH, O_RDWR); + if (fd <= 0) { + close(fd); + ASSERT_TRUE(false); + } + auto ret = CloseCore::DoClose(fd); + EXPECT_TRUE(ret.IsSuccess()); + + ret = CloseCore::DoClose(fd); + EXPECT_FALSE(ret.IsSuccess()); + auto err = ret.GetError(); + EXPECT_EQ(err.GetErrNo(), 13900008); + + GTEST_LOG_(INFO) << "CloseCoreTest-end DoCloseTestFd_0003"; +} + /** * @tc.name: DoCloseTestFile_0001 * @tc.desc: Test function of DoClose() interface for success. * @tc.size: MEDIUM * @tc.type: FUNC * @tc.level Level 1 -* @tc.require: AR000IGDNF */ HWTEST_F(CloseCoreTest, DoCloseTestFile_0001, testing::ext::TestSize.Level1) { @@ -87,7 +143,6 @@ HWTEST_F(CloseCoreTest, DoCloseTestFile_0001, testing::ext::TestSize.Level1) * @tc.size: MEDIUM * @tc.type: FUNC * @tc.level Level 1 -* @tc.require: AR000IGDNF */ HWTEST_F(CloseCoreTest, DoCloseTestFile_0002, testing::ext::TestSize.Level1) { diff --git a/interfaces/test/unittest/js/mod_fs/properties/lstat_core_mock_test.cpp b/interfaces/test/unittest/js/mod_fs/properties/lstat_core_mock_test.cpp new file mode 100644 index 000000000..691f2b3de --- /dev/null +++ b/interfaces/test/unittest/js/mod_fs/properties/lstat_core_mock_test.cpp @@ -0,0 +1,79 @@ +/* + * 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 "lstat_core.h" +#include "uv_fs_mock.h" + +namespace OHOS::FileManagement::ModuleFileIO::Test { +using namespace testing; +using namespace testing::ext; +using namespace std; + +class LstatCoreMockTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); + static inline shared_ptr uvMock = nullptr; +}; + +void LstatCoreMockTest::SetUpTestCase(void) +{ + GTEST_LOG_(INFO) << "SetUpTestCase"; + uvMock = make_shared(); + Uvfs::ins = uvMock; +} + +void LstatCoreMockTest::TearDownTestCase(void) +{ + GTEST_LOG_(INFO) << "TearDownTestCase"; + Uvfs::ins = nullptr; + uvMock = nullptr; +} + +void LstatCoreMockTest::SetUp(void) +{ + GTEST_LOG_(INFO) << "SetUp"; +} + +void LstatCoreMockTest::TearDown(void) +{ + GTEST_LOG_(INFO) << "TearDown"; +} + +/** + * @tc.name: LstatCoreMockTest_DoLstat_001 + * @tc.desc: Test function of LstatCore::DoLstat interface for FALSE. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ +HWTEST_F(LstatCoreMockTest, LstatCoreMockTest_DoLstat_001, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "LstatCoreMockTest-begin LstatCoreMockTest_DoLstat_001"; + + EXPECT_CALL(*uvMock, uv_fs_lstat(_, _, _, _)).WillOnce(Return(-1)); + + auto res = LstatCore::DoLstat("/data/test/lstat.txt"); + EXPECT_EQ(res.IsSuccess(), false); + + GTEST_LOG_(INFO) << "LstatCoreMockTest-end LstatCoreMockTest_DoLstat_001"; +} + +} \ No newline at end of file diff --git a/interfaces/test/unittest/js/mod_fs/properties/lstat_core_test.cpp b/interfaces/test/unittest/js/mod_fs/properties/lstat_core_test.cpp new file mode 100644 index 000000000..c40e99f2f --- /dev/null +++ b/interfaces/test/unittest/js/mod_fs/properties/lstat_core_test.cpp @@ -0,0 +1,94 @@ +/* + * 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 "lstat_core.h" + +namespace OHOS::FileManagement::ModuleFileIO::Test { +using namespace testing; +using namespace testing::ext; +using namespace std; + +class LstatCoreTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); +}; + +void LstatCoreTest::SetUpTestCase(void) +{ + GTEST_LOG_(INFO) << "SetUpTestCase"; + int32_t fd = open("/data/test/lstat.txt", CREATE | O_RDWR, 0644); + if (fd <= 0) { + ASSERT_TRUE(false); + } + close(fd); +} + +void LstatCoreTest::TearDownTestCase(void) +{ + GTEST_LOG_(INFO) << "TearDownTestCase"; + rmdir("/data/test/lstat.txt"); +} + +void LstatCoreTest::SetUp(void) +{ + GTEST_LOG_(INFO) << "SetUp"; +} + +void LstatCoreTest::TearDown(void) +{ + GTEST_LOG_(INFO) << "TearDown"; +} + +/** + * @tc.name: LstatCoreTest_DoLstat_001 + * @tc.desc: Test function of LstatCore::DoLstat interface for FALSE. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ +HWTEST_F(LstatCoreTest, LstatCoreTest_DoLstat_001, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "LstatCoreTest-begin LstatCoreTest_DoLstat_001"; + + auto res = LstatCore::DoLstat("/invalid/test/lstat.txt"); + EXPECT_EQ(res.IsSuccess(), false); + auto err = res.GetError(); + EXPECT_EQ(err.GetErrNo(), 13900002); + + GTEST_LOG_(INFO) << "LstatCoreTest-end LstatCoreTest_DoLstat_001"; +} + +/** + * @tc.name: LstatCoreTest_DoLstat_002 + * @tc.desc: Test function of LstatCore::DoLstat interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ +HWTEST_F(LstatCoreTest, LstatCoreTest_DoLstat_002, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "LstatCoreTest-begin LstatCoreTest_DoLstat_002"; + + auto res = LstatCore::DoLstat("/data/test/lstat.txt"); + EXPECT_EQ(res.IsSuccess(), true); + + GTEST_LOG_(INFO) << "LstatCoreTest-end LstatCoreTest_DoLstat_002"; +} +} \ No newline at end of file diff --git a/interfaces/test/unittest/js/mod_fs/properties/rename_core_mock_test.cpp b/interfaces/test/unittest/js/mod_fs/properties/rename_core_mock_test.cpp new file mode 100644 index 000000000..910487a21 --- /dev/null +++ b/interfaces/test/unittest/js/mod_fs/properties/rename_core_mock_test.cpp @@ -0,0 +1,102 @@ +/* + * 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 "rename_core.h" +#include "uv_fs_mock.h" + +#include + +namespace OHOS::FileManagement::ModuleFileIO::Test { +using namespace testing; +using namespace testing::ext; +using namespace std; + +class RenameCoreMockTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); + static inline shared_ptr uvfs = nullptr; +}; + +void RenameCoreMockTest::SetUpTestCase(void) +{ + uvfs = std::make_shared(); + Uvfs::ins = uvfs; + GTEST_LOG_(INFO) << "SetUpTestCase"; +} + +void RenameCoreMockTest::TearDownTestCase(void) +{ + Uvfs::ins = nullptr; + uvfs = nullptr; + GTEST_LOG_(INFO) << "TearDownTestCase"; +} + +void RenameCoreMockTest::SetUp(void) +{ + GTEST_LOG_(INFO) << "SetUp"; +} + +void RenameCoreMockTest::TearDown(void) +{ + GTEST_LOG_(INFO) << "TearDown"; +} + +/** + * @tc.name: RenameCoreMockTest_DoRename_001 + * @tc.desc: Test function of RenameCore::DoRename interface for FALSE. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ +HWTEST_F(RenameCoreMockTest, RenameCoreMockTest_DoRename_001, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "RenameCoreMockTest-begin RenameCoreMockTest_DoRename_001"; + string src; + string dest; + + EXPECT_CALL(*uvfs, uv_fs_rename(_, _, _, _, _)).WillOnce(Return(-1)); + + auto res = RenameCore::DoRename(src, dest); + EXPECT_EQ(res.IsSuccess(), false); + + GTEST_LOG_(INFO) << "RenameCoreMockTest-end RenameCoreMockTest_DoRename_001"; +} + +/** + * @tc.name: RenameCoreMockTest_DoRename_002 + * @tc.desc: Test function of RenameCore::DoRename interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ +HWTEST_F(RenameCoreMockTest, RenameCoreMockTest_DoRename_002, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "RenameCoreMockTest-begin RenameCoreMockTest_DoRename_002"; + string src; + string dest; + + EXPECT_CALL(*uvfs, uv_fs_rename(_, _, _, _, _)).WillOnce(Return(1)); + + auto res = RenameCore::DoRename(src, dest); + EXPECT_EQ(res.IsSuccess(), true); + + GTEST_LOG_(INFO) << "RenameCoreMockTest-end RenameCoreMockTest_DoRename_002"; +} + + +} // namespace OHOS::FileManagement::ModuleFileIO::Test \ No newline at end of file -- Gitee From b8d3cd784e64feead6870ee222093a063067ab2e Mon Sep 17 00:00:00 2001 From: tianp Date: Sat, 26 Jul 2025 16:18:13 +0800 Subject: [PATCH 2/2] =?UTF-8?q?lstat=E5=8A=9F=E8=83=BD=20=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: tianp Change-Id: I187823d4b61181d35aaf9664538047ec92205891 --- interfaces/kits/js/src/common/ani_helper/ani_helper.h | 6 +++--- interfaces/kits/js/src/common/ani_helper/ani_signature.cpp | 4 ++++ interfaces/kits/js/src/common/ani_helper/ani_signature.h | 5 +++++ interfaces/kits/js/src/common/ani_helper/type_converter.cpp | 6 +++--- interfaces/kits/js/src/mod_fs/properties/ani/close_ani.cpp | 2 +- interfaces/kits/js/src/mod_fs/properties/lstat_core.cpp | 1 + interfaces/kits/js/src/mod_fs/properties/lstat_core.h | 2 +- interfaces/kits/js/src/mod_fs/properties/rename_core.h | 1 - .../unittest/js/mod_fs/properties/lstat_core_mock_test.cpp | 2 +- 9 files changed, 19 insertions(+), 10 deletions(-) diff --git a/interfaces/kits/js/src/common/ani_helper/ani_helper.h b/interfaces/kits/js/src/common/ani_helper/ani_helper.h index 49a1d22f7..3002ac16c 100644 --- a/interfaces/kits/js/src/common/ani_helper/ani_helper.h +++ b/interfaces/kits/js/src/common/ani_helper/ani_helper.h @@ -113,7 +113,7 @@ public: static const string longValueSig = Builder::BuildSignatureDescriptor({}, BasicTypes::longType); ani_long value; status = env->Object_CallMethodByName_Long( - static_cast(property), "toLong", longValueSig.c_str(), &value); + static_cast(property), BasicTypesConverter::toLong.c_str(), longValueSig.c_str(), &value); if (status != ANI_OK) { return { false, nullopt }; } @@ -157,7 +157,7 @@ public: if (status != ANI_OK) { status = vm->GetEnv(ANI_VERSION_1, &env); if (status != ANI_OK) { - HILOGE("vm GetEnv, err: %{private}d", status); + HILOGE("vm GetEnv, err: %{public}d", status); return nullptr; } } @@ -169,7 +169,7 @@ public: if (vm && GetThreadEnvStorage()) { auto status = vm->DetachCurrentThread(); if (status != ANI_OK) { - HILOGE("Detach thread env from vm failed! status: %{private}d", status); + HILOGE("Detach thread env from vm failed! status: %{public}d", status); return; } GetThreadEnvStorage() = nullptr; diff --git a/interfaces/kits/js/src/common/ani_helper/ani_signature.cpp b/interfaces/kits/js/src/common/ani_helper/ani_signature.cpp index f8a2a92de..3b4e5f12d 100644 --- a/interfaces/kits/js/src/common/ani_helper/ani_signature.cpp +++ b/interfaces/kits/js/src/common/ani_helper/ani_signature.cpp @@ -27,6 +27,10 @@ const Type BasicTypes::intType = Builder::BuildInt(); const Type BasicTypes::longType = Builder::BuildLong(); const Type BasicTypes::floatType = Builder::BuildFloat(); const Type BasicTypes::doubleType = Builder::BuildDouble(); +// BasicTypesConverter::toLong +const string BasicTypesConverter::toLong = "toLong"; +const string BasicTypesConverter::toInt = "toInt"; + // BoxedTypes::Boolean const Type BoxedTypes::Boolean::classType = Builder::BuildClass("std.core.Boolean"); const string BoxedTypes::Boolean::classDesc = BoxedTypes::Double::classType.Descriptor(); diff --git a/interfaces/kits/js/src/common/ani_helper/ani_signature.h b/interfaces/kits/js/src/common/ani_helper/ani_signature.h index 3dd55d2c2..bb9217942 100644 --- a/interfaces/kits/js/src/common/ani_helper/ani_signature.h +++ b/interfaces/kits/js/src/common/ani_helper/ani_signature.h @@ -38,6 +38,11 @@ struct BasicTypes { static const Type doubleType; }; +struct BasicTypesConverter { + static const string toLong; + static const string toInt; +}; + struct BaseType { static const string ctorDesc; static const string ctorSig0; diff --git a/interfaces/kits/js/src/common/ani_helper/type_converter.cpp b/interfaces/kits/js/src/common/ani_helper/type_converter.cpp index ba640a84c..d034d29d7 100644 --- a/interfaces/kits/js/src/common/ani_helper/type_converter.cpp +++ b/interfaces/kits/js/src/common/ani_helper/type_converter.cpp @@ -59,7 +59,7 @@ std::tuple> TypeConverter::ToOptionalInt32(ani_env } ani_int intValue; - if (ANI_OK == env->Object_CallMethodByName_Int(value, "toInt", nullptr, &intValue)) { + if (ANI_OK == env->Object_CallMethodByName_Int(value, BasicTypesConverter::toInt.c_str(), nullptr, &intValue)) { return { true, std::make_optional(intValue) }; } @@ -79,7 +79,7 @@ std::tuple> TypeConverter::ToOptionalInt64(ani_env } ani_long longValue; - if (ANI_OK == env->Object_CallMethodByName_Long(value, "toLong", nullptr, &longValue)) { + if (ANI_OK == env->Object_CallMethodByName_Long(value, BasicTypesConverter::toLong.c_str(), nullptr, &longValue)) { return { true, std::make_optional(longValue) }; } @@ -152,7 +152,7 @@ static std::tuple ParseFd(ani_env *env, const ani_object &pathOrF env->Object_InstanceOf(pathOrFd, cls, &isFd); if (isFd) { ani_int fd; - if (ANI_OK != env->Object_CallMethodByName_Int(pathOrFd, "toInt", nullptr, &fd)) { + if (ANI_OK != env->Object_CallMethodByName_Int(pathOrFd, BasicTypesConverter::toInt.c_str(), nullptr, &fd)) { HILOGE("Parse file path failed"); return { false, 0 }; } diff --git a/interfaces/kits/js/src/mod_fs/properties/ani/close_ani.cpp b/interfaces/kits/js/src/mod_fs/properties/ani/close_ani.cpp index 6bdd170fb..e2be4e863 100644 --- a/interfaces/kits/js/src/mod_fs/properties/ani/close_ani.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/ani/close_ani.cpp @@ -44,7 +44,7 @@ tuple ParseFdOrFile(ani_env *env, ani_object obj) if (isDouble) { ani_int fd; - if (ANI_OK != env->Object_CallMethodByName_Int(obj, "toInt", nullptr, &fd)) { + if (ANI_OK != env->Object_CallMethodByName_Int(obj, BasicTypesConverter::toInt.c_str(), nullptr, &fd)) { HILOGE("Get fd value failed"); return { false, result, nullptr }; } diff --git a/interfaces/kits/js/src/mod_fs/properties/lstat_core.cpp b/interfaces/kits/js/src/mod_fs/properties/lstat_core.cpp index cef683a91..3702cacc9 100644 --- a/interfaces/kits/js/src/mod_fs/properties/lstat_core.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/lstat_core.cpp @@ -60,6 +60,7 @@ FsResult LstatCore::DoLstat(const string &path) auto stat = StatInstantiator::InstantiateStat(lstat_req->statbuf); #endif if (stat == nullptr) { + HILOGE("Failed to InstantiateStat."); return FsResult::Error(ENOMEM); } return FsResult::Success(stat); diff --git a/interfaces/kits/js/src/mod_fs/properties/lstat_core.h b/interfaces/kits/js/src/mod_fs/properties/lstat_core.h index 8f95142b8..86748ea5f 100644 --- a/interfaces/kits/js/src/mod_fs/properties/lstat_core.h +++ b/interfaces/kits/js/src/mod_fs/properties/lstat_core.h @@ -25,6 +25,6 @@ class LstatCore final { public: static FsResult DoLstat(const string &path); }; -const std::string PROCEDURE_LSTAT_NAME = "FileIOLstat"; + } // namespace OHOS::FileManagement::ModuleFileIO #endif // INTERFACES_KITS_JS_SRC_MOD_FS_PROPERTIES_LSTAT_CORE_H \ No newline at end of file diff --git a/interfaces/kits/js/src/mod_fs/properties/rename_core.h b/interfaces/kits/js/src/mod_fs/properties/rename_core.h index 0eded1168..0bf0157cb 100644 --- a/interfaces/kits/js/src/mod_fs/properties/rename_core.h +++ b/interfaces/kits/js/src/mod_fs/properties/rename_core.h @@ -28,7 +28,6 @@ public: static FsResult DoRename(const string &src, const string &dest); }; -const string PROCEDURE_RENAME_NAME = "FileIORename"; } // namespace ModuleFileIO } // namespace FileManagement } // namespace OHOS diff --git a/interfaces/test/unittest/js/mod_fs/properties/lstat_core_mock_test.cpp b/interfaces/test/unittest/js/mod_fs/properties/lstat_core_mock_test.cpp index 691f2b3de..2523719e9 100644 --- a/interfaces/test/unittest/js/mod_fs/properties/lstat_core_mock_test.cpp +++ b/interfaces/test/unittest/js/mod_fs/properties/lstat_core_mock_test.cpp @@ -70,7 +70,7 @@ HWTEST_F(LstatCoreMockTest, LstatCoreMockTest_DoLstat_001, testing::ext::TestSiz EXPECT_CALL(*uvMock, uv_fs_lstat(_, _, _, _)).WillOnce(Return(-1)); - auto res = LstatCore::DoLstat("/data/test/lstat.txt"); + auto res = LstatCore::DoLstat("/data/test/LstatCoreMockTestLstat.txt"); EXPECT_EQ(res.IsSuccess(), false); GTEST_LOG_(INFO) << "LstatCoreMockTest-end LstatCoreMockTest_DoLstat_001"; -- Gitee