diff options
author | Bartosz Sosnowski <bartosz@janeasystems.com> | 2018-02-12 13:03:05 +0100 |
---|---|---|
committer | Bartosz Sosnowski <bartosz@janeasystems.com> | 2018-02-22 12:39:17 +0100 |
commit | d3955d15ff5c68acf91f35177d290ff068068a05 (patch) | |
tree | a661aeeaabebdd1b193e29152beaf20a7bfe3c1b /lib | |
parent | b1e52fe2ea99a52ace6399e9f629c965f66a2643 (diff) | |
download | android-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.js | 14 |
1 files changed, 2 insertions, 12 deletions
@@ -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; |