Skip to content

Commit 842b986

Browse files
committed
fs: improve error performance of lchownSync
1 parent 89f000a commit 842b986

File tree

3 files changed

+11
-10
lines changed

3 files changed

+11
-10
lines changed

lib/fs.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2020,9 +2020,11 @@ function lchownSync(path, uid, gid) {
20202020
path = getValidatedPath(path);
20212021
validateInteger(uid, 'uid', -1, kMaxUserId);
20222022
validateInteger(gid, 'gid', -1, kMaxUserId);
2023-
const ctx = { path };
2024-
binding.lchown(pathModule.toNamespacedPath(path), uid, gid, undefined, ctx);
2025-
handleErrorFromBinding(ctx);
2023+
binding.lchown(
2024+
pathModule.toNamespacedPath(path),
2025+
uid,
2026+
gid,
2027+
);
20262028
}
20272029

20282030
/**

src/node_file.cc

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2622,7 +2622,7 @@ static void LChown(const FunctionCallbackInfo<Value>& args) {
26222622
Environment* env = Environment::GetCurrent(args);
26232623

26242624
const int argc = args.Length();
2625-
CHECK_GE(argc, 3);
2625+
CHECK_GE(argc, 2);
26262626

26272627
BufferValue path(env->isolate(), args[0]);
26282628
CHECK_NOT_NULL(*path);
@@ -2635,18 +2635,16 @@ static void LChown(const FunctionCallbackInfo<Value>& args) {
26352635
CHECK(IsSafeJsInt(args[2]));
26362636
const uv_gid_t gid = static_cast<uv_gid_t>(args[2].As<Integer>()->Value());
26372637

2638-
FSReqBase* req_wrap_async = GetReqWrap(args, 3);
2639-
if (req_wrap_async != nullptr) { // lchown(path, uid, gid, req)
2638+
if (argc > 3) { // lchown(path, uid, gid, req)
2639+
FSReqBase* req_wrap_async = GetReqWrap(args, 3);
26402640
FS_ASYNC_TRACE_BEGIN1(
26412641
UV_FS_LCHOWN, req_wrap_async, "path", TRACE_STR_COPY(*path))
26422642
AsyncCall(env, req_wrap_async, args, "lchown", UTF8, AfterNoArgs,
26432643
uv_fs_lchown, *path, uid, gid);
26442644
} else { // lchown(path, uid, gid, undefined, ctx)
2645-
CHECK_EQ(argc, 5);
2646-
FSReqWrapSync req_wrap_sync;
2645+
FSReqWrapSync req_wrap_sync("lchown", *path);
26472646
FS_SYNC_TRACE_BEGIN(lchown);
2648-
SyncCall(env, args[4], &req_wrap_sync, "lchown",
2649-
uv_fs_lchown, *path, uid, gid);
2647+
SyncCallAndThrowOnError(env, &req_wrap_sync, uv_fs_lchown, *path, uid, gid);
26502648
FS_SYNC_TRACE_END(lchown);
26512649
}
26522650
}

typings/internalBinding/fs.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ declare namespace InternalFSBinding {
114114
function lchown(path: string, uid: number, gid: number, req: FSReqCallback): void;
115115
function lchown(path: string, uid: number, gid: number, req: undefined, ctx: FSSyncContext): void;
116116
function lchown(path: string, uid: number, gid: number, usePromises: typeof kUsePromises): Promise<void>;
117+
function lchown(path: string, uid: number, gid: number): void;
117118

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

0 commit comments

Comments
 (0)