use fstatSync instead of statSync

This commit is contained in:
ddorando 2023-09-04 16:07:39 +03:00
parent 46db4850df
commit dad3602d2b
2 changed files with 9 additions and 4 deletions

View file

@ -147,9 +147,10 @@ export function fileExistsSync(path: string): boolean {
throw new Error("Arg 'path' must not be empty")
}
const fd = fs.openSync(path, 'r')
let stats: fs.Stats
try {
stats = fs.statSync(path)
stats = fs.fstatSync(fd)
} catch (error) {
if (hasErrorCode(error) && error.code === 'ENOENT') {
return false
@ -160,6 +161,8 @@ export function fileExistsSync(path: string): boolean {
error
)}`
)
} finally {
fs.closeSync(fd)
}
if (!stats.isDirectory()) {