@@ -315,31 +315,41 @@ pub fn op_node_fs_exists_sync(
315315 state : & mut OpState ,
316316 #[ string] path : & str ,
317317) -> Result < bool , deno_permissions:: PermissionCheckError > {
318- let path = state. borrow_mut :: < PermissionsContainer > ( ) . check_open (
318+ let path_or_err = state. borrow_mut :: < PermissionsContainer > ( ) . check_open (
319319 Cow :: Borrowed ( Path :: new ( path) ) ,
320320 OpenAccessKind :: ReadNoFollow ,
321321 Some ( "node:fs.existsSync()" ) ,
322- ) ?;
323- let fs = state. borrow :: < FileSystemRc > ( ) ;
324- Ok ( fs. exists_sync ( & path) )
322+ ) ;
323+ match path_or_err {
324+ Ok ( path) => {
325+ let fs = state. borrow :: < FileSystemRc > ( ) ;
326+ Ok ( fs. exists_sync ( & path) )
327+ }
328+ Err ( ref e) if e. kind ( ) == std:: io:: ErrorKind :: NotFound => Ok ( false ) ,
329+ Err ( err) => Err ( err) ,
330+ }
325331}
326332
327333#[ op2( stack_trace) ]
328334pub async fn op_node_fs_exists (
329335 state : Rc < RefCell < OpState > > ,
330336 #[ string] path : String ,
331337) -> Result < bool , FsError > {
332- let ( fs, path ) = {
338+ let ( fs, path_or_err ) = {
333339 let mut state = state. borrow_mut ( ) ;
334- let path = state. borrow_mut :: < PermissionsContainer > ( ) . check_open (
340+ let path_or_err = state. borrow_mut :: < PermissionsContainer > ( ) . check_open (
335341 Cow :: Owned ( PathBuf :: from ( path) ) ,
336342 OpenAccessKind :: ReadNoFollow ,
337343 Some ( "node:fs.exists()" ) ,
338- ) ? ;
339- ( state. borrow :: < FileSystemRc > ( ) . clone ( ) , path )
344+ ) ;
345+ ( state. borrow :: < FileSystemRc > ( ) . clone ( ) , path_or_err )
340346 } ;
341347
342- Ok ( fs. exists_async ( path. into_owned ( ) ) . await ?)
348+ match path_or_err {
349+ Ok ( path) => Ok ( fs. exists_async ( path. into_owned ( ) ) . await ?) ,
350+ Err ( ref e) if e. kind ( ) == std:: io:: ErrorKind :: NotFound => Ok ( false ) ,
351+ Err ( err) => Err ( FsError :: Permission ( err) ) ,
352+ }
343353}
344354
345355fn get_open_options ( flags : i32 , mode : Option < u32 > ) -> OpenOptions {
0 commit comments