diff options
author | Axetroy <axetroy.dev@gmail.com> | 2019-12-13 22:47:09 +0800 |
---|---|---|
committer | Ry Dahl <ry@tinyclouds.org> | 2019-12-13 22:47:09 +0800 |
commit | 8cf8a29d35d5832230034b3f9f6ce3cc67dba7c1 (patch) | |
tree | 8103652192c652da7389d8551b86f99eb4624bfb /std/fs/exists.ts | |
parent | df7d8288d984f703722fae161b7d32fae9ab3149 (diff) |
fix permission errors are swallowed by fs.exists (#3493)
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; } } |