From a4a9d4b703ac2baa935b715687d3aa952f03a2b7 Mon Sep 17 00:00:00 2001 From: 18721213663 Date: Thu, 23 Mar 2023 18:09:39 +0800 Subject: [PATCH] bugfix_fs_read&write_offset Signed-off-by: 18721213663 --- .../src/mod_fs/properties/prop_n_exporter.cpp | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/interfaces/kits/js/src/mod_fs/properties/prop_n_exporter.cpp b/interfaces/kits/js/src/mod_fs/properties/prop_n_exporter.cpp index 606e8d144..5f900abf4 100644 --- a/interfaces/kits/js/src/mod_fs/properties/prop_n_exporter.cpp +++ b/interfaces/kits/js/src/mod_fs/properties/prop_n_exporter.cpp @@ -318,6 +318,9 @@ napi_value PropNExporter::ReadSync(napi_env env, napi_callback_info info) NError(EINVAL).ThrowErr(env); return nullptr; } + if (!hasOffset) { + offset = -1; + } void *buf = nullptr; int64_t len = 0; @@ -331,7 +334,6 @@ napi_value PropNExporter::ReadSync(napi_env env, napi_callback_info info) return nullptr; } - ssize_t actLen; uv_buf_t buffer = uv_buf_init(static_cast(buf), len); std::unique_ptr read_req = { new uv_fs_t, CommonFunc::fs_req_cleanup }; @@ -346,8 +348,8 @@ napi_value PropNExporter::ReadSync(napi_env env, napi_callback_info info) NError(errno).ThrowErr(env); return nullptr; } - actLen = ret; - return NVal::CreateInt64(env, actLen).val_; + + return NVal::CreateInt64(env, ret).val_; } static NError ReadExec(shared_ptr arg, char *buf, size_t len, int fd, size_t offset) @@ -397,6 +399,9 @@ napi_value PropNExporter::Read(napi_env env, napi_callback_info info) NError(EINVAL).ThrowErr(env); return nullptr; } + if (!hasOffset) { + offset = -1; + } auto arg = make_shared(NVal(env, funcArg[NARG_POS::SECOND])); if (!arg) { @@ -481,6 +486,9 @@ napi_value PropNExporter::Write(napi_env env, napi_callback_info info) NError(EINVAL).ThrowErr(env); return nullptr; } + if (!hasOffset) { + offset = -1; + } auto arg = make_shared(move(bufGuard)); if (!arg) { @@ -548,8 +556,10 @@ napi_value PropNExporter::WriteSync(napi_env env, napi_callback_info info) HILOGE("Failed to resolve buf and options"); return nullptr; } + if (!hasOffset) { + offset = -1; + } - ssize_t writeLen; uv_buf_t buffer = uv_buf_init(static_cast(buf), len); std::unique_ptr write_req = { new uv_fs_t, CommonFunc::fs_req_cleanup }; @@ -564,8 +574,8 @@ napi_value PropNExporter::WriteSync(napi_env env, napi_callback_info info) NError(errno).ThrowErr(env); return nullptr; } - writeLen = ret; - return NVal::CreateInt64(env, writeLen).val_; + + return NVal::CreateInt64(env, ret).val_; } bool PropNExporter::Export() -- Gitee