Skip to content

Commit b9e2c35

Browse files
anonrigpull[bot]
authored andcommitted
fs: improve error performance of lchownSync
PR-URL: #49962 Refs: nodejs/performance#106 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Stephen Belanger <admin@stephenbelanger.com> Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br>
1 parent 8b359cd commit b9e2c35

File tree

3 files changed

+11
-10
lines changed

3 files changed

+11
-10
lines changed

lib/fs.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -2012,9 +2012,11 @@ function lchownSync(path, uid, gid) {
20122012
path = getValidatedPath(path);
20132013
validateInteger(uid, 'uid', -1, kMaxUserId);
20142014
validateInteger(gid, 'gid', -1, kMaxUserId);
2015-
const ctx = { path };
2016-
binding.lchown(pathModule.toNamespacedPath(path), uid, gid, undefined, ctx);
2017-
handleErrorFromBinding(ctx);
2015+
binding.lchown(
2016+
pathModule.toNamespacedPath(path),
2017+
uid,
2018+
gid,
2019+
);
20182020
}
20192021

20202022
/**

src/node_file.cc

+5-7
Original file line numberDiff line numberDiff line change
@@ -2633,18 +2633,16 @@ static void LChown(const FunctionCallbackInfo<Value>& args) {
26332633
CHECK(IsSafeJsInt(args[2]));
26342634
const uv_gid_t gid = static_cast<uv_gid_t>(args[2].As<Integer>()->Value());
26352635

2636-
FSReqBase* req_wrap_async = GetReqWrap(args, 3);
2637-
if (req_wrap_async != nullptr) { // lchown(path, uid, gid, req)
2636+
if (argc > 3) { // lchown(path, uid, gid, req)
2637+
FSReqBase* req_wrap_async = GetReqWrap(args, 3);
26382638
FS_ASYNC_TRACE_BEGIN1(
26392639
UV_FS_LCHOWN, req_wrap_async, "path", TRACE_STR_COPY(*path))
26402640
AsyncCall(env, req_wrap_async, args, "lchown", UTF8, AfterNoArgs,
26412641
uv_fs_lchown, *path, uid, gid);
2642-
} else { // lchown(path, uid, gid, undefined, ctx)
2643-
CHECK_EQ(argc, 5);
2644-
FSReqWrapSync req_wrap_sync;
2642+
} else { // lchown(path, uid, gid)
2643+
FSReqWrapSync req_wrap_sync("lchown", *path);
26452644
FS_SYNC_TRACE_BEGIN(lchown);
2646-
SyncCall(env, args[4], &req_wrap_sync, "lchown",
2647-
uv_fs_lchown, *path, uid, gid);
2645+
SyncCallAndThrowOnError(env, &req_wrap_sync, uv_fs_lchown, *path, uid, gid);
26482646
FS_SYNC_TRACE_END(lchown);
26492647
}
26502648
}

typings/internalBinding/fs.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ declare namespace InternalFSBinding {
117117
function lchown(path: string, uid: number, gid: number, req: FSReqCallback): void;
118118
function lchown(path: string, uid: number, gid: number, req: undefined, ctx: FSSyncContext): void;
119119
function lchown(path: string, uid: number, gid: number, usePromises: typeof kUsePromises): Promise<void>;
120+
function lchown(path: string, uid: number, gid: number): void;
120121

121122
function link(existingPath: string, newPath: string, req: FSReqCallback): void;
122123
function link(existingPath: string, newPath: string, req: undefined, ctx: FSSyncContext): void;

0 commit comments

Comments
 (0)