Skip to content

Commit

Permalink
fs: throw fchownSync error from c++
Browse files Browse the repository at this point in the history
  • Loading branch information
anonrig committed Dec 6, 2023
1 parent 727dd28 commit 1a6c120
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 @@ -2599,17 +2599,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 1a6c120

Please sign in to comment.