mirror of
https://github.com/denoland/deno.git
synced 2025-09-26 12:19:12 +00:00
fix permission errors are swallowed by fs.exists (#3493)
This commit is contained in:
parent
df7d8288d9
commit
8cf8a29d35
4 changed files with 132 additions and 6 deletions
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue