Skip to content

Commit 88b3339

Browse files
committed
fs: improve error performance of lchownSync
1 parent f353a50 commit 88b3339

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
@@ -2018,9 +2018,11 @@ function lchownSync(path, uid, gid) {
20182018
path = getValidatedPath(path);
20192019
validateInteger(uid, 'uid', -1, kMaxUserId);
20202020
validateInteger(gid, 'gid', -1, kMaxUserId);
2021-
const ctx = { path };
2022-
binding.lchown(pathModule.toNamespacedPath(path), uid, gid, undefined, ctx);
2023-
handleErrorFromBinding(ctx);
2021+
binding.lchown(
2022+
pathModule.toNamespacedPath(path),
2023+
uid,
2024+
gid,
2025+
);
20242026
}
20252027

20262028
/**

src/node_file.cc

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

26232623
const int argc = args.Length();
2624-
CHECK_GE(argc, 3);
2624+
CHECK_GE(argc, 2);
26252625

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

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

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)