summaryrefslogtreecommitdiff
path: root/ext/node
diff options
context:
space:
mode:
Diffstat (limited to 'ext/node')
-rw-r--r--ext/node/lib.rs1
-rw-r--r--ext/node/ops/fs.rs23
-rw-r--r--ext/node/polyfills/_fs/_fs_exists.ts4
3 files changed, 25 insertions, 3 deletions
diff --git a/ext/node/lib.rs b/ext/node/lib.rs
index 13f9abc60..5be0fffa1 100644
--- a/ext/node/lib.rs
+++ b/ext/node/lib.rs
@@ -313,6 +313,7 @@ deno_core::extension!(deno_node,
ops::crypto::x509::op_node_x509_get_serial_number,
ops::crypto::x509::op_node_x509_key_usage,
ops::fs::op_node_fs_exists_sync<P>,
+ ops::fs::op_node_fs_exists<P>,
ops::fs::op_node_cp_sync<P>,
ops::fs::op_node_cp<P>,
ops::fs::op_node_lchown_sync<P>,
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)]
diff --git a/ext/node/polyfills/_fs/_fs_exists.ts b/ext/node/polyfills/_fs/_fs_exists.ts
index 57df1f07c..b5bbe235a 100644
--- a/ext/node/polyfills/_fs/_fs_exists.ts
+++ b/ext/node/polyfills/_fs/_fs_exists.ts
@@ -3,7 +3,7 @@
// TODO(petamoriken): enable prefer-primordials for node polyfills
// deno-lint-ignore-file prefer-primordials
-import { op_node_fs_exists_sync } from "ext:core/ops";
+import { op_node_fs_exists, op_node_fs_exists_sync } from "ext:core/ops";
import { pathFromURL } from "ext:deno_web/00_infra.js";
@@ -16,7 +16,7 @@ type ExistsCallback = (exists: boolean) => void;
*/
export function exists(path: string | URL, callback: ExistsCallback) {
path = path instanceof URL ? pathFromURL(path) : path;
- Deno.lstat(path).then(() => callback(true), () => callback(false));
+ op_node_fs_exists(path).then(callback);
}
// The callback of fs.exists doesn't have standard callback signature.