From 6e86e7733385b1522ee9bca11875556788bc5447 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=A8=E9=91=AB?= Date: Wed, 5 Mar 2025 12:12:32 +0800 Subject: [PATCH 1/5] =?UTF-8?q?close=E6=A0=B8=E5=BF=83=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 周鑫 --- .../js/src/mod_fs/properties/close_core.cpp | 64 +++++++++++++++++++ .../js/src/mod_fs/properties/close_core.h | 33 ++++++++++ 2 files changed, 97 insertions(+) create mode 100644 interfaces/kits/js/src/mod_fs/properties/close_core.cpp create mode 100644 interfaces/kits/js/src/mod_fs/properties/close_core.h diff --git a/interfaces/kits/js/src/mod_fs/properties/close_core.cpp b/interfaces/kits/js/src/mod_fs/properties/close_core.cpp new file mode 100644 index 000000000..dc50abc56 --- /dev/null +++ b/interfaces/kits/js/src/mod_fs/properties/close_core.cpp @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2023 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 "close_core.h" +#include "filemgmt_libhilog.h" +#include "file_utils.h" + +namespace OHOS::FileManagement::ModuleFileIO +{ +using namespace std; + +static int32_t CloseFd(int fd) +{ + std::unique_ptr close_req = {new uv_fs_t, + FsUtils::FsReqCleanup}; + if (!close_req) { + HILOGE("Failed to request heap memory."); + return ENOMEM; + } + int ret = uv_fs_close(nullptr, close_req.get(), fd, nullptr); + if (ret < 0) { + HILOGE("Failed to close file with ret: %{public}d", ret); + return ret; + } + return ERRNO_NOERR; +} + +static bool ValidFd(const int32_t &fd) +{ + if (fd < 0) { + HILOGE("Invalid fd"); + return false; + } + return true; +} + +FsResult CloseCore::DoClose(const int32_t &fd) +{ + if (ValidFd(fd)) { + return FsResult::Error(EINVAL); + } + auto err = CloseFd(fd); + if (err) { + FsResult::Error(err); + } + return FsResult::Success(); +} +} // namespace OHOS::FileManagement::ModuleFileIO diff --git a/interfaces/kits/js/src/mod_fs/properties/close_core.h b/interfaces/kits/js/src/mod_fs/properties/close_core.h new file mode 100644 index 000000000..f60b16574 --- /dev/null +++ b/interfaces/kits/js/src/mod_fs/properties/close_core.h @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2023 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_CLOSE_CORE_H +#define INTERFACES_KITS_JS_SRC_MOD_FS_PROPERTIES_CLOSE_CORE_H + +#include "fs_utils.h" +#include "fs_result.h" +#include "filemgmt_libfs.h" + +namespace OHOS::FileManagement::ModuleFileIO { + +class CloseCore final { +public: + static FsResult DoClose(const int32_t &fd); +}; + +const std::string PROCEDURE_CLOSE_NAME = "FileIOClose"; +} // namespace OHOS::FileManagement::ModuleFileIO + +#endif // INTERFACES_KITS_JS_SRC_MOD_FS_PROPERTIES_CLOSE_CORE_H \ No newline at end of file -- Gitee From cd4f850ee0e87862239bc2d4fe05e83f560640a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=A8=E9=91=AB?= Date: Wed, 5 Mar 2025 12:14:11 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E6=97=B6=E9=97=B4=E6=A0=87=E7=AD=BE?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 周鑫 --- interfaces/kits/js/src/mod_fs/properties/close.cpp | 2 +- interfaces/kits/js/src/mod_fs/properties/close_core.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/interfaces/kits/js/src/mod_fs/properties/close.cpp b/interfaces/kits/js/src/mod_fs/properties/close.cpp index 0ca2fe8e5..570bce793 100755 --- a/interfaces/kits/js/src/mod_fs/properties/close.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/close.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 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 diff --git a/interfaces/kits/js/src/mod_fs/properties/close_core.h b/interfaces/kits/js/src/mod_fs/properties/close_core.h index f60b16574..32ab31bad 100644 --- a/interfaces/kits/js/src/mod_fs/properties/close_core.h +++ b/interfaces/kits/js/src/mod_fs/properties/close_core.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 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 -- Gitee From ef6f347eefb198427792a0d664522115f71dd295 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=A8=E9=91=AB?= Date: Wed, 5 Mar 2025 14:28:49 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E6=97=B6=E9=97=B4=E6=88=B3=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 周鑫 --- interfaces/kits/js/src/mod_fs/properties/close.cpp | 2 +- interfaces/kits/js/src/mod_fs/properties/close_core.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/interfaces/kits/js/src/mod_fs/properties/close.cpp b/interfaces/kits/js/src/mod_fs/properties/close.cpp index 570bce793..0ca2fe8e5 100755 --- a/interfaces/kits/js/src/mod_fs/properties/close.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/close.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2025 Huawei Device Co., Ltd. + * Copyright (c) 2023 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 diff --git a/interfaces/kits/js/src/mod_fs/properties/close_core.cpp b/interfaces/kits/js/src/mod_fs/properties/close_core.cpp index dc50abc56..e95881baf 100644 --- a/interfaces/kits/js/src/mod_fs/properties/close_core.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/close_core.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 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 -- Gitee From e354f3489f3854af7d7898bf88854270dc37bc54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=A8=E9=91=AB?= Date: Wed, 5 Mar 2025 06:35:58 +0000 Subject: [PATCH 4/5] update interfaces/kits/js/src/mod_fs/properties/close_core.cpp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 周鑫 --- interfaces/kits/js/src/mod_fs/properties/close_core.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interfaces/kits/js/src/mod_fs/properties/close_core.cpp b/interfaces/kits/js/src/mod_fs/properties/close_core.cpp index e95881baf..8ba13fe02 100644 --- a/interfaces/kits/js/src/mod_fs/properties/close_core.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/close_core.cpp @@ -52,7 +52,7 @@ static bool ValidFd(const int32_t &fd) FsResult CloseCore::DoClose(const int32_t &fd) { - if (ValidFd(fd)) { + if (!ValidFd(fd)) { return FsResult::Error(EINVAL); } auto err = CloseFd(fd); -- Gitee From 012055eb816a583326b6c154ce528cf0eec26f6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=A8=E9=91=AB?= Date: Wed, 5 Mar 2025 16:23:26 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 周鑫 --- .../kits/js/src/mod_fs/properties/close_core.cpp | 11 +++++------ interfaces/kits/js/src/mod_fs/properties/close_core.h | 2 +- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/interfaces/kits/js/src/mod_fs/properties/close_core.cpp b/interfaces/kits/js/src/mod_fs/properties/close_core.cpp index 8ba13fe02..e93ec88cc 100644 --- a/interfaces/kits/js/src/mod_fs/properties/close_core.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/close_core.cpp @@ -13,22 +13,21 @@ * limitations under the License. */ +#include "close_core.h" + #include #include #include -#include "close_core.h" -#include "filemgmt_libhilog.h" #include "file_utils.h" +#include "filemgmt_libhilog.h" -namespace OHOS::FileManagement::ModuleFileIO -{ +namespace OHOS::FileManagement::ModuleFileIO { using namespace std; static int32_t CloseFd(int fd) { - std::unique_ptr close_req = {new uv_fs_t, - FsUtils::FsReqCleanup}; + std::unique_ptr close_req = { new uv_fs_t, FsUtils::FsReqCleanup }; if (!close_req) { HILOGE("Failed to request heap memory."); return ENOMEM; diff --git a/interfaces/kits/js/src/mod_fs/properties/close_core.h b/interfaces/kits/js/src/mod_fs/properties/close_core.h index 32ab31bad..1bbdd1c31 100644 --- a/interfaces/kits/js/src/mod_fs/properties/close_core.h +++ b/interfaces/kits/js/src/mod_fs/properties/close_core.h @@ -16,9 +16,9 @@ #ifndef INTERFACES_KITS_JS_SRC_MOD_FS_PROPERTIES_CLOSE_CORE_H #define INTERFACES_KITS_JS_SRC_MOD_FS_PROPERTIES_CLOSE_CORE_H +#include "filemgmt_libfs.h" #include "fs_utils.h" #include "fs_result.h" -#include "filemgmt_libfs.h" namespace OHOS::FileManagement::ModuleFileIO { -- Gitee