Skip to content

Commit

Permalink
fs: use fs.access in fs.exists
Browse files Browse the repository at this point in the history
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: #17921

Backport-PR-URL: #19654
PR-URL: #18618
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Ben Noordhuis <[email protected]>
Reviewed-By: Richard Lau <[email protected]>
Reviewed-By: Weijia Wang <[email protected]>
Reviewed-By: Joyee Cheung <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: Evan Lucas <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
bzoz authored and targos committed Apr 4, 2018
1 parent ae86adc commit 5e90fc6
Showing 1 changed file with 2 additions and 9 deletions.
11 changes: 2 additions & 9 deletions lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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;
Expand Down

0 comments on commit 5e90fc6

Please sign in to comment.