Browse Source

realpath: No sync cb() calling allowed.

v0.8.7-release
isaacs 13 years ago
parent
commit
21aa0df8b2
  1. 4
      lib/fs.js
  2. 3
      test/simple/test-fs-realpath.js

4
lib/fs.js

@ -1070,7 +1070,7 @@ fs.realpath = function realpath(p, cache, cb) {
p = pathModule.resolve(p); p = pathModule.resolve(p);
if (cache && Object.prototype.hasOwnProperty.call(cache, p)) { if (cache && Object.prototype.hasOwnProperty.call(cache, p)) {
return cb(null, cache[p]); return process.nextTick(cb.bind(null, null, cache[p]));
} }
var original = p, var original = p,
@ -1088,7 +1088,7 @@ fs.realpath = function realpath(p, cache, cb) {
// walk down the path, swapping out linked pathparts for their real // walk down the path, swapping out linked pathparts for their real
// values // values
LOOP(); return process.nextTick(LOOP);
function LOOP() { function LOOP() {
// stop if scanned past end of path // stop if scanned past end of path
if (pos >= p.length) { if (pos >= p.length) {

3
test/simple/test-fs-realpath.js

@ -515,10 +515,13 @@ function test_lying_cache_liar(cb) {
var rps = fs.realpathSync(bluff, cache); var rps = fs.realpathSync(bluff, cache);
assert.equal(cache[bluff], rps); assert.equal(cache[bluff], rps);
var nums = path.resolve('/1/2/3/4/5/6/7'); var nums = path.resolve('/1/2/3/4/5/6/7');
var called = false; // no sync cb calling!
fs.realpath(nums, cache, function(er, rp) { fs.realpath(nums, cache, function(er, rp) {
called = true;
assert.equal(cache[nums], rp); assert.equal(cache[nums], rp);
if (--n === 0) cb(); if (--n === 0) cb();
}); });
assert(called === false);
var test = path.resolve('/a/b/c/d'), var test = path.resolve('/a/b/c/d'),
expect = path.resolve('/a/b/d'); expect = path.resolve('/a/b/d');

Loading…
Cancel
Save