From 21aa0df8b2f4fb8715943c4b0bdc944554be43e8 Mon Sep 17 00:00:00 2001 From: isaacs Date: Tue, 26 Jun 2012 15:20:26 -0700 Subject: [PATCH] realpath: No sync cb() calling allowed. --- lib/fs.js | 4 ++-- test/simple/test-fs-realpath.js | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/fs.js b/lib/fs.js index 8bfc10cdd3..076ddb50c3 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 d154e4fcd9..2f126ea300 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');