Skip to content

Commit 424be28

Browse files
joyeecheungtargos
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 <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Refael Ackermann <refack@gmail.com>
1 parent 7ee0cea commit 424be28

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

lib/fs.js

+5-2
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)