summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorBartosz Sosnowski <bartosz@janeasystems.com>2018-02-12 13:03:05 +0100
committerBartosz Sosnowski <bartosz@janeasystems.com>2018-02-22 12:39:17 +0100
commitd3955d15ff5c68acf91f35177d290ff068068a05 (patch)
treea661aeeaabebdd1b193e29152beaf20a7bfe3c1b /lib
parentb1e52fe2ea99a52ace6399e9f629c965f66a2643 (diff)
downloadandroid-node-v8-d3955d15ff5c68acf91f35177d290ff068068a05.tar.gz
android-node-v8-d3955d15ff5c68acf91f35177d290ff068068a05.tar.bz2
android-node-v8-d3955d15ff5c68acf91f35177d290ff068068a05.zip
fs: use fs.access in fs.exists
Uses fs.access to implement fs.exists functionality. Fixes a issue, when a file exists but user does not have privileges to do stat on the file. Fixes: https://github.com/nodejs/node/issues/17921 PR-URL: https://github.com/nodejs/node/pull/18618 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Weijia Wang <starkwang@126.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Evan Lucas <evanlucas@me.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/fs.js14
1 files changed, 2 insertions, 12 deletions
diff --git a/lib/fs.js b/lib/fs.js
index 0b17885329..0287d81c94 100644
--- a/lib/fs.js
+++ b/lib/fs.js
@@ -234,14 +234,10 @@ fs.exists = function(path, callback) {
}
try {
- path = getPathFromURL(path);
- validatePath(path);
+ fs.access(path, fs.FS_OK, suppressedCallback);
} catch (err) {
return callback(false);
}
- var req = new FSReqWrap();
- req.oncomplete = suppressedCallback;
- binding.stat(pathModule.toNamespacedPath(path), req);
};
Object.defineProperty(fs.exists, internalUtil.promisify.custom, {
@@ -260,13 +256,7 @@ Object.defineProperty(fs.exists, internalUtil.promisify.custom, {
// TODO(joyeecheung): deprecate the never-throw-on-invalid-arguments behavior
fs.existsSync = function(path) {
try {
- path = getPathFromURL(path);
- validatePath(path);
- const ctx = { path };
- binding.stat(pathModule.toNamespacedPath(path), undefined, ctx);
- if (ctx.errno !== undefined) {
- return false;
- }
+ fs.accessSync(path, fs.FS_OK);
return true;
} catch (e) {
return false;