fs.statSync(fs.realpathSync()) for fileExistsSync

This commit is contained in:
ddorando 2023-09-05 16:10:30 +03:00
parent 8e161f8241
commit 260c5e341d

View file

@ -147,10 +147,9 @@ 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.fstatSync(fd)
stats = fs.statSync(fs.realpathSync(path))
} catch (error) {
if (hasErrorCode(error) && error.code === 'ENOENT') {
return false
@ -161,8 +160,6 @@ export function fileExistsSync(path: string): boolean {
error
)}`
)
} finally {
fs.closeSync(fd)
}
if (!stats.isDirectory()) {