From ac404f0346baf7e3bc0b7fc1bb7730c9099b1e06 Mon Sep 17 00:00:00 2001 From: 18721213663 Date: Sun, 23 Apr 2023 15:04:19 +0800 Subject: [PATCH] bugfix_file_autoclose Signed-off-by: 18721213663 --- interfaces/kits/js/src/mod_fs/properties/close.cpp | 7 +++++++ interfaces/kits/js/src/mod_fs/properties/open.cpp | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/interfaces/kits/js/src/mod_fs/properties/close.cpp b/interfaces/kits/js/src/mod_fs/properties/close.cpp index 05cf915c4..76b639afe 100755 --- a/interfaces/kits/js/src/mod_fs/properties/close.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/close.cpp @@ -98,6 +98,11 @@ napi_value Close::Sync(napi_env env, napi_callback_info info) return nullptr; } } else { + auto err = CloseFd(fileStruct.fileEntity->fd_->GetFD()); + if (err) { + err.ThrowErr(env); + return nullptr; + } auto fp = NClass::RemoveEntityOfFinal(env, funcArg[NARG_POS::FIRST]); if (!fp) { NError(EINVAL).ThrowErr(env); @@ -125,6 +130,8 @@ napi_value Close::Async(napi_env env, napi_callback_info info) } if (!fileStruct.isFd) { + fileStruct.fd = fileStruct.fileEntity->fd_->GetFD(); + fileStruct.isFd = true; auto fp = NClass::RemoveEntityOfFinal(env, funcArg[NARG_POS::FIRST]); if (!fp) { NError(EINVAL).ThrowErr(env); diff --git a/interfaces/kits/js/src/mod_fs/properties/open.cpp b/interfaces/kits/js/src/mod_fs/properties/open.cpp index 822e9eaf6..988280f81 100644 --- a/interfaces/kits/js/src/mod_fs/properties/open.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/open.cpp @@ -81,7 +81,7 @@ static NVal InstantiateFile(napi_env env, int fd, string pathOrUri, bool isUri) } return NVal(); } - auto fdg = make_unique(fd, true); + auto fdg = make_unique(fd, false); fileEntity->fd_.swap(fdg); if (isUri) { fileEntity->path_ = ""; -- Gitee