summaryrefslogtreecommitdiff
path: root/ext/node/ops/fs.rs
blob: b21652634dd809737a7432c76bc88ca8585399bf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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())
}