diff options
Diffstat (limited to 'std/fs/exists.ts')
-rw-r--r-- | std/fs/exists.ts | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/std/fs/exists.ts b/std/fs/exists.ts index 2c68ec6cf..aa6334b43 100644 --- a/std/fs/exists.ts +++ b/std/fs/exists.ts @@ -1,12 +1,20 @@ // Copyright 2018-2019 the Deno authors. All rights reserved. MIT license. - +const { lstat, lstatSync, DenoError, ErrorKind } = Deno; /** * Test whether or not the given path exists by checking with the file system */ export async function exists(filePath: string): Promise<boolean> { - return Deno.lstat(filePath) + return lstat(filePath) .then((): boolean => true) - .catch((): boolean => false); + .catch((err: Error): boolean => { + if (err instanceof DenoError) { + if (err.kind === ErrorKind.NotFound) { + return false; + } + } + + throw err; + }); } /** @@ -14,9 +22,14 @@ export async function exists(filePath: string): Promise<boolean> { */ export function existsSync(filePath: string): boolean { try { - Deno.lstatSync(filePath); + lstatSync(filePath); return true; - } catch { - return false; + } catch (err) { + if (err instanceof DenoError) { + if (err.kind === ErrorKind.NotFound) { + return false; + } + } + throw err; } } |