summaryrefslogtreecommitdiff
path: root/ext/node/ops/fs.rs
diff options
context:
space:
mode:
authorNathan Whitaker <17734409+nathanwhit@users.noreply.github.com>2024-07-05 11:32:51 -0700
committerGitHub <noreply@github.com>2024-07-05 18:32:51 +0000
commitd4d3a3c54f5e26dec0cc79e273dc488f8a47f2b3 (patch)
treee6ff88b550211257ea7a7997e221d10fdf22e242 /ext/node/ops/fs.rs
parent28d2ff7bdc023a3b7aff47503aa03a8dd65fe87f (diff)
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.
Diffstat (limited to 'ext/node/ops/fs.rs')
-rw-r--r--ext/node/ops/fs.rs41
1 files changed, 41 insertions, 0 deletions
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<P>(
+ state: &mut OpState,
+ #[string] path: String,
+ uid: Option<u32>,
+ gid: Option<u32>,
+) -> Result<(), AnyError>
+where
+ P: NodePermissions + 'static,
+{
+ let path = PathBuf::from(path);
+ state
+ .borrow_mut::<P>()
+ .check_write_with_api_name(&path, Some("node:fs.lchownSync"))?;
+ let fs = state.borrow::<FileSystemRc>();
+ fs.lchown_sync(&path, uid, gid)?;
+ Ok(())
+}
+
+#[op2(async)]
+pub async fn op_node_lchown<P>(
+ state: Rc<RefCell<OpState>>,
+ #[string] path: String,
+ uid: Option<u32>,
+ gid: Option<u32>,
+) -> Result<(), AnyError>
+where
+ P: NodePermissions + 'static,
+{
+ let path = PathBuf::from(path);
+ let fs = {
+ let mut state = state.borrow_mut();
+ state
+ .borrow_mut::<P>()
+ .check_write_with_api_name(&path, Some("node:fs.lchown"))?;
+ state.borrow::<FileSystemRc>().clone()
+ };
+ fs.lchown_async(path, uid, gid).await?;
+ Ok(())
+}