diff options
author | Maciej MaĆecki <maciej.malecki@notimplemented.org> | 2012-01-21 05:37:57 +0400 |
---|---|---|
committer | Ben Noordhuis <info@bnoordhuis.nl> | 2012-01-21 17:37:14 +0400 |
commit | e10ed097cb3b506009ab28af4dec93402aa48693 (patch) | |
tree | e262d6ffe8b9bc20aa2c4fda1e2c85ddec49364a /lib | |
parent | 56e34c2f814905a8fc3329485c64a70d59d8eeba (diff) |
path fs: move `path.exists*` to `fs.exists*`
`path.exists*` functions show a deprecation warning and call functions
from `fs`. They should be removed later.
test: fix references to `path.exists*` in tests
test fs: add test for `fs.exists` and `fs.existsSync`
doc: reflect moving `path.exists*` to `fs`
Diffstat (limited to 'lib')
-rw-r--r-- | lib/fs.js | 15 | ||||
-rw-r--r-- | lib/path.js | 14 |
2 files changed, 20 insertions, 9 deletions
diff --git a/lib/fs.js b/lib/fs.js index 51637c13a64..2dc11a750d0 100644 --- a/lib/fs.js +++ b/lib/fs.js @@ -71,6 +71,21 @@ fs.Stats.prototype.isSocket = function() { return this._checkModeProperty(constants.S_IFSOCK); }; +fs.exists = function(path, callback) { + binding.stat(path, function(err, stats) { + if (callback) callback(err ? false : true); + }); +}; + +fs.existsSync = function(path) { + try { + binding.stat(path); + return true; + } catch (e) { + return false; + } +}; + fs.readFile = function(path, encoding_) { var encoding = typeof(encoding_) === 'string' ? encoding_ : null; var callback = arguments[arguments.length - 1]; diff --git a/lib/path.js b/lib/path.js index b70225b1d62..6a744dfeca7 100644 --- a/lib/path.js +++ b/lib/path.js @@ -21,6 +21,7 @@ var isWindows = process.platform === 'win32'; +var _deprecationWarning = require('util')._deprecationWarning; // resolves . and .. elements in a path array with directory names there @@ -402,19 +403,14 @@ exports.extname = function(path) { exports.exists = function(path, callback) { - process.binding('fs').stat(path, function(err, stats) { - if (callback) callback(err ? false : true); - }); + _deprecationWarning('path', '`path.exists` is now called `fs.exists`'); + require('fs').exists(path, callback); }; exports.existsSync = function(path) { - try { - process.binding('fs').stat(path); - return true; - } catch (e) { - return false; - } + _deprecationWarning('path', '`path.exists` is now called `fs.exists`'); + return require('fs').existsSync(path); }; |