From 29b0dc4ec87a6cae39fd353e4c24762aa51a2d5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Geisendo=CC=88rfer?= Date: Tue, 15 Feb 2011 08:30:58 -0500 Subject: [PATCH] Fix: fs.open callback did not fire Problem: Omitting the mode parameter causes the provided callback parameter to never fire. This was originally fixed in 6078c37b and later broken in 5f2e9093. Solution: Overwriting the value of a parameter also overwrites the reference in the arguments object. This patch works arround this fact by not touching the mode parameter until a reference to the callback has been established. --- lib/fs.js | 3 ++- test/simple/test-fs-open.js | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 test/simple/test-fs-open.js diff --git a/lib/fs.js b/lib/fs.js index 18cf7f16c15..8cd15eb04e5 100644 --- a/lib/fs.js +++ b/lib/fs.js @@ -185,10 +185,11 @@ function modeNum(m, def) { } fs.open = function(path, flags, mode, callback) { - mode = modeNum(mode, '0666'); var callback_ = arguments[arguments.length - 1]; var callback = (typeof(callback_) == 'function' ? callback_ : null); + mode = modeNum(mode, '0666'); + binding.open(path, stringToFlags(flags), mode, callback || noop); }; diff --git a/test/simple/test-fs-open.js b/test/simple/test-fs-open.js new file mode 100644 index 00000000000..2971d4608ea --- /dev/null +++ b/test/simple/test-fs-open.js @@ -0,0 +1,17 @@ +var common = require('../common'); +var assert = require('assert'); +var fs = require('fs'); + +var openFd; +fs.open(__filename, 'r', function(err, fd) { + if (err) { + throw err; + } + + openFd = fd; +}); + +process.addListener('exit', function() { + assert.ok(openFd); +}); +