From dadc606419096325ef0b03b6216ee20bef442045 Mon Sep 17 00:00:00 2001 From: Nathan Whitaker <17734409+nathanwhit@users.noreply.github.com> Date: Tue, 2 Jul 2024 19:33:32 -0700 Subject: fix(ext/node): Add `fs.lutimes` / `fs.lutimesSync` (#23172) Part of #18218 - Adds `fs.lutimes` and `fs.lutimesSync` to our node polyfills. To do this I added methods to the `FileSystem` trait + ops to expose the functionality to JS. - Exports `fs._toUnixTimestamp`. Node exposes an internal util `toUnixTimestamp` from the fs module to be used by unit tests (so we need it for the unit test to pass unmodified). It's weird because it's only supposed to be used internally but it's still publicly accessible - Matches up error handling and timestamp handling for fs.futimes and fs.utimes with node - Enables the node_compat utimes test - this exercises futimes, lutimes, and utimes. --- ext/node/ops/fs.rs | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) (limited to 'ext/node/ops') diff --git a/ext/node/ops/fs.rs b/ext/node/ops/fs.rs index cfc760656..304a6c253 100644 --- a/ext/node/ops/fs.rs +++ b/ext/node/ops/fs.rs @@ -222,3 +222,54 @@ where Err(anyhow!("Unsupported platform.")) } } + +#[op2(fast)] +pub fn op_node_lutimes_sync
( + state: &mut OpState, + #[string] path: &str, + #[number] atime_secs: i64, + #[smi] atime_nanos: u32, + #[number] mtime_secs: i64, + #[smi] mtime_nanos: u32, +) -> Result<(), AnyError> +where + P: NodePermissions + 'static, +{ + let path = Path::new(path); + + state + .borrow_mut::
()
+ .check_write_with_api_name(path, Some("node:fs.lutimes"))?;
+
+ let fs = state.borrow:: (
+ state: Rc ()
+ .check_write_with_api_name(&path, Some("node:fs.lutimesSync"))?;
+ state.borrow::