diff --git a/lib/fs.js b/lib/fs.js index 8bfc10cdd36..076ddb50c37 100644 --- a/lib/fs.js +++ b/lib/fs.js @@ -1070,7 +1070,7 @@ fs.realpath = function realpath(p, cache, cb) { p = pathModule.resolve(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, @@ -1088,7 +1088,7 @@ fs.realpath = function realpath(p, cache, cb) { // walk down the path, swapping out linked pathparts for their real // values - LOOP(); + return process.nextTick(LOOP); function LOOP() { // stop if scanned past end of path if (pos >= p.length) { diff --git a/test/simple/test-fs-realpath.js b/test/simple/test-fs-realpath.js index d154e4fcd9e..2f126ea3004 100644 --- a/test/simple/test-fs-realpath.js +++ b/test/simple/test-fs-realpath.js @@ -515,10 +515,13 @@ function test_lying_cache_liar(cb) { var rps = fs.realpathSync(bluff, cache); assert.equal(cache[bluff], rps); 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) { + called = true; assert.equal(cache[nums], rp); if (--n === 0) cb(); }); + assert(called === false); var test = path.resolve('/a/b/c/d'), expect = path.resolve('/a/b/d');