summaryrefslogtreecommitdiff
path: root/ext/node/ops/fs.rs
diff options
context:
space:
mode:
authorDavid Sherret <dsherret@users.noreply.github.com>2023-12-04 16:05:40 -0500
committerGitHub <noreply@github.com>2023-12-04 21:05:40 +0000
commita24d3e8763bc48b69936db9231efb76766914303 (patch)
tree7091c5354d1e341c34e5847ea0271213c8730c69 /ext/node/ops/fs.rs
parent9eb25e3cff22d1f704ede0d4066abc846a26a919 (diff)
perf(node/fs): faster `existsSync` when not exists (#21458)
Diffstat (limited to 'ext/node/ops/fs.rs')
-rw-r--r--ext/node/ops/fs.rs26
1 files changed, 26 insertions, 0 deletions
diff --git a/ext/node/ops/fs.rs b/ext/node/ops/fs.rs
new file mode 100644
index 000000000..b21652634
--- /dev/null
+++ b/ext/node/ops/fs.rs
@@ -0,0 +1,26 @@
+// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
+
+use std::path::PathBuf;
+
+use deno_core::error::AnyError;
+use deno_core::op2;
+use deno_core::OpState;
+use deno_fs::FileSystemRc;
+
+use crate::NodePermissions;
+
+#[op2(fast)]
+pub fn op_node_fs_exists_sync<P>(
+ state: &mut OpState,
+ #[string] path: String,
+) -> Result<bool, AnyError>
+where
+ P: NodePermissions + 'static,
+{
+ let path = PathBuf::from(path);
+ state
+ .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())
+}