Permalink
Browse files

[dist] Vendor mkdirp until `mkdirpSync` patch is applied

  • Loading branch information...
1 parent 90cf526 commit df24e8b0b5d446d1d07016ed0c463136463bb50b @indexzero indexzero committed Aug 14, 2011
Showing with 44 additions and 1 deletion.
  1. +1 −1 lib/cloudfiles/common.js
  2. +43 −0 vendor/mkdirp.js
View
2 lib/cloudfiles/common.js
@@ -11,7 +11,7 @@ var fs = require('fs'),
https = require('https'),
sys = require('sys'),
url = require('url'),
- mkdirpSync = require('mkdirp').mkdirpSync,
+ mkdirpSync = require('../../vendor/mkdirp').mkdirpSync,
request = require('request'),
cloudfiles = require('../cloudfiles');
View
43 vendor/mkdirp.js
@@ -0,0 +1,43 @@
+var path = require('path');
+var fs = require('fs');
+
+exports.mkdirp = exports.mkdirP = function mkdirP (p, mode, f) {
+ var cb = f || function () {};
+ if (p.charAt(0) != '/') { cb(new Error('Relative path: ' + p)); return }
+
+ var ps = path.normalize(p).split('/');
+ path.exists(p, function (exists) {
+ if (exists) cb(null);
+ else mkdirP(ps.slice(0,-1).join('/'), mode, function (err) {
+ if (err && err.code !== 'EEXIST') cb(err)
+ else fs.mkdir(p, mode, function (err) {
+ if (err && err.code !== 'EEXIST') cb(err)
+ else cb()
+ });
+ });
+ });
+};
+
+exports.mkdirpSync = exports.mkdirPSync = function mkdirPSync (p, mode) {
+ if (p.charAt(0) != '/') { throw new Error('Relative path: ' + p); return; }
+
+ var ps = path.normalize(p).split('/'),
+ exists = path.existsSync(p);
+
+ function tryMkdirSync () {
+ try { fs.mkdirSync(p, mode); }
+ catch (ex) { if (ex.code !== 'EEXIST') throw ex; }
+ }
+
+ if (exists) return;
+ else {
+ try {
+ mkdirPSync(ps.slice(0,-1).join('/'), mode);
+ tryMkdirSync();
+ }
+ catch (ex) {
+ console.dir(ex);
+ if (ex.code !== 'EEXIST') { throw ex; }
+ }
+ }
+}

0 comments on commit df24e8b

Please sign in to comment.