Expose posix realpath on windows as well

This commit is contained in:
isaacs 2012-06-08 15:26:04 -07:00
parent 60b45dcbb6
commit 6332a4cf00

View File

@ -893,46 +893,10 @@ fs.unwatchFile = function(filename) {
var normalize = pathModule.normalize; var normalize = pathModule.normalize;
if (isWindows) {
// Node doesn't support symlinks / lstat on windows. Hence realpath is just
// the same as path.resolve that fails if the path doesn't exists.
// windows version
fs.realpathSync = function realpathSync(p, cache) {
p = pathModule.resolve(p);
if (cache && Object.prototype.hasOwnProperty.call(cache, p)) {
return cache[p];
}
fs.statSync(p);
if (cache) cache[p] = p;
return p;
};
// windows version
fs.realpath = function(p, cache, cb) {
if (typeof cb !== 'function') {
cb = cache;
cache = null;
}
p = pathModule.resolve(p);
if (cache && Object.prototype.hasOwnProperty.call(cache, p)) {
return cb(null, cache[p]);
}
fs.stat(p, function(err) {
if (err) return cb(err);
if (cache) cache[p] = p;
cb(null, p);
});
};
} else /* posix */ {
// Regexp that finds the next partion of a (partial) path // Regexp that finds the next partion of a (partial) path
// result is [base_with_slash, base], e.g. ['somedir/', 'somedir'] // result is [base_with_slash, base], e.g. ['somedir/', 'somedir']
var nextPartRe = /(.*?)(?:[\/]+|$)/g; var nextPartRe = /(.*?)(?:[\/]+|$)/g;
// posix version
fs.realpathSync = function realpathSync(p, cache) { fs.realpathSync = function realpathSync(p, cache) {
// make p is absolute // make p is absolute
p = pathModule.resolve(p); p = pathModule.resolve(p);
@ -1006,7 +970,6 @@ if (isWindows) {
}; };
// posix version
fs.realpath = function realpath(p, cache, cb) { fs.realpath = function realpath(p, cache, cb) {
if (typeof cb !== 'function') { if (typeof cb !== 'function') {
cb = cache; cb = cache;
@ -1108,7 +1071,6 @@ if (isWindows) {
} }
}; };
}
var pool; var pool;