镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
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

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

‎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)