fs: improve error performance of `chownSync` · nodejs/node@f766c04 · GitHub
Skip to content

Commit f766c04

Browse files
anonrigtargos
authored andcommitted
fs: improve error performance of chownSync
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 610036c commit f766c04

4 files changed

Lines changed: 65 additions & 10 deletions

File tree

benchmark/fs/bench-chownSync.js

Lines changed: 54 additions & 0 deletions

lib/fs.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2089,9 +2089,11 @@ function chownSync(path, uid, gid) {
20892089
path = getValidatedPath(path);
20902090
validateInteger(uid, 'uid', -1, kMaxUserId);
20912091
validateInteger(gid, 'gid', -1, kMaxUserId);
2092-
const ctx = { path };
2093-
binding.chown(pathModule.toNamespacedPath(path), uid, gid, undefined, ctx);
2094-
handleErrorFromBinding(ctx);
2092+
binding.chown(
2093+
pathModule.toNamespacedPath(path),
2094+
uid,
2095+
gid,
2096+
);
20952097
}
20962098

20972099
/**

src/node_file.cc

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2572,18 +2572,16 @@ static void Chown(const FunctionCallbackInfo<Value>& args) {
25722572
CHECK(IsSafeJsInt(args[2]));
25732573
const uv_gid_t gid = static_cast<uv_gid_t>(args[2].As<Integer>()->Value());
25742574

2575-
FSReqBase* req_wrap_async = GetReqWrap(args, 3);
2576-
if (req_wrap_async != nullptr) { // chown(path, uid, gid, req)
2575+
if (argc > 3) { // chown(path, uid, gid, req)
2576+
FSReqBase* req_wrap_async = GetReqWrap(args, 3);
25772577
FS_ASYNC_TRACE_BEGIN1(
25782578
UV_FS_CHOWN, req_wrap_async, "path", TRACE_STR_COPY(*path))
25792579
AsyncCall(env, req_wrap_async, args, "chown", UTF8, AfterNoArgs,
25802580
uv_fs_chown, *path, uid, gid);
2581-
} else { // chown(path, uid, gid, undefined, ctx)
2582-
CHECK_EQ(argc, 5);
2583-
FSReqWrapSync req_wrap_sync;
2581+
} else { // chown(path, uid, gid)
2582+
FSReqWrapSync req_wrap_sync("chown", *path);
25842583
FS_SYNC_TRACE_BEGIN(chown);
2585-
SyncCall(env, args[4], &req_wrap_sync, "chown",
2586-
uv_fs_chown, *path, uid, gid);
2584+
SyncCallAndThrowOnError(env, &req_wrap_sync, uv_fs_chown, *path, uid, gid);
25872585
FS_SYNC_TRACE_END(chown);
25882586
}
25892587
}

typings/internalBinding/fs.d.ts

Lines changed: 1 addition & 0 deletions

0 commit comments

Comments
 (0)