Browse Source

fs: mkdtemp shouldn't crash if no callback passed

As it is, `fs.mkdtemp` crashes with a C++ assertion if the callback
function is not passed. This patch uses `maybeCallback` to create one,
if no callback function is passed.

PR-URL: https://github.com/nodejs/node/pull/6828
Reviewed-By: Brian White <mscdex@mscdex.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
v7.x
Sakthipriyan Vairamani 9 years ago
committed by James M Snell
parent
commit
dcbf246b35
  1. 3
      lib/fs.js
  2. 2
      test/parallel/test-fs-mkdtemp.js

3
lib/fs.js

@ -2000,7 +2000,8 @@ SyncWriteStream.prototype.destroy = function() {
SyncWriteStream.prototype.destroySoon = SyncWriteStream.prototype.destroy;
fs.mkdtemp = function(prefix, options, callback) {
fs.mkdtemp = function(prefix, options, callback_) {
var callback = maybeCallback(callback_);
if (!prefix || typeof prefix !== 'string')
throw new TypeError('filename prefix is required');

2
test/parallel/test-fs-mkdtemp.js

@ -25,3 +25,5 @@ fs.mkdtemp(
assert(common.fileExists(folder));
})
);
assert.doesNotThrow(() => fs.mkdtemp(path.join(common.tmpDir, 'bar-')));

Loading…
Cancel
Save