Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fix fs.realpath to return on error #2045

Closed
wants to merge 1 commit into from

2 participants

Benjamin Pasero Ben Noordhuis
Benjamin Pasero

There is a missing return statement on error for fs.realpath.

Ben Noordhuis

Patch LGTM. Can you sign the CLA?

Sanity check: what does test/simple/test-fs-realpath.js with the below patch applied do with and without your patch?

diff --git a/test/simple/test-fs-realpath.js b/test/simple/test-fs-realpath.js
index 27ac0b8..b2c8e9b 100644
--- a/test/simple/test-fs-realpath.js
+++ b/test/simple/test-fs-realpath.js
@@ -79,6 +79,19 @@ function bashRealpath(path, callback) {
 }

 // sub-tests:
+function test_simple_error_callback() {
+  var ncalls = 0;
+
+  fs.realpath('/this/path/does/not/exist', function(err, s) {
+    assert(err);
+    assert(!s);
+    ncalls++;
+  });
+
+  process.on('exit', function() {
+    assert.equal(ncalls, 1);
+  });
+}

 function test_simple_relative_symlink(callback) {
   console.log('test_simple_relative_symlink');
@@ -415,6 +428,7 @@ function test_lying_cache_liar(cb) {
 // ----------------------------------------------------------------------------

 var tests = [
+  test_simple_error_callback,
   test_simple_relative_symlink,
   test_simple_absolute_symlink,
   test_deep_relative_file_symlink,

@piscisaureus: Can you confirm the issue?

Benjamin Pasero

I signed the CLA electronically. I hope its fine, otherwise let me know. Thanks.

Benjamin Pasero

Your test shows that the callback is being called twice, it demonstrates the issue if my patch is not applied (ncalls will be 2 in that case).

Ben Noordhuis

Thanks, Benjamin. Merged in b1bb17f.

Ben Noordhuis bnoordhuis closed this
Benjamin Pasero

That was quick, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 8, 2011
  1. Benjamin Pasero
This page is out of date. Refresh to see the latest.
Showing with 1 addition and 1 deletion.
  1. +1 −1  lib/fs.js
2  lib/fs.js
View
@@ -774,7 +774,7 @@ if (isWindows) {
return cb(null, cache[p]);
}
fs.stat(p, function(err) {
- if (err) cb(err);
+ if (err) return cb(err);
if (cache) cache[p] = p;
cb(null, p);
});
Something went wrong with that request. Please try again.