Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lchown sync improvement #50007

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -2025,7 +2025,7 @@ function lchownSync(path, uid, gid) {
validateInteger(uid, 'uid', -1, kMaxUserId);
validateInteger(gid, 'gid', -1, kMaxUserId);
const ctx = { path };
binding.lchown(pathModule.toNamespacedPath(path), uid, gid, undefined, ctx);
binding.lchownSync(pathModule.toNamespacedPath(path), uid, gid, undefined, ctx);
handleErrorFromBinding(ctx);
}

Expand Down
28 changes: 28 additions & 0 deletions src/node_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2659,6 +2659,32 @@ static void LChown(const FunctionCallbackInfo<Value>& args) {
}
}

static void LChownSync(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);

const int argc = args.Length();
CHECK_GE(argc, 3);

BufferValue path(env->isolate(), args[0]);
CHECK_NOT_NULL(*path);
THROW_IF_INSUFFICIENT_PERMISSIONS(
env, permission::PermissionScope::kFileSystemWrite, path.ToStringView());

CHECK(IsSafeJsInt(args[1]));
const uv_uid_t uid = static_cast<uv_uid_t>(args[1].As<Integer>()->Value());

CHECK(IsSafeJsInt(args[2]));
const uv_gid_t gid = static_cast<uv_gid_t>(args[2].As<Integer>()->Value());

uv_fs_t req;
auto cleanup = OnScopeLeave([&req]() { uv_fs_req_cleanup(&req); });
FS_SYNC_TRACE_BEGIN(lchown);
int err = uv_fs_lchown(nullptr, &req, *path, uid, gid, nullptr);
FS_SYNC_TRACE_END(lchown);
if (err < 0) {
return env->ThrowUVException(err, "lchown");
}
}

static void UTimes(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);
Expand Down Expand Up @@ -3295,6 +3321,7 @@ static void CreatePerIsolateProperties(IsolateData* isolate_data,
SetMethod(isolate, target, "chown", Chown);
SetMethod(isolate, target, "fchown", FChown);
SetMethod(isolate, target, "lchown", LChown);
SetMethod(isolate, target, "lchownSync", LChownSync);

SetMethod(isolate, target, "utimes", UTimes);
SetMethod(isolate, target, "futimes", FUTimes);
Expand Down Expand Up @@ -3415,6 +3442,7 @@ void RegisterExternalReferences(ExternalReferenceRegistry* registry) {
registry->Register(Chown);
registry->Register(FChown);
registry->Register(LChown);
registry->Register(LChownSync);

registry->Register(UTimes);
registry->Register(FUTimes);
Expand Down