From 35e8f26f077d8429273ad4ab0b4b282fbaa4e9ea Mon Sep 17 00:00:00 2001 From: Yagiz Nizipli Date: Mon, 11 Dec 2023 19:34:47 -0500 Subject: [PATCH] fs: throw fchownSync error from c++ PR-URL: https://github.com/nodejs/node/pull/51075 Refs: https://github.com/nodejs/performance/issues/106 Reviewed-By: Stephen Belanger Reviewed-By: James M Snell --- lib/fs.js | 4 +--- src/node_file.cc | 12 +++++------- typings/internalBinding/fs.d.ts | 2 +- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/lib/fs.js b/lib/fs.js index 34ad6ef6be835b..e398687c04a2b0 100644 --- a/lib/fs.js +++ b/lib/fs.js @@ -2051,9 +2051,7 @@ function fchownSync(fd, uid, gid) { validateInteger(uid, 'uid', -1, kMaxUserId); validateInteger(gid, 'gid', -1, kMaxUserId); - const ctx = {}; - binding.fchown(fd, uid, gid, undefined, ctx); - handleErrorFromBinding(ctx); + binding.fchown(fd, uid, gid); } /** diff --git a/src/node_file.cc b/src/node_file.cc index 30fb7b46944b25..bddab3031c55e2 100644 --- a/src/node_file.cc +++ b/src/node_file.cc @@ -2590,17 +2590,15 @@ static void FChown(const FunctionCallbackInfo& args) { CHECK(IsSafeJsInt(args[2])); const uv_gid_t gid = static_cast(args[2].As()->Value()); - FSReqBase* req_wrap_async = GetReqWrap(args, 3); - if (req_wrap_async != nullptr) { // fchown(fd, uid, gid, req) + if (argc > 3) { // fchown(fd, uid, gid, req) + FSReqBase* req_wrap_async = GetReqWrap(args, 3); FS_ASYNC_TRACE_BEGIN0(UV_FS_FCHOWN, req_wrap_async) AsyncCall(env, req_wrap_async, args, "fchown", UTF8, AfterNoArgs, uv_fs_fchown, fd, uid, gid); - } else { // fchown(fd, uid, gid, undefined, ctx) - CHECK_EQ(argc, 5); - FSReqWrapSync req_wrap_sync; + } else { // fchown(fd, uid, gid) + FSReqWrapSync req_wrap_sync("fchown"); FS_SYNC_TRACE_BEGIN(fchown); - SyncCall(env, args[4], &req_wrap_sync, "fchown", - uv_fs_fchown, fd, uid, gid); + SyncCallAndThrowOnError(env, &req_wrap_sync, uv_fs_fchown, fd, uid, gid); FS_SYNC_TRACE_END(fchown); } } diff --git a/typings/internalBinding/fs.d.ts b/typings/internalBinding/fs.d.ts index 71707c0329020a..046eeeb230974b 100644 --- a/typings/internalBinding/fs.d.ts +++ b/typings/internalBinding/fs.d.ts @@ -81,7 +81,7 @@ declare namespace InternalFSBinding { function fchmod(fd: number, mode: number, usePromises: typeof kUsePromises): Promise; function fchown(fd: number, uid: number, gid: number, req: FSReqCallback): void; - function fchown(fd: number, uid: number, gid: number, req: undefined, ctx: FSSyncContext): void; + function fchown(fd: number, uid: number, gid: number): void; function fchown(fd: number, uid: number, gid: number, usePromises: typeof kUsePromises): Promise; function fdatasync(fd: number, req: FSReqCallback): void;