Expose posix realpath on windows as well
This commit is contained in:
parent
60b45dcbb6
commit
6332a4cf00
52
lib/fs.js
52
lib/fs.js
@ -893,47 +893,11 @@ fs.unwatchFile = function(filename) {
|
|||||||
|
|
||||||
var normalize = pathModule.normalize;
|
var normalize = pathModule.normalize;
|
||||||
|
|
||||||
if (isWindows) {
|
// Regexp that finds the next partion of a (partial) path
|
||||||
// Node doesn't support symlinks / lstat on windows. Hence realpath is just
|
// result is [base_with_slash, base], e.g. ['somedir/', 'somedir']
|
||||||
// the same as path.resolve that fails if the path doesn't exists.
|
var nextPartRe = /(.*?)(?:[\/]+|$)/g;
|
||||||
|
|
||||||
// windows version
|
fs.realpathSync = function realpathSync(p, cache) {
|
||||||
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
|
|
||||||
// result is [base_with_slash, base], e.g. ['somedir/', 'somedir']
|
|
||||||
var nextPartRe = /(.*?)(?:[\/]+|$)/g;
|
|
||||||
|
|
||||||
// posix version
|
|
||||||
fs.realpathSync = function realpathSync(p, cache) {
|
|
||||||
// make p is absolute
|
// make p is absolute
|
||||||
p = pathModule.resolve(p);
|
p = pathModule.resolve(p);
|
||||||
|
|
||||||
@ -1003,11 +967,10 @@ if (isWindows) {
|
|||||||
if (cache) cache[original] = p;
|
if (cache) cache[original] = p;
|
||||||
|
|
||||||
return p;
|
return p;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// 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;
|
||||||
cache = null;
|
cache = null;
|
||||||
@ -1106,9 +1069,8 @@ if (isWindows) {
|
|||||||
|
|
||||||
return process.nextTick(LOOP);
|
return process.nextTick(LOOP);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
var pool;
|
var pool;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user