From 5f9f452d4ae3f1ea00ec69c98e3d4ec500e1a18c Mon Sep 17 00:00:00 2001 From: 18721213663 Date: Tue, 28 Mar 2023 21:02:38 +0800 Subject: [PATCH] test_330 Signed-off-by: 18721213663 --- .../kits/js/src/common/file_helper/fd_guard.cpp | 15 ++++++++++++++- .../kits/js/src/common/file_helper/fd_guard.h | 2 +- .../kits/js/src/mod_fs/class_file/file_entity.h | 2 ++ .../kits/js/src/mod_fs/properties/close.cpp | 17 +++++++++++++++++ 4 files changed, 34 insertions(+), 2 deletions(-) diff --git a/interfaces/kits/js/src/common/file_helper/fd_guard.cpp b/interfaces/kits/js/src/common/file_helper/fd_guard.cpp index 6959b45a5..8d0924142 100644 --- a/interfaces/kits/js/src/common/file_helper/fd_guard.cpp +++ b/interfaces/kits/js/src/common/file_helper/fd_guard.cpp @@ -15,6 +15,10 @@ #include "fd_guard.h" +#include +#include +#include +#include #include #include "../log.h" @@ -43,11 +47,20 @@ FDGuard &FDGuard::operator=(FDGuard &&fdg) FDGuard::~FDGuard() { + HILOGI("~FDGuard"); if (fd_ >= 0 && fd_ <= STDERR_FILENO) { HILOGI("~FDGuard, fd_ = %{public}d", fd_); } if (fd_ >= 0 && autoClose_) { - close(fd_); + HILOGI("~FDGuard, fd_ = %{public}d", fd_); + struct stat buf; + if (fstat(fd_, &buf) == 0) { + HILOGI("Unlock succeeded inode = %{public}" PRIu64, buf.st_ino); + } else { + HILOGI("Failed to get inode number"); + } + int ret = close(fd_); + HILOGE("fd_ = %{public}d, errno = %{public}d", fd_, ret); } } diff --git a/interfaces/kits/js/src/common/file_helper/fd_guard.h b/interfaces/kits/js/src/common/file_helper/fd_guard.h index 07c27b19d..da1c11614 100644 --- a/interfaces/kits/js/src/common/file_helper/fd_guard.h +++ b/interfaces/kits/js/src/common/file_helper/fd_guard.h @@ -40,7 +40,7 @@ public: private: int fd_ = -1; - bool autoClose_ = true; + bool autoClose_ = false; }; } // namespace DistributedFS } // namespace OHOS diff --git a/interfaces/kits/js/src/mod_fs/class_file/file_entity.h b/interfaces/kits/js/src/mod_fs/class_file/file_entity.h index 7af17996a..b6d58cbfe 100644 --- a/interfaces/kits/js/src/mod_fs/class_file/file_entity.h +++ b/interfaces/kits/js/src/mod_fs/class_file/file_entity.h @@ -35,6 +35,7 @@ struct FileEntity { virtual ~FileEntity() { + HILOGI("~FileEntity"); if (!fd_.get()) { return; } @@ -42,6 +43,7 @@ struct FileEntity { int ret = flock(fd, LOCK_UN); if (ret == 0) { struct stat buf; + HILOGI("~FileEntity File name: %{public}s", path_.c_str()); if (fstat(fd, &buf) == 0) { HILOGI("Unlock succeeded inode = %{public}" PRIu64, buf.st_ino); } else { diff --git a/interfaces/kits/js/src/mod_fs/properties/close.cpp b/interfaces/kits/js/src/mod_fs/properties/close.cpp index 195feb69d..34e8479b0 100644 --- a/interfaces/kits/js/src/mod_fs/properties/close.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/close.cpp @@ -15,6 +15,9 @@ #include "close.h" +#include +#include +#include #include #include #include @@ -58,6 +61,7 @@ static tuple ParseJsOperand(napi_env env, napi_value fdOrFileF napi_value Close::Sync(napi_env env, napi_callback_info info) { + HILOGI("start closesync"); NFuncArg funcArg(env, info); if (!funcArg.InitArgs(NARG_CNT::ONE)) { HILOGE("Number of arguments unmatched"); @@ -73,6 +77,12 @@ napi_value Close::Sync(napi_env env, napi_callback_info info) } if (fileStruct.isFd) { + struct stat buf; + if (fstat(fileStruct.fd, &buf) == 0) { + HILOGI("Unlock succeeded inode = %{public}" PRIu64, buf.st_ino); + } else { + HILOGI("Failed to get inode number"); + } std::unique_ptr close_req = { new uv_fs_t, CommonFunc::fs_req_cleanup }; if (!close_req) { @@ -96,6 +106,7 @@ napi_value Close::Sync(napi_env env, napi_callback_info info) napi_value Close::Async(napi_env env, napi_callback_info info) { + HILOGI("start close"); NFuncArg funcArg(env, info); if (!funcArg.InitArgs(NARG_CNT::ONE, NARG_CNT::TWO)) { HILOGE("Number of arguments unmatched"); @@ -112,6 +123,12 @@ napi_value Close::Async(napi_env env, napi_callback_info info) auto cbExec = [fileStruct = fileStruct]() -> NError { if (fileStruct.isFd) { + struct stat buf; + if (fstat(fileStruct.fd, &buf) == 0) { + HILOGI("Unlock succeeded inode = %{public}" PRIu64, buf.st_ino); + } else { + HILOGI("Failed to get inode number"); + } std::unique_ptr close_req = { new uv_fs_t, CommonFunc::fs_req_cleanup }; if (!close_req) { -- Gitee