Skip to content

Commit

Permalink
fs: throw fchownSync error from c++
Browse files Browse the repository at this point in the history
PR-URL: #51075
Refs: nodejs/performance#106
Reviewed-By: Stephen Belanger <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
anonrig authored and RafaelGSS committed Dec 15, 2023
1 parent 9b7f79a commit 35e8f26
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 11 deletions.
4 changes: 1 addition & 3 deletions lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
12 changes: 5 additions & 7 deletions src/node_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2590,17 +2590,15 @@ static void FChown(const FunctionCallbackInfo<Value>& args) {
CHECK(IsSafeJsInt(args[2]));
const uv_gid_t gid = static_cast<uv_gid_t>(args[2].As<Integer>()->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);
}
}
Expand Down
2 changes: 1 addition & 1 deletion typings/internalBinding/fs.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ declare namespace InternalFSBinding {
function fchmod(fd: number, mode: number, usePromises: typeof kUsePromises): Promise<void>;

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<void>;

function fdatasync(fd: number, req: FSReqCallback): void;
Expand Down

0 comments on commit 35e8f26

Please sign in to comment.