diff options
author | Nathan Whitaker <17734409+nathanwhit@users.noreply.github.com> | 2024-07-02 19:33:32 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-07-02 19:33:32 -0700 |
commit | dadc606419096325ef0b03b6216ee20bef442045 (patch) | |
tree | a09293a1f852d03d13a2b6eb9e4dfb3f552fb7a0 /ext/node/ops/fs.rs | |
parent | 3324d7203e8d00bb39cfae104e0aec61ba954e9b (diff) |
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.
Diffstat (limited to 'ext/node/ops/fs.rs')
-rw-r--r-- | ext/node/ops/fs.rs | 51 |
1 files changed, 51 insertions, 0 deletions
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<P>( + 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::<P>() + .check_write_with_api_name(path, Some("node:fs.lutimes"))?; + + let fs = state.borrow::<FileSystemRc>(); + fs.lutime_sync(path, atime_secs, atime_nanos, mtime_secs, mtime_nanos)?; + Ok(()) +} + +#[op2(async)] +pub async fn op_node_lutimes<P>( + state: Rc<RefCell<OpState>>, + #[string] path: String, + #[number] atime_secs: i64, + #[smi] atime_nanos: u32, + #[number] mtime_secs: i64, + #[smi] mtime_nanos: 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.lutimesSync"))?; + state.borrow::<FileSystemRc>().clone() + }; + + fs.lutime_async(path, atime_secs, atime_nanos, mtime_secs, mtime_nanos) + .await?; + + Ok(()) +} |