Skip to content

Commit 8b3b688

Browse files
joyeecheungcodebytere
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 41712ae commit 8b3b688

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
@@ -221,11 +221,14 @@ Object.defineProperty(exists, internalUtil.promisify.custom, {
221221
// TODO(joyeecheung): deprecate the never-throw-on-invalid-arguments behavior
222222
function existsSync(path) {
223223
try {
224-
fs.accessSync(path, F_OK);
225-
return true;
224+
path = toPathIfFileURL(path);
225+
validatePath(path);
226226
} catch (e) {
227227
return false;
228228
}
229+
const ctx = { path };
230+
binding.access(pathModule.toNamespacedPath(path), F_OK, undefined, ctx);
231+
return ctx.errno === undefined;
229232
}
230233

231234
function readFileAfterOpen(err, fd) {

0 commit comments

Comments
 (0)