pax_global_header00006660000000000000000000000064123320442730014512gustar00rootroot0000000000000052 comment=b98bedf92798ed73c87413eaf413d01dbe094a09 node-mkdirp-0.5.0/000077500000000000000000000000001233204427300137255ustar00rootroot00000000000000node-mkdirp-0.5.0/.travis.yml000066400000000000000000000000661233204427300160400ustar00rootroot00000000000000language: node_js node_js: - 0.6 - 0.8 - "0.10" node-mkdirp-0.5.0/LICENSE000066400000000000000000000021651233204427300147360ustar00rootroot00000000000000Copyright 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.5.0/bin/000077500000000000000000000000001233204427300144755ustar00rootroot00000000000000node-mkdirp-0.5.0/bin/cmd.js000077500000000000000000000013331233204427300156010ustar00rootroot00000000000000#!/usr/bin/env node var mkdirp = require('../'); var minimist = require('minimist'); var fs = require('fs'); var argv = minimist(process.argv.slice(2), { alias: { m: 'mode', h: 'help' }, string: [ 'mode' ] }); if (argv.help) { fs.createReadStream(__dirname + '/usage.txt').pipe(process.stdout); return; } var paths = argv._.slice(); var mode = argv.mode ? parseInt(argv.mode, 8) : undefined; (function next () { if (paths.length === 0) return; var p = paths.shift(); if (mode === undefined) mkdirp(p, cb) else mkdirp(p, mode, cb) function cb (err) { if (err) { console.error(err.message); process.exit(1); } else next(); } })(); node-mkdirp-0.5.0/bin/usage.txt000066400000000000000000000004731233204427300163460ustar00rootroot00000000000000usage: mkdirp [DIR1,DIR2..] {OPTIONS} Create each supplied directory including any necessary parent directories that don't yet exist. If the directory already exists, do nothing. OPTIONS are: -m, --mode If a directory needs to be created, set the mode as an octal permission string. node-mkdirp-0.5.0/examples/000077500000000000000000000000001233204427300155435ustar00rootroot00000000000000node-mkdirp-0.5.0/examples/pow.js000066400000000000000000000002161233204427300167050ustar00rootroot00000000000000var mkdirp = require('mkdirp'); mkdirp('/tmp/foo/bar/baz', function (err) { if (err) console.error(err) else console.log('pow!') }); node-mkdirp-0.5.0/index.js000066400000000000000000000050431233204427300153740ustar00rootroot00000000000000var path = require('path'); var fs = require('fs'); module.exports = mkdirP.mkdirp = mkdirP.mkdirP = mkdirP; function mkdirP (p, opts, f, made) { if (typeof opts === 'function') { f = opts; opts = {}; } else if (!opts || typeof opts !== 'object') { opts = { mode: opts }; } var mode = opts.mode; var xfs = opts.fs || fs; if (mode === undefined) { mode = 0777 & (~process.umask()); } if (!made) made = null; var cb = f || function () {}; p = path.resolve(p); xfs.mkdir(p, mode, function (er) { if (!er) { made = made || p; return cb(null, made); } switch (er.code) { case 'ENOENT': mkdirP(path.dirname(p), opts, function (er, made) { if (er) cb(er, made); else mkdirP(p, opts, 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: xfs.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, opts, made) { if (!opts || typeof opts !== 'object') { opts = { mode: opts }; } var mode = opts.mode; var xfs = opts.fs || fs; if (mode === undefined) { mode = 0777 & (~process.umask()); } if (!made) made = null; p = path.resolve(p); try { xfs.mkdirSync(p, mode); made = made || p; } catch (err0) { switch (err0.code) { case 'ENOENT' : made = sync(path.dirname(p), opts, made); sync(p, opts, 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 = xfs.statSync(p); } catch (err1) { throw err0; } if (!stat.isDirectory()) throw err0; break; } } return made; }; node-mkdirp-0.5.0/package.json000066400000000000000000000010531233204427300162120ustar00rootroot00000000000000{ "name": "mkdirp", "description": "Recursively mkdir, like `mkdir -p`", "version": "0.5.0", "author": "James Halliday (http://substack.net)", "main": "./index", "keywords": [ "mkdir", "directory" ], "repository": { "type": "git", "url": "https://github.com/substack/node-mkdirp.git" }, "scripts": { "test": "tap test/*.js" }, "dependencies": { "minimist": "0.0.8" }, "devDependencies": { "tap": "~0.4.0", "mock-fs": "~2.2.0" }, "bin": "bin/cmd.js", "license": "MIT" } node-mkdirp-0.5.0/readme.markdown000066400000000000000000000040571233204427300167340ustar00rootroot00000000000000# 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, opts, cb) Create a new directory and any necessary subdirectories at `dir` with octal permission string `opts.mode`. If `opts` is a non-object, it will be treated as the `opts.mode`. If `opts.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. You can optionally pass in an alternate `fs` implementation by passing in `opts.fs`. Your implementation should have `opts.fs.mkdir(path, mode, cb)` and `opts.fs.stat(path, cb)`. ## mkdirp.sync(dir, opts) Synchronously create a new directory and any necessary subdirectories at `dir` with octal permission string `opts.mode`. If `opts` is a non-object, it will be treated as the `opts.mode`. If `opts.mode` isn't specified, it defaults to `0777 & (~process.umask())`. Returns the first directory that had to be created, if any. You can optionally pass in an alternate `fs` implementation by passing in `opts.fs`. Your implementation should have `opts.fs.mkdirSync(path, mode)` and `opts.fs.statSync(path)`. # usage This package also ships with a `mkdirp` command. ``` usage: mkdirp [DIR1,DIR2..] {OPTIONS} Create each supplied directory including any necessary parent directories that don't yet exist. If the directory already exists, do nothing. OPTIONS are: -m, --mode If a directory needs to be created, set the mode as an octal permission string. ``` # install With [npm](http://npmjs.org) do: ``` npm install mkdirp ``` to get the library, or ``` npm install -g mkdirp ``` to get the command. # license MIT node-mkdirp-0.5.0/test/000077500000000000000000000000001233204427300147045ustar00rootroot00000000000000node-mkdirp-0.5.0/test/chmod.js000066400000000000000000000020131233204427300163300ustar00rootroot00000000000000var 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.5.0/test/clobber.js000066400000000000000000000014651233204427300166600ustar00rootroot00000000000000var 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.5.0/test/mkdirp.js000066400000000000000000000014771233204427300165410ustar00rootroot00000000000000var mkdirp = require('../'); var path = require('path'); var fs = require('fs'); var exists = fs.exists || path.exists; var test = require('tap').test; test('woo', function (t) { t.plan(5); 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) { t.ifError(err); exists(file, function (ex) { t.ok(ex, 'file created'); fs.stat(file, function (err, stat) { t.ifError(err); t.equal(stat.mode & 0777, 0755); t.ok(stat.isDirectory(), 'target not a directory'); }) }) }); }); node-mkdirp-0.5.0/test/opts_fs.js000066400000000000000000000015451233204427300167240ustar00rootroot00000000000000var mkdirp = require('../'); var path = require('path'); var test = require('tap').test; var mockfs = require('mock-fs'); test('opts.fs', function (t) { t.plan(5); 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 = '/beep/boop/' + [x,y,z].join('/'); var xfs = mockfs.fs(); mkdirp(file, { fs: xfs, mode: 0755 }, function (err) { t.ifError(err); xfs.exists(file, function (ex) { t.ok(ex, 'created file'); xfs.stat(file, function (err, stat) { t.ifError(err); t.equal(stat.mode & 0777, 0755); t.ok(stat.isDirectory(), 'target not a directory'); }); }); }); }); node-mkdirp-0.5.0/test/opts_fs_sync.js000066400000000000000000000014371233204427300177600ustar00rootroot00000000000000var mkdirp = require('../'); var path = require('path'); var test = require('tap').test; var mockfs = require('mock-fs'); test('opts.fs sync', 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 = '/beep/boop/' + [x,y,z].join('/'); var xfs = mockfs.fs(); mkdirp.sync(file, { fs: xfs, mode: 0755 }); xfs.exists(file, function (ex) { t.ok(ex, 'created file'); xfs.stat(file, function (err, stat) { t.ifError(err); t.equal(stat.mode & 0777, 0755); t.ok(stat.isDirectory(), 'target not a directory'); }); }); }); node-mkdirp-0.5.0/test/perm.js000066400000000000000000000014411233204427300162050ustar00rootroot00000000000000var mkdirp = require('../'); var path = require('path'); var fs = require('fs'); var exists = fs.exists || path.exists; var test = require('tap').test; test('async perm', function (t) { t.plan(5); var file = '/tmp/' + (Math.random() * (1<<30)).toString(16); mkdirp(file, 0755, function (err) { t.ifError(err); exists(file, function (ex) { t.ok(ex, 'file created'); fs.stat(file, function (err, stat) { t.ifError(err); t.equal(stat.mode & 0777, 0755); t.ok(stat.isDirectory(), 'target not a directory'); }) }) }); }); test('async root perm', function (t) { mkdirp('/tmp', 0755, function (err) { if (err) t.fail(err); t.end(); }); t.end(); }); node-mkdirp-0.5.0/test/perm_sync.js000066400000000000000000000016311233204427300172420ustar00rootroot00000000000000var mkdirp = require('../'); var path = require('path'); var fs = require('fs'); var exists = fs.exists || path.exists; var test = require('tap').test; test('sync perm', function (t) { t.plan(4); var file = '/tmp/' + (Math.random() * (1<<30)).toString(16) + '.json'; mkdirp.sync(file, 0755); exists(file, function (ex) { t.ok(ex, 'file created'); fs.stat(file, function (err, stat) { t.ifError(err); t.equal(stat.mode & 0777, 0755); t.ok(stat.isDirectory(), 'target not a directory'); }); }); }); test('sync root perm', function (t) { t.plan(3); var file = '/tmp'; mkdirp.sync(file, 0755); exists(file, function (ex) { t.ok(ex, 'file created'); fs.stat(file, function (err, stat) { t.ifError(err); t.ok(stat.isDirectory(), 'target not a directory'); }) }); }); node-mkdirp-0.5.0/test/race.js000066400000000000000000000020461233204427300161560ustar00rootroot00000000000000var mkdirp = require('../').mkdirp; var path = require('path'); var fs = require('fs'); var exists = fs.exists || path.exists; var test = require('tap').test; test('race', function (t) { t.plan(6); 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) { t.ifError(err); exists(file, function (ex) { t.ok(ex, 'file created'); fs.stat(file, function (err, stat) { t.ifError(err); t.equal(stat.mode & 0777, 0755); t.ok(stat.isDirectory(), 'target not a directory'); if (cb) cb(); }); }) }); } }); node-mkdirp-0.5.0/test/rel.js000066400000000000000000000016261233204427300160310ustar00rootroot00000000000000var mkdirp = require('../'); var path = require('path'); var fs = require('fs'); var exists = fs.exists || path.exists; var test = require('tap').test; test('rel', function (t) { t.plan(5); 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) { t.ifError(err); exists(file, function (ex) { t.ok(ex, 'file created'); fs.stat(file, function (err, stat) { t.ifError(err); process.chdir(cwd); t.equal(stat.mode & 0777, 0755); t.ok(stat.isDirectory(), 'target not a directory'); }) }) }); }); node-mkdirp-0.5.0/test/return.js000066400000000000000000000014721233204427300165650ustar00rootroot00000000000000var 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.5.0/test/return_sync.js000066400000000000000000000015271233204427300176220ustar00rootroot00000000000000var 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.5.0/test/root.js000066400000000000000000000007161233204427300162310ustar00rootroot00000000000000var 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.5.0/test/sync.js000066400000000000000000000015051233204427300162170ustar00rootroot00000000000000var mkdirp = require('../'); var path = require('path'); var fs = require('fs'); var exists = fs.exists || path.exists; var test = require('tap').test; test('sync', 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('/'); try { mkdirp.sync(file, 0755); } catch (err) { t.fail(err); return t.end(); } exists(file, function (ex) { t.ok(ex, 'file created'); fs.stat(file, function (err, stat) { t.ifError(err); t.equal(stat.mode & 0777, 0755); t.ok(stat.isDirectory(), 'target not a directory'); }); }); }); node-mkdirp-0.5.0/test/umask.js000066400000000000000000000015441233204427300163660ustar00rootroot00000000000000var mkdirp = require('../'); var path = require('path'); var fs = require('fs'); var exists = fs.exists || path.exists; var test = require('tap').test; test('implicit mode from umask', function (t) { t.plan(5); 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) { t.ifError(err); exists(file, function (ex) { t.ok(ex, 'file created'); fs.stat(file, function (err, stat) { t.ifError(err); t.equal(stat.mode & 0777, 0777 & (~process.umask())); t.ok(stat.isDirectory(), 'target not a directory'); }); }) }); }); node-mkdirp-0.5.0/test/umask_sync.js000066400000000000000000000015421233204427300174200ustar00rootroot00000000000000var mkdirp = require('../'); var path = require('path'); var fs = require('fs'); var exists = fs.exists || path.exists; var test = require('tap').test; test('umask sync modes', 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('/'); try { mkdirp.sync(file); } catch (err) { t.fail(err); return t.end(); } exists(file, function (ex) { t.ok(ex, 'file created'); fs.stat(file, function (err, stat) { t.ifError(err); t.equal(stat.mode & 0777, (0777 & (~process.umask()))); t.ok(stat.isDirectory(), 'target not a directory'); }); }); });