From d4d3a3c54f5e26dec0cc79e273dc488f8a47f2b3 Mon Sep 17 00:00:00 2001 From: Nathan Whitaker <17734409+nathanwhit@users.noreply.github.com> Date: Fri, 5 Jul 2024 11:32:51 -0700 Subject: fix(node): Implement `fs.lchown` (and `process.getegid`) (#24418) Closes https://github.com/denoland/deno/issues/21260. Part of https://github.com/denoland/deno/issues/18218. Implements `node:fs.lchown`, and enables the node_compat test for it. The test uses `process.getegid`, which we didn't have implemented, so I went ahead and implemented that as well to get the test working. --- ext/node/ops/fs.rs | 41 +++++++++++++++++++++++++++++++++++++++++ ext/node/ops/os/mod.rs | 19 +++++++++++++++++++ 2 files changed, 60 insertions(+) (limited to 'ext/node/ops') diff --git a/ext/node/ops/fs.rs b/ext/node/ops/fs.rs index 304a6c253..47b66ee1d 100644 --- a/ext/node/ops/fs.rs +++ b/ext/node/ops/fs.rs @@ -273,3 +273,44 @@ where Ok(()) } + +#[op2] +pub fn op_node_lchown_sync

( + state: &mut OpState, + #[string] path: String, + uid: Option, + gid: Option, +) -> Result<(), AnyError> +where + P: NodePermissions + 'static, +{ + let path = PathBuf::from(path); + state + .borrow_mut::

() + .check_write_with_api_name(&path, Some("node:fs.lchownSync"))?; + let fs = state.borrow::(); + fs.lchown_sync(&path, uid, gid)?; + Ok(()) +} + +#[op2(async)] +pub async fn op_node_lchown

( + state: Rc>, + #[string] path: String, + uid: Option, + gid: Option, +) -> Result<(), AnyError> +where + P: NodePermissions + 'static, +{ + let path = PathBuf::from(path); + let fs = { + let mut state = state.borrow_mut(); + state + .borrow_mut::

() + .check_write_with_api_name(&path, Some("node:fs.lchown"))?; + state.borrow::().clone() + }; + fs.lchown_async(path, uid, gid).await?; + Ok(()) +} diff --git a/ext/node/ops/os/mod.rs b/ext/node/ops/os/mod.rs index 5b32113e5..b7374dc32 100644 --- a/ext/node/ops/os/mod.rs +++ b/ext/node/ops/os/mod.rs @@ -75,6 +75,25 @@ where Ok(euid) } +#[op2(fast)] +pub fn op_getegid

(state: &mut OpState) -> Result +where + P: NodePermissions + 'static, +{ + { + let permissions = state.borrow_mut::

(); + permissions.check_sys("getegid", "node:os.getegid()")?; + } + + #[cfg(windows)] + let egid = 0; + #[cfg(unix)] + // SAFETY: Call to libc getegid. + let egid = unsafe { libc::getegid() }; + + Ok(egid) +} + #[op2] #[serde] pub fn op_cpus

(state: &mut OpState) -> Result, AnyError> -- cgit v1.2.3