]>
git.r.bdr.sh - rbdr/dotfiles/blob - atom/packages/ex-mode/node_modules/fs-plus/node_modules/mkdirp/index.js
fda6de8a2c2313676c3f28a0b4cd77a1bbfdff28
1 var path
= require('path');
2 var fs
= require('fs');
4 module
.exports
= mkdirP
.mkdirp
= mkdirP
.mkdirP
= mkdirP
;
6 function mkdirP (p
, mode
, f
, made
) {
7 if (typeof mode
=== 'function' || mode
=== undefined) {
9 mode
= 0777 & (~process
.umask());
11 if (!made
) made
= null;
13 var cb
= f
|| function () {};
14 if (typeof mode
=== 'string') mode
= parseInt(mode
, 8);
17 fs
.mkdir(p
, mode
, function (er
) {
20 return cb(null, made
);
24 mkdirP(path
.dirname(p
), mode
, function (er
, made
) {
26 else mkdirP(p
, mode
, cb
, made
);
30 // In the case of any other error, just see if there's a dir
31 // there already. If so, then hooray! If not, then something
34 fs
.stat(p
, function (er2
, stat
) {
35 // if the stat fails, then that's super weird.
36 // let the original error be the failure reason.
37 if (er2
|| !stat
.isDirectory()) cb(er
, made
)
45 mkdirP
.sync
= function sync (p
, mode
, made
) {
46 if (mode
=== undefined) {
47 mode
= 0777 & (~process
.umask());
49 if (!made
) made
= null;
51 if (typeof mode
=== 'string') mode
= parseInt(mode
, 8);
55 fs
.mkdirSync(p
, mode
);
61 made
= sync(path
.dirname(p
), mode
, made
);
65 // In the case of any other error, just see if there's a dir
66 // there already. If so, then hooray! If not, then something
71 stat
= fs
.statSync(p
);
76 if (!stat
.isDirectory()) throw err0
;