From 9ad824b6164754c07f9eeae666bec1b859962590 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=B6=E9=87=91=E6=B2=9B?= Date: Sat, 26 Jul 2025 16:39:53 +0800 Subject: [PATCH 1/2] symlink&utimes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 陶金沛 Change-Id: I4031b7f96fa46c6f581197636ab369d0bbcf1ac4 --- .../src/mod_fs/properties/ani/symlink_ani.cpp | 53 ++++++ .../src/mod_fs/properties/ani/symlink_ani.h | 35 ++++ .../src/mod_fs/properties/ani/utimes_ani.cpp | 48 +++++ .../js/src/mod_fs/properties/ani/utimes_ani.h | 36 ++++ .../src/mod_fs/properties/ani/write_ani.cpp | 13 +- .../src/mod_fs/properties/ani/xattr_ani.cpp | 98 ++++++++++ .../js/src/mod_fs/properties/ani/xattr_ani.h | 38 ++++ .../mod_fs/properties/create_stream_core.cpp | 44 +++++ .../mod_fs/properties/create_stream_core.h | 39 ++++ .../dfs_listener/file_dfs_listener_stub.cpp | 74 ++++++++ .../dfs_listener/file_dfs_listener_stub.h | 46 +++++ .../js/src/mod_fs/properties/symlink_core.cpp | 47 +++++ .../js/src/mod_fs/properties/symlink_core.h | 32 ++++ .../js/src/mod_fs/properties/utimes_core.cpp | 64 +++++++ .../js/src/mod_fs/properties/utimes_core.h | 32 ++++ .../js/src/mod_fs/properties/xattr_core.cpp | 87 +++++++++ .../js/src/mod_fs/properties/xattr_core.h | 35 ++++ .../properties/create_stream_core_test.cpp | 81 ++++++++ .../properties/symlink_core_mock_test.cpp | 104 ++++++++++ .../properties/utimes_core_mock_test.cpp | 124 ++++++++++++ .../js/mod_fs/properties/utimes_core_test.cpp | 73 +++++++ .../properties/xattr_core_mock_test.cpp | 179 ++++++++++++++++++ .../js/mod_fs/properties/xattr_core_test.cpp | 143 ++++++++++++++ 23 files changed, 1518 insertions(+), 7 deletions(-) create mode 100644 interfaces/kits/js/src/mod_fs/properties/ani/symlink_ani.cpp create mode 100644 interfaces/kits/js/src/mod_fs/properties/ani/symlink_ani.h create mode 100644 interfaces/kits/js/src/mod_fs/properties/ani/utimes_ani.cpp create mode 100644 interfaces/kits/js/src/mod_fs/properties/ani/utimes_ani.h create mode 100644 interfaces/kits/js/src/mod_fs/properties/ani/xattr_ani.cpp create mode 100644 interfaces/kits/js/src/mod_fs/properties/ani/xattr_ani.h create mode 100644 interfaces/kits/js/src/mod_fs/properties/create_stream_core.cpp create mode 100644 interfaces/kits/js/src/mod_fs/properties/create_stream_core.h create mode 100644 interfaces/kits/js/src/mod_fs/properties/dfs_listener/file_dfs_listener_stub.cpp create mode 100644 interfaces/kits/js/src/mod_fs/properties/dfs_listener/file_dfs_listener_stub.h create mode 100644 interfaces/kits/js/src/mod_fs/properties/symlink_core.cpp create mode 100644 interfaces/kits/js/src/mod_fs/properties/symlink_core.h create mode 100644 interfaces/kits/js/src/mod_fs/properties/utimes_core.cpp create mode 100644 interfaces/kits/js/src/mod_fs/properties/utimes_core.h create mode 100644 interfaces/kits/js/src/mod_fs/properties/xattr_core.cpp create mode 100644 interfaces/kits/js/src/mod_fs/properties/xattr_core.h create mode 100644 interfaces/test/unittest/js/mod_fs/properties/create_stream_core_test.cpp create mode 100644 interfaces/test/unittest/js/mod_fs/properties/symlink_core_mock_test.cpp create mode 100644 interfaces/test/unittest/js/mod_fs/properties/utimes_core_mock_test.cpp create mode 100644 interfaces/test/unittest/js/mod_fs/properties/utimes_core_test.cpp create mode 100644 interfaces/test/unittest/js/mod_fs/properties/xattr_core_mock_test.cpp create mode 100644 interfaces/test/unittest/js/mod_fs/properties/xattr_core_test.cpp diff --git a/interfaces/kits/js/src/mod_fs/properties/ani/symlink_ani.cpp b/interfaces/kits/js/src/mod_fs/properties/ani/symlink_ani.cpp new file mode 100644 index 000000000..4cbac5133 --- /dev/null +++ b/interfaces/kits/js/src/mod_fs/properties/ani/symlink_ani.cpp @@ -0,0 +1,53 @@ +/* + * 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 "symlink_ani.h" + +#include "error_handler.h" +#include "filemgmt_libhilog.h" +#include "symlink_core.h" +#include "type_converter.h" + +namespace OHOS { +namespace FileManagement { +namespace ModuleFileIO { +namespace ANI { + +void SymlinkAni::SymlinkSync(ani_env *env, [[maybe_unused]] ani_class clazz, ani_string target, ani_string srcPath) +{ + auto [succTarget, targetPath] = TypeConverter::ToUTF8String(env, target); + if (!succTarget) { + HILOGE("Invalid target"); + ErrorHandler::Throw(env, EINVAL); + return; + } + auto [succSrc, src] = TypeConverter::ToUTF8String(env, srcPath); + if (!succSrc) { + HILOGE("Invalid src"); + ErrorHandler::Throw(env, EINVAL); + return; + } + auto ret = SymlinkCore::DoSymlink(targetPath, src); + if (!ret.IsSuccess()) { + HILOGE("DoSymlink 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/symlink_ani.h b/interfaces/kits/js/src/mod_fs/properties/ani/symlink_ani.h new file mode 100644 index 000000000..6ba3abb55 --- /dev/null +++ b/interfaces/kits/js/src/mod_fs/properties/ani/symlink_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_SYMLINK_ANI_H +#define INTERFACES_KITS_JS_SRC_MOD_FS_SYMLINK_ANI_H + +#include + +namespace OHOS { +namespace FileManagement { +namespace ModuleFileIO { +namespace ANI { + +class SymlinkAni final { +public: + static void SymlinkSync(ani_env *env, [[maybe_unused]] ani_class clazz, ani_string target, ani_string srcPath); +}; +} // namespace ANI +} // namespace ModuleFileIO +} // namespace FileManagement +} // namespace OHOS + +#endif // INTERFACES_KITS_JS_SRC_MOD_FS_SYMLINK_ANI_H \ No newline at end of file diff --git a/interfaces/kits/js/src/mod_fs/properties/ani/utimes_ani.cpp b/interfaces/kits/js/src/mod_fs/properties/ani/utimes_ani.cpp new file mode 100644 index 000000000..849f10d4d --- /dev/null +++ b/interfaces/kits/js/src/mod_fs/properties/ani/utimes_ani.cpp @@ -0,0 +1,48 @@ +/* + * 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 "utimes_ani.h" + +#include "error_handler.h" +#include "filemgmt_libhilog.h" +#include "type_converter.h" +#include "utimes_core.h" + +namespace OHOS { +namespace FileManagement { +namespace ModuleFileIO { +namespace ANI { + +void UtimesAni::Utimes( + ani_env *env, [[maybe_unused]] ani_class clazz, ani_string path, ani_double mtime) +{ + auto [succPath, newPath] = TypeConverter::ToUTF8String(env, path); + if (!succPath) { + HILOGE("Invalid path"); + ErrorHandler::Throw(env, EINVAL); + return; + } + auto ret = UtimesCore::DoUtimes(newPath, static_cast(mtime)); + if (!ret.IsSuccess()) { + HILOGE("Utimes 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/utimes_ani.h b/interfaces/kits/js/src/mod_fs/properties/ani/utimes_ani.h new file mode 100644 index 000000000..118f7d25a --- /dev/null +++ b/interfaces/kits/js/src/mod_fs/properties/ani/utimes_ani.h @@ -0,0 +1,36 @@ +/* + * 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_UTIMES_ANI_H +#define INTERFACES_KITS_JS_SRC_MOD_FS_UTIMES_ANI_H + +#include + +namespace OHOS { +namespace FileManagement { +namespace ModuleFileIO { +namespace ANI { + +class UtimesAni final { +public: + static void Utimes( + ani_env *env, [[maybe_unused]] ani_class clazz, ani_string path, ani_double mtime); +}; +} // namespace ANI +} // namespace ModuleFileIO +} // namespace FileManagement +} // namespace OHOS + +#endif // INTERFACES_KITS_JS_SRC_MOD_FS_UTIMES_ANI_H \ No newline at end of file diff --git a/interfaces/kits/js/src/mod_fs/properties/ani/write_ani.cpp b/interfaces/kits/js/src/mod_fs/properties/ani/write_ani.cpp index 64c8d1bfa..a9a798a47 100644 --- a/interfaces/kits/js/src/mod_fs/properties/ani/write_ani.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/ani/write_ani.cpp @@ -40,13 +40,6 @@ static tuple> ToWriteOptions(ani_env *env, ani_obje return { true, nullopt }; } - auto [succEncoding, encoding] = AniHelper::ParseEncoding(env, obj); - if (!succEncoding) { - HILOGE("Illegal option.encoding parameter"); - return { false, nullopt }; - } - options.encoding = encoding; - auto [succOffset, offset] = AniHelper::ParseInt64Option(env, obj, "offset"); if (!succOffset) { HILOGE("Illegal option.offset parameter"); @@ -61,6 +54,12 @@ static tuple> ToWriteOptions(ani_env *env, ani_obje } options.length = length; + auto [succEncoding, encoding] = AniHelper::ParseEncoding(env, obj); + if (!succEncoding) { + HILOGE("Illegal option.encoding parameter"); + return { false, nullopt }; + } + options.encoding = encoding; return { true, make_optional(move(options)) }; } 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 new file mode 100644 index 000000000..2a69e0bd2 --- /dev/null +++ b/interfaces/kits/js/src/mod_fs/properties/ani/xattr_ani.cpp @@ -0,0 +1,98 @@ +/* + * 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 "xattr_ani.h" + +#include "error_handler.h" +#include "filemgmt_libhilog.h" +#include "type_converter.h" +#include "xattr_core.h" + +namespace OHOS { +namespace FileManagement { +namespace ModuleFileIO { +namespace ANI { + +void XattrAni::SetXattrSync( + ani_env *env, [[maybe_unused]] ani_class clazz, ani_string path, ani_string key, ani_string value) +{ + auto [pathSucc, pathStr] = TypeConverter::ToUTF8String(env, path); + if (!pathSucc) { + HILOGE("Invalid path"); + ErrorHandler::Throw(env, EINVAL); + return; + } + + auto [keySucc, keyStr] = TypeConverter::ToUTF8String(env, key); + if (!keySucc) { + HILOGE("Invalid xattr key"); + ErrorHandler::Throw(env, EINVAL); + return; + } + + auto [valueSucc, valueStr] = TypeConverter::ToUTF8String(env, value); + if (!valueSucc) { + HILOGE("Invalid xattr value"); + ErrorHandler::Throw(env, EINVAL); + return; + } + + auto ret = XattrCore::DoSetXattr(pathStr, keyStr, valueStr); + if (!ret.IsSuccess()) { + HILOGE("DoSetXattr failed"); + const auto &err = ret.GetError(); + ErrorHandler::Throw(env, err); + return; + } +} + +ani_string XattrAni::GetXattrSync(ani_env *env, [[maybe_unused]] ani_class clazz, ani_string path, ani_string key) +{ + auto [pathSucc, pathStr] = TypeConverter::ToUTF8String(env, path); + if (!pathSucc) { + HILOGE("Invalid path"); + ErrorHandler::Throw(env, EINVAL); + return nullptr; + } + + auto [keySucc, keyStr] = TypeConverter::ToUTF8String(env, key); + if (!keySucc) { + HILOGE("Invalid xattr key"); + ErrorHandler::Throw(env, EINVAL); + return nullptr; + } + + auto ret = XattrCore::DoGetXattr(pathStr, keyStr); + if (!ret.IsSuccess()) { + HILOGE("DoSetXattr failed"); + const auto &err = ret.GetError(); + ErrorHandler::Throw(env, err); + return nullptr; + } + + const auto &res = ret.GetData().value(); + auto [succ, result] = TypeConverter::ToAniString(env, res); + if (!succ) { + HILOGE("Create ani_string error"); + ErrorHandler::Throw(env, UNKNOWN_ERR); + return nullptr; + } + return result; +} + +} // 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/xattr_ani.h b/interfaces/kits/js/src/mod_fs/properties/ani/xattr_ani.h new file mode 100644 index 000000000..2bc788d12 --- /dev/null +++ b/interfaces/kits/js/src/mod_fs/properties/ani/xattr_ani.h @@ -0,0 +1,38 @@ +/* + * 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_XATTR_ANI_H +#define INTERFACES_KITS_JS_SRC_MOD_FS_PROPERTIES_ANI_XATTR_ANI_H + +#include + +namespace OHOS { +namespace FileManagement { +namespace ModuleFileIO { +namespace ANI { + +class XattrAni final { +public: + static void SetXattrSync( + ani_env *env, [[maybe_unused]] ani_class clazz, ani_string path, ani_string key, ani_string value); + static ani_string GetXattrSync(ani_env *env, [[maybe_unused]] ani_class clazz, ani_string path, ani_string key); +}; + +} // namespace ANI +} // namespace ModuleFileIO +} // namespace FileManagement +} // namespace OHOS + +#endif // INTERFACES_KITS_JS_SRC_MOD_FS_PROPERTIES_ANI_XATTR_ANI_H \ No newline at end of file diff --git a/interfaces/kits/js/src/mod_fs/properties/create_stream_core.cpp b/interfaces/kits/js/src/mod_fs/properties/create_stream_core.cpp new file mode 100644 index 000000000..e17d5a1ba --- /dev/null +++ b/interfaces/kits/js/src/mod_fs/properties/create_stream_core.cpp @@ -0,0 +1,44 @@ +/* + * 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 "create_stream_core.h" + +#include + +#include "file_utils.h" +#include "filemgmt_libhilog.h" +#include "fs_utils.h" +#include "stream_instantiator.h" +#include "stream_entity.h" + +namespace OHOS { +namespace FileManagement { +namespace ModuleFileIO { +using namespace std; + +FsResult CreateStreamCore::DoCreateStream(const std::string &path, const std::string &mode) +{ + FILE *file = fopen(path.c_str(), mode.c_str()); + if (!file) { + HILOGE("Failed to fopen file by path"); + return FsResult::Error(errno); + } + + return StreamInstantiator::InstantiateStream(move(file)); +} + +} // namespace ModuleFileIO +} // namespace FileManagement +} // namespace OHOS \ No newline at end of file diff --git a/interfaces/kits/js/src/mod_fs/properties/create_stream_core.h b/interfaces/kits/js/src/mod_fs/properties/create_stream_core.h new file mode 100644 index 000000000..8c0a2aade --- /dev/null +++ b/interfaces/kits/js/src/mod_fs/properties/create_stream_core.h @@ -0,0 +1,39 @@ +/* + * 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_CREATE_STREAM_CORE_H +#define INTERFACES_KITS_JS_SRC_MOD_FS_PROPERTIES_CREATE_STREAM_CORE_H + +#include "filemgmt_libfs.h" +#include "fs_stream.h" + +namespace OHOS { +namespace FileManagement { +namespace ModuleFileIO { + +class CreateStreamCore final { +public: + static FsResult DoCreateStream(const std::string &path, const std::string &mode); +}; + +struct AsyncCreateStreamArg { + std::shared_ptr fp { nullptr }; +}; + +const std::string PROCEDURE_CREATESTREAM_NAME = "FileIOCreateStream"; +} // namespace ModuleFileIO +} // namespace FileManagement +} // namespace OHOS +#endif // INTERFACES_KITS_JS_SRC_MOD_FS_PROPERTIES_CREATE_STREAM_CORE_H \ No newline at end of file diff --git a/interfaces/kits/js/src/mod_fs/properties/dfs_listener/file_dfs_listener_stub.cpp b/interfaces/kits/js/src/mod_fs/properties/dfs_listener/file_dfs_listener_stub.cpp new file mode 100644 index 000000000..a77a6ff26 --- /dev/null +++ b/interfaces/kits/js/src/mod_fs/properties/dfs_listener/file_dfs_listener_stub.cpp @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2024 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 "file_dfs_listener_stub.h" +#include "file_dfs_listener_interface_code.h" +#include "filemgmt_libhilog.h" + +namespace OHOS { +namespace FileManagement { +namespace ModuleFileIO { +using namespace FileManagement; +namespace { + constexpr int NO_ERROR = 0; + constexpr int E_INVAL_ARG = 1; +} + +FileDfsListenerStub::FileDfsListenerStub() +{ + opToInterfaceMap_[static_cast + (Storage::DistributedFile::FileDfsListenerInterfaceCode::FILE_DFS_LISTENER_ON_STATUS)] = + &FileDfsListenerStub::HandleOnStatus; +} + +int32_t FileDfsListenerStub::OnRemoteRequest(uint32_t code, + MessageParcel &data, + MessageParcel &reply, + MessageOption &option) +{ + if (data.ReadInterfaceToken() != GetDescriptor()) { + return FILE_DFS_LISTENER_DESCRIPTOR_IS_EMPTY; + } + switch (code) { + case static_cast(Storage::DistributedFile::FileDfsListenerInterfaceCode::FILE_DFS_LISTENER_ON_STATUS): + return HandleOnStatus(data, reply); + default: + HILOGE("Cannot response request %{public}d: unknown tranction", code); + return IPCObjectStub::OnRemoteRequest(code, data, reply, option); + } +} + +int32_t FileDfsListenerStub::HandleOnStatus(MessageParcel &data, MessageParcel &reply) +{ + std::string networkId; + if (!data.ReadString(networkId)) { + HILOGE("read networkId failed"); + return E_INVAL_ARG; + } + int32_t status; + if (!data.ReadInt32(status)) { + HILOGE("read status failed"); + return E_INVAL_ARG; + } + if (networkId.empty() || status < 0) { + HILOGE("Invalid arguments"); + return E_INVAL_ARG; + } + OnStatus(networkId, status); + return NO_ERROR; +} + +} // namespace ModuleFileIO +} // namespace FileManagement +} // namespace OHOS \ No newline at end of file diff --git a/interfaces/kits/js/src/mod_fs/properties/dfs_listener/file_dfs_listener_stub.h b/interfaces/kits/js/src/mod_fs/properties/dfs_listener/file_dfs_listener_stub.h new file mode 100644 index 000000000..bafb64cad --- /dev/null +++ b/interfaces/kits/js/src/mod_fs/properties/dfs_listener/file_dfs_listener_stub.h @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2024 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 FILEMANAGEMENT_FILE_API_FILE_DFS_LISTENER_STUB_H +#define FILEMANAGEMENT_FILE_API_FILE_DFS_LISTENER_STUB_H + +#include +#include "i_file_dfs_listener.h" +#include "iremote_stub.h" +#include "message_option.h" +#include "message_parcel.h" +#include "refbase.h" + +namespace OHOS { +namespace FileManagement { +namespace ModuleFileIO { +class FileDfsListenerStub : public IRemoteStub { +public: + FileDfsListenerStub(); + virtual ~FileDfsListenerStub() = default; + int32_t OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; + +private: + using FileDfsListenerInterface = int32_t (FileDfsListenerStub::*)(MessageParcel &data, MessageParcel &reply); + std::map opToInterfaceMap_; + + int32_t HandleOnStatus(MessageParcel &data, MessageParcel &reply); +}; + +} // namespace ModuleFileIO +} // namespace FileManagement +} // namespace OHOS + +#endif // FILEMANAGEMENT_FILE_API_FILE_DFS_LISTENER_STUB_H \ No newline at end of file diff --git a/interfaces/kits/js/src/mod_fs/properties/symlink_core.cpp b/interfaces/kits/js/src/mod_fs/properties/symlink_core.cpp new file mode 100644 index 000000000..217f429fd --- /dev/null +++ b/interfaces/kits/js/src/mod_fs/properties/symlink_core.cpp @@ -0,0 +1,47 @@ +/* + * 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 "symlink_core.h" + +#include +#include +#include +#include + +#include "filemgmt_libhilog.h" +#include "fs_utils.h" + +namespace OHOS { +namespace FileManagement { +namespace ModuleFileIO { +using namespace std; + +FsResult SymlinkCore::DoSymlink(const string &target, const string &srcPath) +{ + std::unique_ptr symlinkReq = { new uv_fs_t, FsUtils::FsReqCleanup }; + if (!symlinkReq) { + HILOGE("Failed to request heap memory."); + return FsResult::Error(ENOMEM); + } + int ret = uv_fs_symlink(nullptr, symlinkReq.get(), target.c_str(), srcPath.c_str(), 0, nullptr); + if (ret < 0) { + HILOGE("Failed to create a link for old 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/symlink_core.h b/interfaces/kits/js/src/mod_fs/properties/symlink_core.h new file mode 100644 index 000000000..223c8b683 --- /dev/null +++ b/interfaces/kits/js/src/mod_fs/properties/symlink_core.h @@ -0,0 +1,32 @@ +/* + * 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_SYMLINK_CORE_H +#define INTERFACES_KITS_JS_SRC_MOD_FS_PROPERTIES_SYMLINK_CORE_H + +#include "filemgmt_libfs.h" + +namespace OHOS { +namespace FileManagement { +namespace ModuleFileIO { +class SymlinkCore final { +public: + static FsResult DoSymlink(const string &target, const string &srcPath); +}; +const std::string PROCEDURE_RMDIRENT_NAME = "FileIOSymLink"; +} // namespace ModuleFileIO +} // namespace FileManagement +} // namespace OHOS +#endif // INTERFACES_KITS_JS_SRC_MOD_FS_PROPERTIES_SYMLINK_CORE_H \ No newline at end of file diff --git a/interfaces/kits/js/src/mod_fs/properties/utimes_core.cpp b/interfaces/kits/js/src/mod_fs/properties/utimes_core.cpp new file mode 100644 index 000000000..4b517167b --- /dev/null +++ b/interfaces/kits/js/src/mod_fs/properties/utimes_core.cpp @@ -0,0 +1,64 @@ +/* + * 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 "utimes_core.h" + +#include + +#include "filemgmt_libhilog.h" +#include "fs_utils.h" + +namespace OHOS { +namespace FileManagement { +namespace ModuleFileIO { +using namespace std; + +FsResult UtimesCore::DoUtimes(const string &path, const double mtime) +{ + if (mtime < 0) { + HILOGE("Invalid mtime"); + return FsResult::Error(EINVAL); + } + std::unique_ptr statReq = { + new (std::nothrow) uv_fs_t, FsUtils::FsReqCleanup }; + if (!statReq) { + HILOGE("Failed to request heap memory."); + return FsResult::Error(ENOMEM); + } + int ret = uv_fs_stat(nullptr, statReq.get(), path.c_str(), nullptr); + if (ret < 0) { + HILOGE("Failed to get stat of the file by path"); + return FsResult::Error(ret); + } + + std::unique_ptr utimesReq = { + new uv_fs_t, FsUtils::FsReqCleanup }; + if (!utimesReq) { + HILOGE("Failed to request heap memory."); + return FsResult::Error(ENOMEM); + } + + double atime = static_cast(statReq->statbuf.st_atim.tv_sec) + + static_cast(statReq->statbuf.st_atim.tv_nsec) / NS; + ret = uv_fs_utime(nullptr, utimesReq.get(), path.c_str(), atime, mtime / MS, nullptr); + if (ret < 0) { + HILOGE("Failed to chang mtime of the file for %{public}d", ret); + return FsResult::Error(ret); + } + return FsResult::Success(); +} +} // ModuleFileIO +} // FileManagement +} // OHOS \ No newline at end of file diff --git a/interfaces/kits/js/src/mod_fs/properties/utimes_core.h b/interfaces/kits/js/src/mod_fs/properties/utimes_core.h new file mode 100644 index 000000000..86fe8c4fd --- /dev/null +++ b/interfaces/kits/js/src/mod_fs/properties/utimes_core.h @@ -0,0 +1,32 @@ +/* + * 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_UTIMES_CORE_H +#define INTERFACES_KITS_JS_SRC_MOD_FS_PROPERTIES_UTIMES_CORE_H + +#include "filemgmt_libfs.h" + +namespace OHOS { +namespace FileManagement { +namespace ModuleFileIO { +class UtimesCore final { +public: + static FsResult DoUtimes(const string &path, const double mtime); +}; +const std::string PROCEDURE_RMDIRENT_NAME = "FileIOUtimes"; +} // namespace ModuleFileIO +} // namespace FileManagement +} // namespace OHOS +#endif // INTERFACES_KITS_JS_SRC_MOD_FS_PROPERTIES_UTIMES_CORE_H \ No newline at end of file diff --git a/interfaces/kits/js/src/mod_fs/properties/xattr_core.cpp b/interfaces/kits/js/src/mod_fs/properties/xattr_core.cpp new file mode 100644 index 000000000..ba22e42c7 --- /dev/null +++ b/interfaces/kits/js/src/mod_fs/properties/xattr_core.cpp @@ -0,0 +1,87 @@ +/* + * 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 "xattr_core.h" + +#include +#include +#include + +#include "file_utils.h" +#include "filemgmt_libhilog.h" + +namespace OHOS { +namespace FileManagement { +namespace ModuleFileIO { +using namespace std; +constexpr size_t MAX_XATTR_SIZE = 4096; + +static bool IsIllegalXattr(const char *key, const char *value) +{ + bool isIllegalKey = strnlen(key, MAX_XATTR_SIZE + 1) > MAX_XATTR_SIZE; + if (isIllegalKey) { + HILOGE("key is too long"); + } + bool isIllegalValue = strnlen(value, MAX_XATTR_SIZE + 1) > MAX_XATTR_SIZE; + if (isIllegalValue) { + HILOGE("value is too long"); + } + return isIllegalKey || isIllegalValue; +} + +static int32_t GetXattrCore(const char *path, const char *key, std::shared_ptr result) +{ + ssize_t xAttrSize = getxattr(path, key, nullptr, 0); + if (xAttrSize == -1 || xAttrSize == 0) { + *result = ""; + return ERRNO_NOERR; + } + auto xattrValue = CreateUniquePtr(static_cast(xAttrSize) + 1); + xAttrSize = getxattr(path, key, xattrValue.get(), static_cast(xAttrSize)); + if (xAttrSize == -1) { + return errno; + } + xattrValue[xAttrSize] = '\0'; + *result = std::string(xattrValue.get()); + return ERRNO_NOERR; +} + +FsResult XattrCore::DoSetXattr(const string &path, const string &key, const string &value) +{ + if (IsIllegalXattr(key.c_str(), value.c_str())) { + HILOGE("Invalid xattr value"); + return FsResult::Error(EINVAL); + } + if (setxattr(path.c_str(), key.c_str(), value.c_str(), strnlen(value.c_str(), MAX_XATTR_SIZE), 0) < 0) { + HILOGE("setxattr fail, errno is %{public}d", errno); + return FsResult::Error(errno); + } + return FsResult::Success(); +} + +FsResult XattrCore::DoGetXattr(const string &path, const string &key) +{ + auto result = make_shared(); + int32_t ret = GetXattrCore(path.c_str(), key.c_str(), result); + if (ret != ERRNO_NOERR) { + HILOGE("Invalid getxattr"); + return FsResult::Error(ret); + } + return FsResult::Success(move(*result)); +} + +} // namespace ModuleFileIO +} // namespace FileManagement +} // namespace OHOS \ No newline at end of file diff --git a/interfaces/kits/js/src/mod_fs/properties/xattr_core.h b/interfaces/kits/js/src/mod_fs/properties/xattr_core.h new file mode 100644 index 000000000..71ca376e9 --- /dev/null +++ b/interfaces/kits/js/src/mod_fs/properties/xattr_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_XATTR_CORE_H +#define INTERFACES_KITS_JS_SRC_MOD_FS_PROPERTIES_XATTR_CORE_H + +#include "filemgmt_libfs.h" +#include "fs_utils.h" + +namespace OHOS { +namespace FileManagement { +namespace ModuleFileIO { +using namespace std; +class XattrCore final { +public: + static FsResult DoSetXattr(const string &path, const string &key, const string &value); + static FsResult DoGetXattr(const string &path, const string &key); +}; + +} // namespace ModuleFileIO +} // namespace FileManagement +} // namespace OHOS +#endif // INTERFACES_KITS_JS_SRC_MOD_FS_PROPERTIES_XATTR_CORE_H \ No newline at end of file diff --git a/interfaces/test/unittest/js/mod_fs/properties/create_stream_core_test.cpp b/interfaces/test/unittest/js/mod_fs/properties/create_stream_core_test.cpp new file mode 100644 index 000000000..30e1ad522 --- /dev/null +++ b/interfaces/test/unittest/js/mod_fs/properties/create_stream_core_test.cpp @@ -0,0 +1,81 @@ +/* +* 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 "create_stream_core.h" + +#define CREATE_STREAM_FILE_PATH "/data/test/CreateStreamCoreTest.txt" + +namespace OHOS { +namespace FileManagement { +namespace ModuleFileIO { +using namespace std; +class CreateStreamCoreTest : public testing::Test { +public: + static void SetUpTestCase(void) + { + int32_t fd = open(CREATE_STREAM_FILE_PATH, CREATE | O_RDWR, 0644); + close(fd); + }; + static void TearDownTestCase() + { + rmdir(CREATE_STREAM_FILE_PATH); + }; + void SetUp() {}; + void TearDown() {}; +}; +/** +* @tc.name: DoCreateStreamTest_0001 +* @tc.desc: Test function of DoCreateStream() interface for success. +* @tc.size: MEDIUM +* @tc.type: FUNC +* @tc.level Level 1 +*/ +HWTEST_F(CreateStreamCoreTest, DoCreateStreamTest_0001, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "CreateStreamCoreTest-begin DoCreateStreamTest_0001"; + auto ret = CreateStreamCore::DoCreateStream(CREATE_STREAM_FILE_PATH, "r"); + ASSERT_TRUE(ret.IsSuccess()); + + auto stream = ret.GetData().value(); + ASSERT_NE(stream, nullptr); + auto retClose = stream->Close(); + EXPECT_TRUE(retClose.IsSuccess()); + + GTEST_LOG_(INFO) << "CreateStreamCoreTest-end DoCreateStreamTest_0001"; +} + +/** +* @tc.name: DoCreateStreamTest_0002 +* @tc.desc: Test function of DoCreateStream() interface for fail. +* @tc.size: MEDIUM +* @tc.type: FUNC +* @tc.level Level 1 +*/ +HWTEST_F(CreateStreamCoreTest, DoCreateStreamTest_0002, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "CreateStreamCoreTest-begin DoCreateStreamTest_0002"; + auto ret = CreateStreamCore::DoCreateStream(CREATE_STREAM_FILE_PATH, "ssss"); + EXPECT_FALSE(ret.IsSuccess()); + + auto err = ret.GetError(); + EXPECT_EQ(err.GetErrNo(), 13900020); + + GTEST_LOG_(INFO) << "CreateStreamCoreTest-end DoCreateStreamTest_0002"; +} + +} +} +} \ No newline at end of file diff --git a/interfaces/test/unittest/js/mod_fs/properties/symlink_core_mock_test.cpp b/interfaces/test/unittest/js/mod_fs/properties/symlink_core_mock_test.cpp new file mode 100644 index 000000000..dd6e4b43b --- /dev/null +++ b/interfaces/test/unittest/js/mod_fs/properties/symlink_core_mock_test.cpp @@ -0,0 +1,104 @@ +/* + * 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 "symlink_core.h" +#include "uv_fs_mock.h" + +#include + +namespace OHOS::FileManagement::ModuleFileIO::Test { +using namespace testing; +using namespace testing::ext; +using namespace std; + +class SymlinkCoreMockTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); + static inline shared_ptr uvMock = nullptr; +}; + +void SymlinkCoreMockTest::SetUpTestCase(void) +{ + GTEST_LOG_(INFO) << "SetUpTestCase"; + uvMock = std::make_shared(); + Uvfs::ins = uvMock; +} + +void SymlinkCoreMockTest::TearDownTestCase(void) +{ + GTEST_LOG_(INFO) << "TearDownTestCase"; + Uvfs::ins = nullptr; + uvMock = nullptr; +} + +void SymlinkCoreMockTest::SetUp(void) +{ + GTEST_LOG_(INFO) << "SetUp"; +} + +void SymlinkCoreMockTest::TearDown(void) +{ + GTEST_LOG_(INFO) << "TearDown"; +} + +/** + * @tc.name: SymlinkCoreMockTest_DoSymlink_001 + * @tc.desc: Test function of SymlinkCore::DoSymlink interface for FALSE. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ +HWTEST_F(SymlinkCoreMockTest, SymlinkCoreMockTest_DoSymlink_001, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "SymlinkCore-begin SymlinkCoreMockTest_DoSymlink_001"; + + string target; + string srcPath; + + EXPECT_CALL(*uvMock, uv_fs_symlink(_, _, _, _, _, _)).WillOnce(Return(-1)); + + auto res = SymlinkCore::DoSymlink(target, srcPath); + EXPECT_EQ(res.IsSuccess(), false); + + GTEST_LOG_(INFO) << "SymlinkCore-end SymlinkCoreMockTest_DoSymlink_001"; +} + +/** + * @tc.name: SymlinkCoreMockTest_DoSymlink_002 + * @tc.desc: Test function of SymlinkCore::DoSymlink interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ +HWTEST_F(SymlinkCoreMockTest, SymlinkCoreMockTest_DoSymlink_002, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "SymlinkCore-begin SymlinkCoreMockTest_DoSymlink_002"; + + string target; + string srcPath; + + EXPECT_CALL(*uvMock, uv_fs_symlink(_, _, _, _, _, _)).WillOnce(Return(1)); + + auto res = SymlinkCore::DoSymlink(target, srcPath); + EXPECT_EQ(res.IsSuccess(), true); + + GTEST_LOG_(INFO) << "SymlinkCore-end SymlinkCoreMockTest_DoSymlink_002"; +} + +} // OHOS::FileManagement::ModuleFileIO::Test diff --git a/interfaces/test/unittest/js/mod_fs/properties/utimes_core_mock_test.cpp b/interfaces/test/unittest/js/mod_fs/properties/utimes_core_mock_test.cpp new file mode 100644 index 000000000..c7d7e60c2 --- /dev/null +++ b/interfaces/test/unittest/js/mod_fs/properties/utimes_core_mock_test.cpp @@ -0,0 +1,124 @@ +/* + * 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 "utimes_core.h" +#include "uv_fs_mock.h" + +#include + +namespace OHOS::FileManagement::ModuleFileIO::Test { +using namespace testing; +using namespace testing::ext; +using namespace std; + +class UtimesCoreMockTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); + static inline shared_ptr uvMock = nullptr; +}; + +void UtimesCoreMockTest::SetUpTestCase(void) +{ + GTEST_LOG_(INFO) << "SetUpTestCase"; + uvMock = std::make_shared(); + Uvfs::ins = uvMock; +} + +void UtimesCoreMockTest::TearDownTestCase(void) +{ + GTEST_LOG_(INFO) << "TearDownTestCase"; + Uvfs::ins = nullptr; + uvMock = nullptr; +} + +void UtimesCoreMockTest::SetUp(void) +{ + GTEST_LOG_(INFO) << "SetUp"; +} + +void UtimesCoreMockTest::TearDown(void) +{ + GTEST_LOG_(INFO) << "TearDown"; +} + +/** + * @tc.name: UtimesCoreMockTest_DoUtimes_001 + * @tc.desc: Test function of UtimesCore::DoUtimes interface for Failed. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ +HWTEST_F(UtimesCoreMockTest, UtimesCoreMockTest_DoUtimes_001, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "UtimesCoreMockTest-begin UtimesCoreMockTest_DoUtimes_001"; + + string path; + double mtime = 1; + + EXPECT_CALL(*uvMock, uv_fs_stat(_, _, _, _)).WillOnce(Return(-1)); + auto res = UtimesCore::DoUtimes(path, mtime); + EXPECT_EQ(res.IsSuccess(), false); + + GTEST_LOG_(INFO) << "UtimesCoreMockTest-end UtimesCoreMockTest_DoUtimes_001"; +} + +/** + * @tc.name: UtimesCoreMockTest_DoUtimes_002 + * @tc.desc: Test function of UtimesCore::DoUtimes interface for FALSE. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ +HWTEST_F(UtimesCoreMockTest, UtimesCoreMockTest_DoUtimes_002, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "UtimesCoreMockTest-begin UtimesCoreMockTest_DoUtimes_002"; + + string path; + double mtime = 1; + + EXPECT_CALL(*uvMock, uv_fs_stat(_, _, _, _)).WillOnce(Return(1)); + EXPECT_CALL(*uvMock, uv_fs_utime(_, _, _, _, _, _)).WillOnce(Return(-1)); + auto res = UtimesCore::DoUtimes(path, mtime); + EXPECT_EQ(res.IsSuccess(), false); + + GTEST_LOG_(INFO) << "UtimesCoreMockTest-end UtimesCoreMockTest_DoUtimes_002"; +} + +/** + * @tc.name: UtimesCoreMockTest_DoUtimes_003 + * @tc.desc: Test function of UtimesCore::DoUtimes interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ +HWTEST_F(UtimesCoreMockTest, UtimesCoreMockTest_DoUtimes_003, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "UtimesCoreMockTest-begin UtimesCoreMockTest_DoUtimes_003"; + + string path; + double mtime = 1; + + EXPECT_CALL(*uvMock, uv_fs_stat(_, _, _, _)).WillOnce(Return(1)); + EXPECT_CALL(*uvMock, uv_fs_utime(_, _, _, _, _, _)).WillOnce(Return(1)); + auto res = UtimesCore::DoUtimes(path, mtime); + EXPECT_EQ(res.IsSuccess(), true); + + GTEST_LOG_(INFO) << "UtimesCoreMockTest-end UtimesCoreMockTest_DoUtimes_003"; +} + +} // namespace OHOS::FileManagement::ModuleFileIO::Test diff --git a/interfaces/test/unittest/js/mod_fs/properties/utimes_core_test.cpp b/interfaces/test/unittest/js/mod_fs/properties/utimes_core_test.cpp new file mode 100644 index 000000000..54ee576cc --- /dev/null +++ b/interfaces/test/unittest/js/mod_fs/properties/utimes_core_test.cpp @@ -0,0 +1,73 @@ +/* + * 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 "utimes_core.h" + +#include + + +namespace OHOS::FileManagement::ModuleFileIO::Test { +using namespace testing; +using namespace testing::ext; +using namespace std; + +class UtimesCoreTest : public testing::Test { +public: + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); +}; + +void UtimesCoreTest::SetUpTestCase(void) +{ + GTEST_LOG_(INFO) << "SetUpTestCase"; +} + +void UtimesCoreTest::TearDownTestCase(void) +{ + GTEST_LOG_(INFO) << "TearDownTestCase"; +} + +void UtimesCoreTest::SetUp(void) +{ + GTEST_LOG_(INFO) << "SetUp"; +} + +void UtimesCoreTest::TearDown(void) +{ + GTEST_LOG_(INFO) << "TearDown"; +} + +/** + * @tc.name: UtimesCoreTest_DoUtimes_001 + * @tc.desc: Test function of UtimesCore::DoUtimes interface for Failed. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ +HWTEST_F(UtimesCoreTest, UtimesCoreTest_DoUtimes_001, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "UtimesCoreTest-begin UtimesCoreTest_DoUtimes_001"; + + string path; + double mtime = -1; + auto res = UtimesCore::DoUtimes(path, mtime); + EXPECT_EQ(res.IsSuccess(), false); + + GTEST_LOG_(INFO) << "UtimesCoreTest-end UtimesCoreTest_DoUtimes_001"; +} + +} // namespace OHOS::FileManagement::ModuleFileIO::Test diff --git a/interfaces/test/unittest/js/mod_fs/properties/xattr_core_mock_test.cpp b/interfaces/test/unittest/js/mod_fs/properties/xattr_core_mock_test.cpp new file mode 100644 index 000000000..e34ff3bdf --- /dev/null +++ b/interfaces/test/unittest/js/mod_fs/properties/xattr_core_mock_test.cpp @@ -0,0 +1,179 @@ +/* + * 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 +#include +#include + +#include "system_mock.h" +#include "xattr_core.h" + +namespace OHOS::FileManagement::ModuleFileIO::Test { +using namespace testing; +using namespace testing::ext; +using namespace std; + +class XattrCoreMockTest : public testing::Test { +public: + static filesystem::path tempFilePath; + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); + static inline shared_ptr sys = nullptr; +}; + +filesystem::path XattrCoreMockTest::tempFilePath; + +void XattrCoreMockTest::SetUpTestCase(void) +{ + GTEST_LOG_(INFO) << "SetUpTestCase"; + tempFilePath = "/data/local/tmp/xattr_test_file.txt"; + ofstream tempfile(tempFilePath); + tempfile << "Test content\n123\n456"; + tempfile.close(); + sys = make_shared(); + System::ins = sys; +} + +void XattrCoreMockTest::TearDownTestCase(void) +{ + GTEST_LOG_(INFO) << "TearDownTestCase"; + filesystem::remove(tempFilePath); + System::ins = nullptr; + sys = nullptr; +} + +void XattrCoreMockTest::SetUp(void) +{ + GTEST_LOG_(INFO) << "SetUp"; +} + +void XattrCoreMockTest::TearDown(void) +{ + GTEST_LOG_(INFO) << "TearDown"; +} + +/** + * @tc.name: XattrCoreMockTest_DoSetXattr_001 + * @tc.desc: Test function of XattrCore::DoSetXattr interface for FAILED. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ +HWTEST_F(XattrCoreMockTest, XattrCoreMockTest_DoSetXattr_001, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "XattrCoreMockTest-begin XattrCoreMockTest_DoSetXattr_001"; + + string path = tempFilePath.string(); + string key = "test_key"; + string value = "test_value"; + + EXPECT_CALL(*sys, setxattr(_, _, _, _, _)).WillOnce(SetErrnoAndReturn(EIO, -1)); + auto ret = XattrCore::DoSetXattr(path, key, value); + EXPECT_FALSE(ret.IsSuccess()); + + GTEST_LOG_(INFO) << "XattrCoreMockTest-end XattrCoreMockTest_DoSetXattr_001"; +} + +/** + * @tc.name: XattrCoreMockTest_DoSetXattr_002 + * @tc.desc: Test function of XattrCore::DoSetXattr interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ +HWTEST_F(XattrCoreMockTest, XattrCoreMockTest_DoSetXattr_002, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "XattrCoreMockTest-begin XattrCoreMockTest_DoSetXattr_002"; + + string path = tempFilePath.string(); + string key = "test_key"; + string value = "test_value"; + + EXPECT_CALL(*sys, setxattr(_, _, _, _, _)).WillOnce(Return(0)); + auto ret = XattrCore::DoSetXattr(path, key, value); + EXPECT_TRUE(ret.IsSuccess()); + + GTEST_LOG_(INFO) << "XattrCoreMockTest-end XattrCoreMockTest_DoSetXattr_002"; +} + +/** + * @tc.name: XattrCoreMockTest_DoGetXattr_001 + * @tc.desc: Test function of XattrCore::DoGetXattr interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ +HWTEST_F(XattrCoreMockTest, XattrCoreMockTest_DoGetXattr_001, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "XattrCoreMockTest-begin XattrCoreMockTest_DoGetXattr_001"; + + string path = tempFilePath.string(); + string key = "test_key"; + + EXPECT_CALL(*sys, getxattr(_, _, _, _)).WillRepeatedly(SetErrnoAndReturn(EIO, -1)); + auto ret = XattrCore::DoGetXattr(path, key); + EXPECT_TRUE(ret.IsSuccess()); + + GTEST_LOG_(INFO) << "XattrCoreMockTest-end XattrCoreMockTest_DoGetXattr_001"; +} + +/** + * @tc.name: XattrCoreMockTest_DoGetXattr_002 + * @tc.desc: Test function of XattrCore::DoGetXattr interface for FAILED. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ +HWTEST_F(XattrCoreMockTest, XattrCoreMockTest_DoGetXattr_002, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "XattrCoreMockTest-begin XattrCoreMockTest_DoGetXattr_002"; + + string path = tempFilePath.string(); + string key = "test_key"; + + EXPECT_CALL(*sys, getxattr(_, _, _, _)).WillOnce(Return(1)).WillOnce(SetErrnoAndReturn(EIO, -1)); + auto ret = XattrCore::DoGetXattr(path, key); + EXPECT_FALSE(ret.IsSuccess()); + + GTEST_LOG_(INFO) << "XattrCoreMockTest-end XattrCoreMockTest_DoGetXattr_002"; +} + +/** + * @tc.name: XattrCoreMockTest_DoGetXattr_003 + * @tc.desc: Test function of XattrCore::DoGetXattr interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ +HWTEST_F(XattrCoreMockTest, XattrCoreMockTest_DoGetXattr_003, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "XattrCoreMockTest-begin XattrCoreMockTest_DoGetXattr_003"; + + string path = tempFilePath.string(); + string key = "test_key"; + + EXPECT_CALL(*sys, getxattr(_, _, _, _)).WillOnce(Return(1)).WillOnce(Return(1)); + auto ret = XattrCore::DoGetXattr(path, key); + EXPECT_TRUE(ret.IsSuccess()); + + GTEST_LOG_(INFO) << "XattrCoreMockTest-end XattrCoreMockTest_DoGetXattr_003"; +} + +} // namespace OHOS::FileManagement::ModuleFileIO::Test \ No newline at end of file diff --git a/interfaces/test/unittest/js/mod_fs/properties/xattr_core_test.cpp b/interfaces/test/unittest/js/mod_fs/properties/xattr_core_test.cpp new file mode 100644 index 000000000..febfd1c1e --- /dev/null +++ b/interfaces/test/unittest/js/mod_fs/properties/xattr_core_test.cpp @@ -0,0 +1,143 @@ +/* + * 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 +#include + +#include "xattr_core.h" + +#define MAX_LEN 4096 + +namespace OHOS::FileManagement::ModuleFileIO::Test { +using namespace testing; +using namespace testing::ext; +using namespace std; + +class XattrCoreTest : public testing::Test { +public: + static filesystem::path tempFilePath; + static void SetUpTestCase(void); + static void TearDownTestCase(void); + void SetUp(); + void TearDown(); +}; + +filesystem::path XattrCoreTest::tempFilePath; + +void XattrCoreTest::SetUpTestCase(void) +{ + tempFilePath = "/data/local/tmp/xattr_test_file.txt"; + ofstream tempfile(tempFilePath); + tempfile << "Test content\n123\n456"; + tempfile.close(); + GTEST_LOG_(INFO) << "SetUpTestCase"; +} + +void XattrCoreTest::TearDownTestCase(void) +{ + filesystem::remove(tempFilePath); + GTEST_LOG_(INFO) << "TearDownTestCase"; +} + +void XattrCoreTest::SetUp(void) +{ + GTEST_LOG_(INFO) << "SetUp"; +} + +void XattrCoreTest::TearDown(void) +{ + GTEST_LOG_(INFO) << "TearDown"; +} + +/** + * @tc.name: XattrCoreTest_DoSetXattr_001 + * @tc.desc: Test function of XattrCore::DoSetXattr interface for FAILED. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ +HWTEST_F(XattrCoreTest, XattrCoreTest_DoSetXattr_001, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "XattrCoreTest-begin XattrCoreTest_DoSetXattr_001"; + + string path = tempFilePath.string(); + std::string key = "test_key"; + std::string value(MAX_LEN + 1, 'a'); + + auto ret = XattrCore::DoSetXattr(path, key, value); + + EXPECT_FALSE(ret.IsSuccess()); + auto err = ret.GetError(); + int errCode = err.GetErrNo(); + EXPECT_EQ(errCode, 13900020); + auto msg = err.GetErrMsg(); + EXPECT_EQ(msg, "Invalid argument"); + + GTEST_LOG_(INFO) << "XattrCoreTest-end XattrCoreTest_DoSetXattr_001"; +} + +/** + * @tc.name: XattrCoreTest_DoSetXattr_002 + * @tc.desc: Test function of XattrCore::DoSetXattr interface for FAILED. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ +HWTEST_F(XattrCoreTest, XattrCoreTest_DoSetXattr_002, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "XattrCoreTest-begin XattrCoreTest_DoSetXattr_002"; + + string path = tempFilePath.string(); + std::string key(MAX_LEN + 1, 'a'); + std::string value = "test_value"; + + auto ret = XattrCore::DoSetXattr(path, key, value); + + EXPECT_FALSE(ret.IsSuccess()); + auto err = ret.GetError(); + int errCode = err.GetErrNo(); + EXPECT_EQ(errCode, 13900020); + auto msg = err.GetErrMsg(); + EXPECT_EQ(msg, "Invalid argument"); + + GTEST_LOG_(INFO) << "XattrCoreTest-end XattrCoreTest_DoSetXattr_002"; +} + +/** + * @tc.name: XattrCoreTest_DoGetXattr_001 + * @tc.desc: Test function of XattrCore::DoGetXattr interface for SUCCESS. + * @tc.size: MEDIUM + * @tc.type: FUNC + * @tc.level Level 1 + */ +HWTEST_F(XattrCoreTest, XattrCoreTest_DoGetXattr_001, testing::ext::TestSize.Level1) +{ + GTEST_LOG_(INFO) << "XattrCoreTest-begin XattrCoreTest_DoGetXattr_001"; + + std::string path = "/data/local/tmp/nonexistent_file"; + string key = "test_key"; + + auto ret = XattrCore::DoGetXattr(path, key); + + ASSERT_TRUE(ret.IsSuccess()); + EXPECT_EQ(ret.GetData().value(), ""); + + GTEST_LOG_(INFO) << "XattrCoreTest-end XattrCoreTest_DoGetXattr_001"; +} + +} // namespace OHOS::FileManagement::ModuleFileIO::Test \ No newline at end of file -- Gitee From 9098fc0fb166a55b087e95de5b44610cdb7e80a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=B6=E9=87=91=E6=B2=9B?= Date: Mon, 28 Jul 2025 11:42:14 +0800 Subject: [PATCH 2/2] =?UTF-8?q?symlink&utimes=E5=8A=9F=E8=83=BD=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 陶金沛 Change-Id: Iad56e4f0cc7df44e0d5b8614769fb69b3faeb833 --- .../kits/js/src/mod_fs/properties/ani/symlink_ani.h | 6 +++--- .../kits/js/src/mod_fs/properties/ani/utimes_ani.h | 6 +++--- .../properties/dfs_listener/file_dfs_listener_stub.cpp | 7 ++++--- .../properties/dfs_listener/file_dfs_listener_stub.h | 8 ++++---- .../kits/js/src/mod_fs/properties/symlink_core.h | 2 +- .../kits/js/src/mod_fs/properties/xattr_core.cpp | 4 ++-- .../js/mod_fs/properties/symlink_core_mock_test.cpp | 2 +- .../js/mod_fs/properties/xattr_core_mock_test.cpp | 10 +++++----- 8 files changed, 23 insertions(+), 22 deletions(-) diff --git a/interfaces/kits/js/src/mod_fs/properties/ani/symlink_ani.h b/interfaces/kits/js/src/mod_fs/properties/ani/symlink_ani.h index 6ba3abb55..3c8c16ca2 100644 --- a/interfaces/kits/js/src/mod_fs/properties/ani/symlink_ani.h +++ b/interfaces/kits/js/src/mod_fs/properties/ani/symlink_ani.h @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef INTERFACES_KITS_JS_SRC_MOD_FS_SYMLINK_ANI_H -#define INTERFACES_KITS_JS_SRC_MOD_FS_SYMLINK_ANI_H +#ifndef INTERFACES_KITS_JS_SRC_MOD_FS_PROPERTIES_ANI_SYMLINK_ANI_H +#define INTERFACES_KITS_JS_SRC_MOD_FS_PROPERTIES_ANI_SYMLINK_ANI_H #include @@ -32,4 +32,4 @@ public: } // namespace FileManagement } // namespace OHOS -#endif // INTERFACES_KITS_JS_SRC_MOD_FS_SYMLINK_ANI_H \ No newline at end of file +#endif // INTERFACES_KITS_JS_SRC_MOD_FS_PROPERTIES_ANI_SYMLINK_ANI_H \ No newline at end of file diff --git a/interfaces/kits/js/src/mod_fs/properties/ani/utimes_ani.h b/interfaces/kits/js/src/mod_fs/properties/ani/utimes_ani.h index 118f7d25a..b07dd421d 100644 --- a/interfaces/kits/js/src/mod_fs/properties/ani/utimes_ani.h +++ b/interfaces/kits/js/src/mod_fs/properties/ani/utimes_ani.h @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef INTERFACES_KITS_JS_SRC_MOD_FS_UTIMES_ANI_H -#define INTERFACES_KITS_JS_SRC_MOD_FS_UTIMES_ANI_H +#ifndef INTERFACES_KITS_JS_SRC_MOD_FS_PROPERTIES_ANI_UTIMES_ANI_H +#define INTERFACES_KITS_JS_SRC_MOD_FS_PROPERTIES_ANI_UTIMES_ANI_H #include @@ -33,4 +33,4 @@ public: } // namespace FileManagement } // namespace OHOS -#endif // INTERFACES_KITS_JS_SRC_MOD_FS_UTIMES_ANI_H \ No newline at end of file +#endif // INTERFACES_KITS_JS_SRC_MOD_FS_PROPERTIES_ANI_UTIMES_ANI_H \ No newline at end of file diff --git a/interfaces/kits/js/src/mod_fs/properties/dfs_listener/file_dfs_listener_stub.cpp b/interfaces/kits/js/src/mod_fs/properties/dfs_listener/file_dfs_listener_stub.cpp index a77a6ff26..e996e7187 100644 --- a/interfaces/kits/js/src/mod_fs/properties/dfs_listener/file_dfs_listener_stub.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/dfs_listener/file_dfs_listener_stub.cpp @@ -12,8 +12,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -#include "file_dfs_listener_stub.h" + #include "file_dfs_listener_interface_code.h" +#include "file_dfs_listener_stub.h" #include "filemgmt_libhilog.h" namespace OHOS { @@ -53,12 +54,12 @@ int32_t FileDfsListenerStub::HandleOnStatus(MessageParcel &data, MessageParcel & { std::string networkId; if (!data.ReadString(networkId)) { - HILOGE("read networkId failed"); + HILOGE("Read networkId failed"); return E_INVAL_ARG; } int32_t status; if (!data.ReadInt32(status)) { - HILOGE("read status failed"); + HILOGE("Read status failed"); return E_INVAL_ARG; } if (networkId.empty() || status < 0) { diff --git a/interfaces/kits/js/src/mod_fs/properties/dfs_listener/file_dfs_listener_stub.h b/interfaces/kits/js/src/mod_fs/properties/dfs_listener/file_dfs_listener_stub.h index bafb64cad..3b5f782e6 100644 --- a/interfaces/kits/js/src/mod_fs/properties/dfs_listener/file_dfs_listener_stub.h +++ b/interfaces/kits/js/src/mod_fs/properties/dfs_listener/file_dfs_listener_stub.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * 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 @@ -13,8 +13,8 @@ * limitations under the License. */ -#ifndef FILEMANAGEMENT_FILE_API_FILE_DFS_LISTENER_STUB_H -#define FILEMANAGEMENT_FILE_API_FILE_DFS_LISTENER_STUB_H +#ifndef INTERFACES_KITS_JS_SRC_MOD_FS_PROPERTIES_DFS_LISTENER_FILE_DFS_LISTENER_STUB_H +#define INTERFACES_KITS_JS_SRC_MOD_FS_PROPERTIES_DFS_LISTENER_FILE_DFS_LISTENER_STUB_H #include #include "i_file_dfs_listener.h" @@ -43,4 +43,4 @@ private: } // namespace FileManagement } // namespace OHOS -#endif // FILEMANAGEMENT_FILE_API_FILE_DFS_LISTENER_STUB_H \ No newline at end of file +#endif // INTERFACES_KITS_JS_SRC_MOD_FS_PROPERTIES_DFS_LISTENER_FILE_DFS_LISTENER_STUB_H \ No newline at end of file diff --git a/interfaces/kits/js/src/mod_fs/properties/symlink_core.h b/interfaces/kits/js/src/mod_fs/properties/symlink_core.h index 223c8b683..4eaef88d9 100644 --- a/interfaces/kits/js/src/mod_fs/properties/symlink_core.h +++ b/interfaces/kits/js/src/mod_fs/properties/symlink_core.h @@ -25,7 +25,7 @@ class SymlinkCore final { public: static FsResult DoSymlink(const string &target, const string &srcPath); }; -const std::string PROCEDURE_RMDIRENT_NAME = "FileIOSymLink"; + } // namespace ModuleFileIO } // namespace FileManagement } // namespace OHOS diff --git a/interfaces/kits/js/src/mod_fs/properties/xattr_core.cpp b/interfaces/kits/js/src/mod_fs/properties/xattr_core.cpp index ba22e42c7..03ad384d2 100644 --- a/interfaces/kits/js/src/mod_fs/properties/xattr_core.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/xattr_core.cpp @@ -32,7 +32,7 @@ static bool IsIllegalXattr(const char *key, const char *value) { bool isIllegalKey = strnlen(key, MAX_XATTR_SIZE + 1) > MAX_XATTR_SIZE; if (isIllegalKey) { - HILOGE("key is too long"); + HILOGE("Key is too long"); } bool isIllegalValue = strnlen(value, MAX_XATTR_SIZE + 1) > MAX_XATTR_SIZE; if (isIllegalValue) { @@ -65,7 +65,7 @@ FsResult XattrCore::DoSetXattr(const string &path, const string &key, cons return FsResult::Error(EINVAL); } if (setxattr(path.c_str(), key.c_str(), value.c_str(), strnlen(value.c_str(), MAX_XATTR_SIZE), 0) < 0) { - HILOGE("setxattr fail, errno is %{public}d", errno); + HILOGE("Setxattr fail, errno is %{public}d", errno); return FsResult::Error(errno); } return FsResult::Success(); diff --git a/interfaces/test/unittest/js/mod_fs/properties/symlink_core_mock_test.cpp b/interfaces/test/unittest/js/mod_fs/properties/symlink_core_mock_test.cpp index dd6e4b43b..0869c89e1 100644 --- a/interfaces/test/unittest/js/mod_fs/properties/symlink_core_mock_test.cpp +++ b/interfaces/test/unittest/js/mod_fs/properties/symlink_core_mock_test.cpp @@ -36,7 +36,7 @@ public: void SymlinkCoreMockTest::SetUpTestCase(void) { GTEST_LOG_(INFO) << "SetUpTestCase"; - uvMock = std::make_shared(); + uvMock = make_shared(); Uvfs::ins = uvMock; } diff --git a/interfaces/test/unittest/js/mod_fs/properties/xattr_core_mock_test.cpp b/interfaces/test/unittest/js/mod_fs/properties/xattr_core_mock_test.cpp index e34ff3bdf..c9e8869ac 100644 --- a/interfaces/test/unittest/js/mod_fs/properties/xattr_core_mock_test.cpp +++ b/interfaces/test/unittest/js/mod_fs/properties/xattr_core_mock_test.cpp @@ -76,7 +76,7 @@ void XattrCoreMockTest::TearDown(void) * @tc.type: FUNC * @tc.level Level 1 */ -HWTEST_F(XattrCoreMockTest, XattrCoreMockTest_DoSetXattr_001, testing::ext::TestSize.Level1) +HWTEST_F(XattrCoreMockTest, XattrCoreMockTest_DoSetXattr_001, TestSize.Level1) { GTEST_LOG_(INFO) << "XattrCoreMockTest-begin XattrCoreMockTest_DoSetXattr_001"; @@ -98,7 +98,7 @@ HWTEST_F(XattrCoreMockTest, XattrCoreMockTest_DoSetXattr_001, testing::ext::Test * @tc.type: FUNC * @tc.level Level 1 */ -HWTEST_F(XattrCoreMockTest, XattrCoreMockTest_DoSetXattr_002, testing::ext::TestSize.Level1) +HWTEST_F(XattrCoreMockTest, XattrCoreMockTest_DoSetXattr_002, TestSize.Level1) { GTEST_LOG_(INFO) << "XattrCoreMockTest-begin XattrCoreMockTest_DoSetXattr_002"; @@ -120,7 +120,7 @@ HWTEST_F(XattrCoreMockTest, XattrCoreMockTest_DoSetXattr_002, testing::ext::Test * @tc.type: FUNC * @tc.level Level 1 */ -HWTEST_F(XattrCoreMockTest, XattrCoreMockTest_DoGetXattr_001, testing::ext::TestSize.Level1) +HWTEST_F(XattrCoreMockTest, XattrCoreMockTest_DoGetXattr_001, TestSize.Level1) { GTEST_LOG_(INFO) << "XattrCoreMockTest-begin XattrCoreMockTest_DoGetXattr_001"; @@ -141,7 +141,7 @@ HWTEST_F(XattrCoreMockTest, XattrCoreMockTest_DoGetXattr_001, testing::ext::Test * @tc.type: FUNC * @tc.level Level 1 */ -HWTEST_F(XattrCoreMockTest, XattrCoreMockTest_DoGetXattr_002, testing::ext::TestSize.Level1) +HWTEST_F(XattrCoreMockTest, XattrCoreMockTest_DoGetXattr_002, TestSize.Level1) { GTEST_LOG_(INFO) << "XattrCoreMockTest-begin XattrCoreMockTest_DoGetXattr_002"; @@ -162,7 +162,7 @@ HWTEST_F(XattrCoreMockTest, XattrCoreMockTest_DoGetXattr_002, testing::ext::Test * @tc.type: FUNC * @tc.level Level 1 */ -HWTEST_F(XattrCoreMockTest, XattrCoreMockTest_DoGetXattr_003, testing::ext::TestSize.Level1) +HWTEST_F(XattrCoreMockTest, XattrCoreMockTest_DoGetXattr_003, TestSize.Level1) { GTEST_LOG_(INFO) << "XattrCoreMockTest-begin XattrCoreMockTest_DoGetXattr_003"; -- Gitee