Skip to content

Commit bcc7b7a

Browse files
joyeecheungTrott
authored andcommitted
fs: handle result of access binding directly in fs.existsSync
Instead of throwing errors in fs.accessSync and then catching it, handle the result from the binding directly in fs.existsSync. Note that the argument validation errors still needs to be caught until we properly deprecate the don't-thrown-on-invalid-arguments behavior. PR-URL: #24015 Fixes: #24008 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Refael Ackermann <[email protected]>
1 parent 616fac9 commit bcc7b7a

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

lib/fs.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,11 +228,14 @@ Object.defineProperty(exists, internalUtil.promisify.custom, {
228228
// TODO(joyeecheung): deprecate the never-throw-on-invalid-arguments behavior
229229
function existsSync(path) {
230230
try {
231-
fs.accessSync(path, F_OK);
232-
return true;
231+
path = toPathIfFileURL(path);
232+
validatePath(path);
233233
} catch (e) {
234234
return false;
235235
}
236+
const ctx = { path };
237+
binding.access(pathModule.toNamespacedPath(path), F_OK, undefined, ctx);
238+
return ctx.errno === undefined;
236239
}
237240

238241
function readFileAfterOpen(err, fd) {

0 commit comments

Comments
 (0)