From aeed6c3f9716834474469e1e83135d0f18980b6e Mon Sep 17 00:00:00 2001 From: 18721213663 Date: Thu, 13 Apr 2023 11:09:04 +0800 Subject: [PATCH] bugfix_fileio_mode_init Signed-off-by: 18721213663 --- .../js/src/mod_environment/environment_napi.cpp | 15 ++++++++++++++- .../kits/js/src/mod_fileio/properties/open.cpp | 8 ++++---- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/interfaces/kits/js/src/mod_environment/environment_napi.cpp b/interfaces/kits/js/src/mod_environment/environment_napi.cpp index cb03433e7..f8ef720e2 100644 --- a/interfaces/kits/js/src/mod_environment/environment_napi.cpp +++ b/interfaces/kits/js/src/mod_environment/environment_napi.cpp @@ -31,7 +31,20 @@ napi_value EnvironmentExport(napi_env env, napi_value exports) return exports; } -NAPI_MODULE(environment, EnvironmentExport) +static napi_module _module = { + .nm_version = 1, + .nm_flags = 0, + .nm_filename = nullptr, + .nm_register_func = EnvironmentExport, + .nm_modname = "file.environment", + .nm_priv = ((void *)0), + .reserved = {0} +}; + +extern "C" __attribute__((constructor)) void RegisterModule(void) +{ + napi_module_register(&_module); +} } // namespace ModuleEnvironment } // namespace FileManagement } // namespace OHOS \ No newline at end of file diff --git a/interfaces/kits/js/src/mod_fileio/properties/open.cpp b/interfaces/kits/js/src/mod_fileio/properties/open.cpp index a024642b2..cc84fd971 100644 --- a/interfaces/kits/js/src/mod_fileio/properties/open.cpp +++ b/interfaces/kits/js/src/mod_fileio/properties/open.cpp @@ -90,15 +90,15 @@ napi_value Open::Sync(napi_env env, napi_callback_info info) } size_t argc = funcArg.GetArgc(); + int32_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP; if (argc != NARG_CNT::THREE) { size_t flagsFirst { flags }; if ((flagsFirst & O_CREAT) || (flagsFirst & O_TMPFILE)) { UniError(EINVAL).ThrowErr(env, "called with O_CREAT/O_TMPFILE but no mode"); return nullptr; } - fd = open(path.get(), flags); + fd = open(path.get(), flags, mode); } else { - int mode; tie(succ, mode) = NVal(env, funcArg.GetArg(NARG_POS::THIRD)).ToInt32(); if (!succ) { UniError(EINVAL).ThrowErr(env, "Invalid mode"); @@ -119,7 +119,7 @@ napi_value Open::Sync(napi_env env, napi_callback_info info) return NVal::CreateInt64(env, fd).val_; } -static UniError DoOpenExec(const std::string& path, const int flags, const int mode, shared_ptr arg) +static UniError DoOpenExec(const std::string& path, const int flags, const int32_t mode, shared_ptr arg) { int fd = -1; if (!ModuleRemoteUri::RemoteUri::IsRemoteUri(path, fd, flags)) { @@ -157,7 +157,7 @@ napi_value Open::Async(napi_env env, napi_callback_info info) (void)AdaptToAbi(flags); } - int mode = 0; + int32_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP; size_t argc = funcArg.GetArgc(); if (argc == NARG_CNT::FOUR || (argc == NARG_CNT::THREE && NVal(env, funcArg[NARG_POS::THIRD]).TypeIs(napi_number))) { -- Gitee