summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJoyee Cheung <joyeec9h3@gmail.com>2018-11-01 18:04:57 +0800
committerRich Trott <rtrott@gmail.com>2018-11-03 18:43:00 -0700
commitbcc7b7a58c13b92f6427184f3fe4583a7728f57c (patch)
treec876f44096978381f955a0b2bde8ab152e1dcc4c /lib
parent616fac9169840c76512920e66b6428971df3d289 (diff)
downloadandroid-node-v8-bcc7b7a58c13b92f6427184f3fe4583a7728f57c.tar.gz
android-node-v8-bcc7b7a58c13b92f6427184f3fe4583a7728f57c.tar.bz2
android-node-v8-bcc7b7a58c13b92f6427184f3fe4583a7728f57c.zip
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: https://github.com/nodejs/node/pull/24015 Fixes: https://github.com/nodejs/node/issues/24008 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Refael Ackermann <refack@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/fs.js7
1 files changed, 5 insertions, 2 deletions
diff --git a/lib/fs.js b/lib/fs.js
index 89c005375f..dba9049fae 100644
--- a/lib/fs.js
+++ b/lib/fs.js
@@ -228,11 +228,14 @@ Object.defineProperty(exists, internalUtil.promisify.custom, {
// TODO(joyeecheung): deprecate the never-throw-on-invalid-arguments behavior
function existsSync(path) {
try {
- fs.accessSync(path, F_OK);
- return true;
+ path = toPathIfFileURL(path);
+ validatePath(path);
} catch (e) {
return false;
}
+ const ctx = { path };
+ binding.access(pathModule.toNamespacedPath(path), F_OK, undefined, ctx);
+ return ctx.errno === undefined;
}
function readFileAfterOpen(err, fd) {