Skip to content

Commit 5e90fc6

Browse files
bzoztargos
authored andcommitted
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: #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]>
1 parent ae86adc commit 5e90fc6

File tree

1 file changed

+2
-9
lines changed

1 file changed

+2
-9
lines changed

lib/fs.js

+2-9
Original file line numberDiff line numberDiff line change
@@ -323,12 +323,7 @@ fs.accessSync = function(path, mode) {
323323
};
324324

325325
fs.exists = function(path, callback) {
326-
if (handleError((path = getPathFromURL(path)), cb))
327-
return;
328-
if (!nullCheck(path, cb)) return;
329-
var req = new FSReqWrap();
330-
req.oncomplete = cb;
331-
binding.stat(pathModule.toNamespacedPath(path), req);
326+
fs.access(path, fs.F_OK, cb);
332327
function cb(err) {
333328
if (callback) callback(err ? false : true);
334329
}
@@ -345,9 +340,7 @@ Object.defineProperty(fs.exists, internalUtil.promisify.custom, {
345340

346341
fs.existsSync = function(path) {
347342
try {
348-
handleError((path = getPathFromURL(path)));
349-
nullCheck(path);
350-
binding.stat(pathModule.toNamespacedPath(path));
343+
fs.accessSync(path, fs.F_OK);
351344
return true;
352345
} catch (e) {
353346
return false;

0 commit comments

Comments
 (0)