Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Fix fs.realpath to return on error #2045

Closed
wants to merge 1 commit into from

2 participants

@bpasero

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

@bnoordhuis
Owner

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?

@bpasero

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

@bpasero

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).

@bnoordhuis
Owner

Thanks, Benjamin. Merged in b1bb17f.

@bnoordhuis bnoordhuis closed this
@bpasero

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. @bpasero
This page is out of date. Refresh to see the latest.
Showing with 1 addition and 1 deletion.
  1. +1 −1  lib/fs.js
View
2  lib/fs.js
@@ -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.