diff options
Diffstat (limited to 'ext/node/ops/fs.rs')
-rw-r--r-- | ext/node/ops/fs.rs | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/ext/node/ops/fs.rs b/ext/node/ops/fs.rs index 47b66ee1d..687903325 100644 --- a/ext/node/ops/fs.rs +++ b/ext/node/ops/fs.rs @@ -26,7 +26,28 @@ where .borrow_mut::<P>() .check_read_with_api_name(&path, Some("node:fs.existsSync()"))?; let fs = state.borrow::<FileSystemRc>(); - Ok(fs.lstat_sync(&path).is_ok()) + Ok(fs.exists_sync(&path)) +} + +#[op2(async)] +pub async fn op_node_fs_exists<P>( + state: Rc<RefCell<OpState>>, + #[string] path: String, +) -> Result<bool, AnyError> +where + P: NodePermissions + 'static, +{ + let path = PathBuf::from(path); + + let fs = { + let mut state = state.borrow_mut(); + state + .borrow_mut::<P>() + .check_read_with_api_name(&path, Some("node:fs.exists()"))?; + state.borrow::<FileSystemRc>().clone() + }; + + Ok(fs.exists_async(path).await?) } #[op2(fast)] |