Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
fs: make mkdir() call callback if mode is omitted
Browse files Browse the repository at this point in the history
Fixes #2043.
  • Loading branch information
bnoordhuis committed Nov 8, 2011
1 parent 105d178 commit 04958e8
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@ fs.fsyncSync = function(fd) {
};

fs.mkdir = function(path, mode, callback) {
if (typeof mode === 'function') callback = mode;
binding.mkdir(path, modeNum(mode, 511 /*=0777*/), callback || noop);
};

Expand Down
84 changes: 84 additions & 0 deletions test/simple/test-fs-mkdir.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.

var common = require('../common');
var assert = require('assert');
var path = require('path');
var fs = require('fs');

function unlink(pathname) {
try {
fs.rmdirSync(pathname);
} catch (e) {
}
}

(function() {
var ncalls = 0;
var pathname = common.tmpDir + '/test1';

unlink(pathname);

fs.mkdir(pathname, function(err) {
assert.equal(err, null);
assert.equal(path.existsSync(pathname), true);
ncalls++;
});

process.on('exit', function() {
unlink(pathname);
assert.equal(ncalls, 1);
});
})();

(function() {
var ncalls = 0;
var pathname = common.tmpDir + '/test2';

unlink(pathname);

fs.mkdir(pathname, 511 /*=0777*/, function(err) {
assert.equal(err, null);
assert.equal(path.existsSync(pathname), true);
ncalls++;
});

process.on('exit', function() {
unlink(pathname);
assert.equal(ncalls, 1);
});
})();

(function() {
var pathname = common.tmpDir + '/test3';

unlink(pathname);
fs.mkdirSync(pathname);

var exists = path.existsSync(pathname);
unlink(pathname);

assert.equal(exists, true);
})();

// Keep the event loop alive so the async mkdir() requests
// have a chance to run (since they don't ref the event loop).
process.nextTick(function(){});

0 comments on commit 04958e8

Please sign in to comment.