mirror of
https://github.com/nodejs/node.git
synced 2026-11-29 14:27:57 -05:00
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 Backport-PR-URL: https://github.com/nodejs/node/pull/19654 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>
This commit is contained in:
1 parent
ae86adc086
commit
5e90fc6a85
1 file changed
+2
-9
@@ -323,12 +323,7 @@ fs.accessSync = function(path, mode) {
|
||||
};
|
||||
|
||||
fs.exists = function(path, callback) {
|
||||
if (handleError((path = getPathFromURL(path)), cb))
|
||||
return;
|
||||
if (!nullCheck(path, cb)) return;
|
||||
var req = new FSReqWrap();
|
||||
req.oncomplete = cb;
|
||||
binding.stat(pathModule.toNamespacedPath(path), req);
|
||||
fs.access(path, fs.F_OK, cb);
|
||||
function cb(err) {
|
||||
if (callback) callback(err ? false : true);
|
||||
}
|
||||
@@ -345,9 +340,7 @@ Object.defineProperty(fs.exists, internalUtil.promisify.custom, {
|
||||
|
||||
fs.existsSync = function(path) {
|
||||
try {
|
||||
handleError((path = getPathFromURL(path)));
|
||||
nullCheck(path);
|
||||
binding.stat(pathModule.toNamespacedPath(path));
|
||||
fs.accessSync(path, fs.F_OK);
|
||||
return true;
|
||||
} catch (e) {
|
||||
return false;
|
||||
|
||||
Reference in new issue
Block a user