pax_global_header00006660000000000000000000000064121116547010014510gustar00rootroot0000000000000052 comment=f104bbb4c2044892dc95300a5f397657919a858a node-mkdirp-0.3.5/000077500000000000000000000000001211165470100137265ustar00rootroot00000000000000node-mkdirp-0.3.5/.travis.yml000066400000000000000000000000531211165470100160350ustar00rootroot00000000000000language: node_js node_js: - 0.4 - 0.6 node-mkdirp-0.3.5/LICENSE000066400000000000000000000021651211165470100147370ustar00rootroot00000000000000Copyright 2010 James Halliday (mail@substack.net) This project is free software released under the MIT/X11 license: 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. node-mkdirp-0.3.5/examples/000077500000000000000000000000001211165470100155445ustar00rootroot00000000000000node-mkdirp-0.3.5/examples/pow.js000066400000000000000000000002161211165470100167060ustar00rootroot00000000000000var mkdirp = require('mkdirp'); mkdirp('/tmp/foo/bar/baz', function (err) { if (err) console.error(err) else console.log('pow!') }); node-mkdirp-0.3.5/index.js000066400000000000000000000045031211165470100153750ustar00rootroot00000000000000var path = require('path'); var fs = require('fs'); module.exports = mkdirP.mkdirp = mkdirP.mkdirP = mkdirP; function mkdirP (p, mode, f, made) { if (typeof mode === 'function' || mode === undefined) { f = mode; mode = 0777 & (~process.umask()); } if (!made) made = null; var cb = f || function () {}; if (typeof mode === 'string') mode = parseInt(mode, 8); p = path.resolve(p); fs.mkdir(p, mode, function (er) { if (!er) { made = made || p; return cb(null, made); } switch (er.code) { case 'ENOENT': mkdirP(path.dirname(p), mode, function (er, made) { if (er) cb(er, made); else mkdirP(p, mode, cb, made); }); break; // In the case of any other error, just see if there's a dir // there already. If so, then hooray! If not, then something // is borked. default: fs.stat(p, function (er2, stat) { // if the stat fails, then that's super weird. // let the original error be the failure reason. if (er2 || !stat.isDirectory()) cb(er, made) else cb(null, made); }); break; } }); } mkdirP.sync = function sync (p, mode, made) { if (mode === undefined) { mode = 0777 & (~process.umask()); } if (!made) made = null; if (typeof mode === 'string') mode = parseInt(mode, 8); p = path.resolve(p); try { fs.mkdirSync(p, mode); made = made || p; } catch (err0) { switch (err0.code) { case 'ENOENT' : made = sync(path.dirname(p), mode, made); sync(p, mode, made); break; // In the case of any other error, just see if there's a dir // there already. If so, then hooray! If not, then something // is borked. default: var stat; try { stat = fs.statSync(p); } catch (err1) { throw err0; } if (!stat.isDirectory()) throw err0; break; } } return made; }; node-mkdirp-0.3.5/package.json000066400000000000000000000010131211165470100162070ustar00rootroot00000000000000{ "name" : "mkdirp", "description" : "Recursively mkdir, like `mkdir -p`", "version" : "0.3.5", "author" : "James Halliday (http://substack.net)", "main" : "./index", "keywords" : [ "mkdir", "directory" ], "repository" : { "type" : "git", "url" : "http://github.com/substack/node-mkdirp.git" }, "scripts" : { "test" : "tap test/*.js" }, "devDependencies" : { "tap" : "~0.4.0" }, "license" : "MIT" } node-mkdirp-0.3.5/readme.markdown000066400000000000000000000021441211165470100167300ustar00rootroot00000000000000# mkdirp Like `mkdir -p`, but in node.js! [![build status](https://secure.travis-ci.org/substack/node-mkdirp.png)](http://travis-ci.org/substack/node-mkdirp) # example ## pow.js ```js var mkdirp = require('mkdirp'); mkdirp('/tmp/foo/bar/baz', function (err) { if (err) console.error(err) else console.log('pow!') }); ``` Output ``` pow! ``` And now /tmp/foo/bar/baz exists, huzzah! # methods ```js var mkdirp = require('mkdirp'); ``` ## mkdirp(dir, mode, cb) Create a new directory and any necessary subdirectories at `dir` with octal permission string `mode`. If `mode` isn't specified, it defaults to `0777 & (~process.umask())`. `cb(err, made)` fires with the error or the first directory `made` that had to be created, if any. ## mkdirp.sync(dir, mode) Synchronously create a new directory and any necessary subdirectories at `dir` with octal permission string `mode`. If `mode` isn't specified, it defaults to `0777 & (~process.umask())`. Returns the first directory that had to be created, if any. # install With [npm](http://npmjs.org) do: ``` npm install mkdirp ``` # license MIT node-mkdirp-0.3.5/test/000077500000000000000000000000001211165470100147055ustar00rootroot00000000000000node-mkdirp-0.3.5/test/chmod.js000066400000000000000000000020131211165470100163310ustar00rootroot00000000000000var mkdirp = require('../').mkdirp; var path = require('path'); var fs = require('fs'); var test = require('tap').test; var ps = [ '', 'tmp' ]; for (var i = 0; i < 25; i++) { var dir = Math.floor(Math.random() * Math.pow(16,4)).toString(16); ps.push(dir); } var file = ps.join('/'); test('chmod-pre', function (t) { var mode = 0744 mkdirp(file, mode, function (er) { t.ifError(er, 'should not error'); fs.stat(file, function (er, stat) { t.ifError(er, 'should exist'); t.ok(stat && stat.isDirectory(), 'should be directory'); t.equal(stat && stat.mode & 0777, mode, 'should be 0744'); t.end(); }); }); }); test('chmod', function (t) { var mode = 0755 mkdirp(file, mode, function (er) { t.ifError(er, 'should not error'); fs.stat(file, function (er, stat) { t.ifError(er, 'should exist'); t.ok(stat && stat.isDirectory(), 'should be directory'); t.end(); }); }); }); node-mkdirp-0.3.5/test/clobber.js000066400000000000000000000014651211165470100166610ustar00rootroot00000000000000var mkdirp = require('../').mkdirp; var path = require('path'); var fs = require('fs'); var test = require('tap').test; var ps = [ '', 'tmp' ]; for (var i = 0; i < 25; i++) { var dir = Math.floor(Math.random() * Math.pow(16,4)).toString(16); ps.push(dir); } var file = ps.join('/'); // a file in the way var itw = ps.slice(0, 3).join('/'); test('clobber-pre', function (t) { console.error("about to write to "+itw) fs.writeFileSync(itw, 'I AM IN THE WAY, THE TRUTH, AND THE LIGHT.'); fs.stat(itw, function (er, stat) { t.ifError(er) t.ok(stat && stat.isFile(), 'should be file') t.end() }) }) test('clobber', function (t) { t.plan(2); mkdirp(file, 0755, function (err) { t.ok(err); t.equal(err.code, 'ENOTDIR'); t.end(); }); }); node-mkdirp-0.3.5/test/mkdirp.js000066400000000000000000000016121211165470100165310ustar00rootroot00000000000000var mkdirp = require('../'); var path = require('path'); var fs = require('fs'); var test = require('tap').test; test('woo', function (t) { t.plan(2); var x = Math.floor(Math.random() * Math.pow(16,4)).toString(16); var y = Math.floor(Math.random() * Math.pow(16,4)).toString(16); var z = Math.floor(Math.random() * Math.pow(16,4)).toString(16); var file = '/tmp/' + [x,y,z].join('/'); mkdirp(file, 0755, function (err) { if (err) t.fail(err); else path.exists(file, function (ex) { if (!ex) t.fail('file not created') else fs.stat(file, function (err, stat) { if (err) t.fail(err) else { t.equal(stat.mode & 0777, 0755); t.ok(stat.isDirectory(), 'target not a directory'); t.end(); } }) }) }); }); node-mkdirp-0.3.5/test/perm.js000066400000000000000000000015541211165470100162130ustar00rootroot00000000000000var mkdirp = require('../'); var path = require('path'); var fs = require('fs'); var test = require('tap').test; test('async perm', function (t) { t.plan(2); var file = '/tmp/' + (Math.random() * (1<<30)).toString(16); mkdirp(file, 0755, function (err) { if (err) t.fail(err); else path.exists(file, function (ex) { if (!ex) t.fail('file not created') else fs.stat(file, function (err, stat) { if (err) t.fail(err) else { t.equal(stat.mode & 0777, 0755); t.ok(stat.isDirectory(), 'target not a directory'); t.end(); } }) }) }); }); test('async root perm', function (t) { mkdirp('/tmp', 0755, function (err) { if (err) t.fail(err); t.end(); }); t.end(); }); node-mkdirp-0.3.5/test/perm_sync.js000066400000000000000000000020431211165470100172410ustar00rootroot00000000000000var mkdirp = require('../'); var path = require('path'); var fs = require('fs'); var test = require('tap').test; test('sync perm', function (t) { t.plan(2); var file = '/tmp/' + (Math.random() * (1<<30)).toString(16) + '.json'; mkdirp.sync(file, 0755); path.exists(file, function (ex) { if (!ex) t.fail('file not created') else fs.stat(file, function (err, stat) { if (err) t.fail(err) else { t.equal(stat.mode & 0777, 0755); t.ok(stat.isDirectory(), 'target not a directory'); t.end(); } }) }); }); test('sync root perm', function (t) { t.plan(1); var file = '/tmp'; mkdirp.sync(file, 0755); path.exists(file, function (ex) { if (!ex) t.fail('file not created') else fs.stat(file, function (err, stat) { if (err) t.fail(err) else { t.ok(stat.isDirectory(), 'target not a directory'); t.end(); } }) }); }); node-mkdirp-0.3.5/test/race.js000066400000000000000000000021371211165470100161600ustar00rootroot00000000000000var mkdirp = require('../').mkdirp; var path = require('path'); var fs = require('fs'); var test = require('tap').test; test('race', function (t) { t.plan(4); var ps = [ '', 'tmp' ]; for (var i = 0; i < 25; i++) { var dir = Math.floor(Math.random() * Math.pow(16,4)).toString(16); ps.push(dir); } var file = ps.join('/'); var res = 2; mk(file, function () { if (--res === 0) t.end(); }); mk(file, function () { if (--res === 0) t.end(); }); function mk (file, cb) { mkdirp(file, 0755, function (err) { if (err) t.fail(err); else path.exists(file, function (ex) { if (!ex) t.fail('file not created') else fs.stat(file, function (err, stat) { if (err) t.fail(err) else { t.equal(stat.mode & 0777, 0755); t.ok(stat.isDirectory(), 'target not a directory'); if (cb) cb(); } }) }) }); } }); node-mkdirp-0.3.5/test/rel.js000066400000000000000000000017451211165470100160340ustar00rootroot00000000000000var mkdirp = require('../'); var path = require('path'); var fs = require('fs'); var test = require('tap').test; test('rel', function (t) { t.plan(2); var x = Math.floor(Math.random() * Math.pow(16,4)).toString(16); var y = Math.floor(Math.random() * Math.pow(16,4)).toString(16); var z = Math.floor(Math.random() * Math.pow(16,4)).toString(16); var cwd = process.cwd(); process.chdir('/tmp'); var file = [x,y,z].join('/'); mkdirp(file, 0755, function (err) { if (err) t.fail(err); else path.exists(file, function (ex) { if (!ex) t.fail('file not created') else fs.stat(file, function (err, stat) { if (err) t.fail(err) else { process.chdir(cwd); t.equal(stat.mode & 0777, 0755); t.ok(stat.isDirectory(), 'target not a directory'); t.end(); } }) }) }); }); node-mkdirp-0.3.5/test/return.js000066400000000000000000000014721211165470100165660ustar00rootroot00000000000000var mkdirp = require('../'); var path = require('path'); var fs = require('fs'); var test = require('tap').test; test('return value', function (t) { t.plan(4); var x = Math.floor(Math.random() * Math.pow(16,4)).toString(16); var y = Math.floor(Math.random() * Math.pow(16,4)).toString(16); var z = Math.floor(Math.random() * Math.pow(16,4)).toString(16); var file = '/tmp/' + [x,y,z].join('/'); // should return the first dir created. // By this point, it would be profoundly surprising if /tmp didn't // already exist, since every other test makes things in there. mkdirp(file, function (err, made) { t.ifError(err); t.equal(made, '/tmp/' + x); mkdirp(file, function (err, made) { t.ifError(err); t.equal(made, null); }); }); }); node-mkdirp-0.3.5/test/return_sync.js000066400000000000000000000015271211165470100176230ustar00rootroot00000000000000var mkdirp = require('../'); var path = require('path'); var fs = require('fs'); var test = require('tap').test; test('return value', function (t) { t.plan(2); var x = Math.floor(Math.random() * Math.pow(16,4)).toString(16); var y = Math.floor(Math.random() * Math.pow(16,4)).toString(16); var z = Math.floor(Math.random() * Math.pow(16,4)).toString(16); var file = '/tmp/' + [x,y,z].join('/'); // should return the first dir created. // By this point, it would be profoundly surprising if /tmp didn't // already exist, since every other test makes things in there. // Note that this will throw on failure, which will fail the test. var made = mkdirp.sync(file); t.equal(made, '/tmp/' + x); // making the same file again should have no effect. made = mkdirp.sync(file); t.equal(made, null); }); node-mkdirp-0.3.5/test/root.js000066400000000000000000000007161211165470100162320ustar00rootroot00000000000000var mkdirp = require('../'); var path = require('path'); var fs = require('fs'); var test = require('tap').test; test('root', function (t) { // '/' on unix, 'c:/' on windows. var file = path.resolve('/'); mkdirp(file, 0755, function (err) { if (err) throw err fs.stat(file, function (er, stat) { if (er) throw er t.ok(stat.isDirectory(), 'target is a directory'); t.end(); }) }); }); node-mkdirp-0.3.5/test/sync.js000066400000000000000000000015711211165470100162230ustar00rootroot00000000000000var mkdirp = require('../'); var path = require('path'); var fs = require('fs'); var test = require('tap').test; test('sync', function (t) { t.plan(2); var x = Math.floor(Math.random() * Math.pow(16,4)).toString(16); var y = Math.floor(Math.random() * Math.pow(16,4)).toString(16); var z = Math.floor(Math.random() * Math.pow(16,4)).toString(16); var file = '/tmp/' + [x,y,z].join('/'); try { mkdirp.sync(file, 0755); } catch (err) { t.fail(err); return t.end(); } path.exists(file, function (ex) { if (!ex) t.fail('file not created') else fs.stat(file, function (err, stat) { if (err) t.fail(err) else { t.equal(stat.mode & 0777, 0755); t.ok(stat.isDirectory(), 'target not a directory'); t.end(); } }); }); }); node-mkdirp-0.3.5/test/umask.js000066400000000000000000000016561211165470100163730ustar00rootroot00000000000000var mkdirp = require('../'); var path = require('path'); var fs = require('fs'); var test = require('tap').test; test('implicit mode from umask', function (t) { t.plan(2); var x = Math.floor(Math.random() * Math.pow(16,4)).toString(16); var y = Math.floor(Math.random() * Math.pow(16,4)).toString(16); var z = Math.floor(Math.random() * Math.pow(16,4)).toString(16); var file = '/tmp/' + [x,y,z].join('/'); mkdirp(file, function (err) { if (err) t.fail(err); else path.exists(file, function (ex) { if (!ex) t.fail('file not created') else fs.stat(file, function (err, stat) { if (err) t.fail(err) else { t.equal(stat.mode & 0777, 0777 & (~process.umask())); t.ok(stat.isDirectory(), 'target not a directory'); t.end(); } }) }) }); }); node-mkdirp-0.3.5/test/umask_sync.js000066400000000000000000000016261211165470100174240ustar00rootroot00000000000000var mkdirp = require('../'); var path = require('path'); var fs = require('fs'); var test = require('tap').test; test('umask sync modes', function (t) { t.plan(2); var x = Math.floor(Math.random() * Math.pow(16,4)).toString(16); var y = Math.floor(Math.random() * Math.pow(16,4)).toString(16); var z = Math.floor(Math.random() * Math.pow(16,4)).toString(16); var file = '/tmp/' + [x,y,z].join('/'); try { mkdirp.sync(file); } catch (err) { t.fail(err); return t.end(); } path.exists(file, function (ex) { if (!ex) t.fail('file not created') else fs.stat(file, function (err, stat) { if (err) t.fail(err) else { t.equal(stat.mode & 0777, (0777 & (~process.umask()))); t.ok(stat.isDirectory(), 'target not a directory'); t.end(); } }); }); });