Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

fs: deprecate exists() and existsSync() #8418

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions doc/api/fs.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,8 @@ callback, and have some fallback logic if it is null.

## fs.exists(path, callback)

This function is **deprecated**.

Test whether or not the given path exists by checking with the file system.
Then call the `callback` argument with either true or false. Example:

Expand All @@ -658,6 +660,8 @@ and handle the error when it's not there.

## fs.existsSync(path)

This function is **deprecated**.

Synchronous version of `fs.exists`.

## Class: fs.Stats
Expand Down
8 changes: 4 additions & 4 deletions lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,23 +180,23 @@ fs.Stats.prototype.isSocket = function() {
return this._checkModeProperty(constants.S_IFSOCK);
};

fs.exists = function(path, callback) {
fs.exists = util.deprecate(function(path, callback) {
if (!nullCheck(path, cb)) return;
binding.stat(pathModule._makeLong(path), cb);
function cb(err, stats) {
if (callback) callback(err ? false : true);
}
};
}, 'fs: exists() is deprecated.');

fs.existsSync = function(path) {
fs.existsSync = util.deprecate(function(path) {
try {
nullCheck(path);
binding.stat(pathModule._makeLong(path));
return true;
} catch (e) {
return false;
}
};
}, 'fs: existsSync() is deprecated.');

fs.readFile = function(path, options, callback_) {
var callback = maybeCallback(arguments[arguments.length - 1]);
Expand Down
6 changes: 5 additions & 1 deletion test/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,12 @@ if (process.platform === 'win32') {
exports.PIPE = exports.tmpDir + '/test.sock';
exports.opensslCli = path.join(process.execPath, '..', 'openssl-cli');
}
if (!fs.existsSync(exports.opensslCli))

try {
fs.statSync(exports.opensslCli);
} catch (err) {
exports.opensslCli = false;
}

if (process.platform === 'win32') {
exports.faketimeCli = false;
Expand Down