Skip to content
This repository
Browse code

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

  • Loading branch information...
commit df24e8b0b5d446d1d07016ed0c463136463bb50b 1 parent 90cf526
Charlie Robbins authored August 14, 2011
2  lib/cloudfiles/common.js
@@ -11,7 +11,7 @@ var fs = require('fs'),
11 11
     https = require('https'),
12 12
     sys = require('sys'),
13 13
     url = require('url'),
14  
-    mkdirpSync = require('mkdirp').mkdirpSync,
  14
+    mkdirpSync = require('../../vendor/mkdirp').mkdirpSync,
15 15
     request = require('request'),
16 16
     cloudfiles = require('../cloudfiles');
17 17
 
43  vendor/mkdirp.js
... ...
@@ -0,0 +1,43 @@
  1
+var path = require('path');
  2
+var fs = require('fs');
  3
+
  4
+exports.mkdirp = exports.mkdirP = function mkdirP (p, mode, f) {
  5
+    var cb = f || function () {};
  6
+    if (p.charAt(0) != '/') { cb(new Error('Relative path: ' + p)); return }
  7
+    
  8
+    var ps = path.normalize(p).split('/');
  9
+    path.exists(p, function (exists) {
  10
+        if (exists) cb(null);
  11
+        else mkdirP(ps.slice(0,-1).join('/'), mode, function (err) {
  12
+            if (err && err.code !== 'EEXIST') cb(err)
  13
+            else fs.mkdir(p, mode, function (err) {
  14
+                if (err && err.code !== 'EEXIST') cb(err)
  15
+                else cb()
  16
+            });
  17
+        });
  18
+    });
  19
+};
  20
+
  21
+exports.mkdirpSync = exports.mkdirPSync = function mkdirPSync (p, mode) {
  22
+  if (p.charAt(0) != '/') { throw new Error('Relative path: ' + p); return; }
  23
+  
  24
+  var ps = path.normalize(p).split('/'),
  25
+      exists = path.existsSync(p);
  26
+  
  27
+  function tryMkdirSync () {
  28
+      try { fs.mkdirSync(p, mode); }
  29
+      catch (ex) { if (ex.code !== 'EEXIST') throw ex; }
  30
+  }
  31
+  
  32
+  if (exists) return;
  33
+  else {
  34
+      try { 
  35
+          mkdirPSync(ps.slice(0,-1).join('/'), mode); 
  36
+          tryMkdirSync();
  37
+      }
  38
+      catch (ex) {
  39
+        console.dir(ex);
  40
+          if (ex.code !== 'EEXIST') { throw ex; }
  41
+      } 
  42
+  }
  43
+}

0 notes on commit df24e8b

Please sign in to comment.
Something went wrong with that request. Please try again.