[Pkg-javascript-commits] [SCM] NodeJS library to recursively create directories branch, master, updated. debian/0.2.1-1-3-g8a7ac74

Jérémy Lal kapouer at melix.org
Thu Mar 8 15:29:05 UTC 2012


The following commit has been merged in the master branch:
commit b13ae0947634cee7340318bba2318cd4986f56c9
Author: Jérémy Lal <kapouer at melix.org>
Date:   Thu Mar 8 16:19:07 2012 +0100

    Imported Upstream version 0.3.0

diff --git a/README.markdown b/README.markdown
index c7cec72..b4dd75f 100644
--- a/README.markdown
+++ b/README.markdown
@@ -10,7 +10,7 @@ pow.js
 ------
     var mkdirp = require('mkdirp');
     
-    mkdirp('/tmp/foo/bar/baz', 0755, function (err) {
+    mkdirp('/tmp/foo/bar/baz', function (err) {
         if (err) console.error(err)
         else console.log('pow!')
     });
@@ -31,12 +31,16 @@ 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())`.
+
 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())`.
+
 install
 =======
 
diff --git a/examples/pow.js b/examples/pow.js
index 7741462..e692421 100644
--- a/examples/pow.js
+++ b/examples/pow.js
@@ -1,6 +1,6 @@
 var mkdirp = require('mkdirp');
 
-mkdirp('/tmp/foo/bar/baz', 0755, function (err) {
+mkdirp('/tmp/foo/bar/baz', function (err) {
     if (err) console.error(err)
     else console.log('pow!')
 });
diff --git a/index.js b/index.js
index f6e4f2b..25f43ad 100644
--- a/index.js
+++ b/index.js
@@ -4,7 +4,10 @@ var fs = require('fs');
 module.exports = mkdirP.mkdirp = mkdirP.mkdirP = mkdirP;
 
 function mkdirP (p, mode, f) {
-    if (mode === undefined) throw new Error('mode not specified');
+    if (typeof mode === 'function' || mode === undefined) {
+        f = mode;
+        mode = 0777 & (~process.umask());
+    }
     
     var cb = f || function () {};
     if (typeof mode === 'string') mode = parseInt(mode, 8);
@@ -25,7 +28,6 @@ function mkdirP (p, mode, f) {
                     // if the stat fails, then that's super weird.
                     // let the original EEXIST be the failure reason.
                     if (er2 || !stat.isDirectory()) cb(er)
-                    else if ((stat.mode & 0777) !== mode) fs.chmod(p, mode, cb);
                     else cb();
                 });
                 break;
@@ -38,7 +40,9 @@ function mkdirP (p, mode, f) {
 }
 
 mkdirP.sync = function sync (p, mode) {
-    if (mode === undefined) throw new Error('mode not specified');
+    if (mode === undefined) {
+        mode = 0777 & (~process.umask());
+    }
     
     if (typeof mode === 'string') mode = parseInt(mode, 8);
     p = path.resolve(p);
@@ -63,16 +67,6 @@ mkdirP.sync = function sync (p, mode) {
                     throw err0
                 }
                 if (!stat.isDirectory()) throw err0;
-                else if ((stat.mode & 0777) !== mode) {
-                    try {
-                        fs.chmodSync(p, mode);
-                    }
-                    catch (err) {
-                        if (err && err.code === 'EPERM') return null;
-                        else throw err;
-                    }
-                    return null;
-                }
                 else return null;
                 break;
             default :
diff --git a/package.json b/package.json
index a783046..1bf9ac7 100644
--- a/package.json
+++ b/package.json
@@ -1,7 +1,7 @@
 {
     "name" : "mkdirp",
     "description" : "Recursively mkdir, like `mkdir -p`",
-    "version" : "0.2.1",
+    "version" : "0.3.0",
     "author" : "James Halliday <mail at substack.net> (http://substack.net)",
     "main" : "./index",
     "keywords" : [
diff --git a/test/chmod.js b/test/chmod.js
index 0609694..520dcb8 100644
--- a/test/chmod.js
+++ b/test/chmod.js
@@ -32,7 +32,6 @@ test('chmod', function (t) {
         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 0755');
             t.end();
         });
     });
diff --git a/test/mkdirp.js b/test/umask.js
similarity index 83%
copy from test/mkdirp.js
copy to test/umask.js
index b07cd70..64ccafe 100644
--- a/test/mkdirp.js
+++ b/test/umask.js
@@ -3,7 +3,7 @@ var path = require('path');
 var fs = require('fs');
 var test = require('tap').test;
 
-test('woo', function (t) {
+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);
@@ -11,14 +11,14 @@ test('woo', function (t) {
     
     var file = '/tmp/' + [x,y,z].join('/');
     
-    mkdirp(file, 0755, function (err) {
+    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, 0755);
+                    t.equal(stat.mode & 0777, 0777 & (~process.umask()));
                     t.ok(stat.isDirectory(), 'target not a directory');
                     t.end();
                 }
diff --git a/test/sync.js b/test/umask_sync.js
similarity index 83%
copy from test/sync.js
copy to test/umask_sync.js
index e0e389d..83cba56 100644
--- a/test/sync.js
+++ b/test/umask_sync.js
@@ -3,7 +3,7 @@ var path = require('path');
 var fs = require('fs');
 var test = require('tap').test;
 
-test('sync', function (t) {
+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);
@@ -11,14 +11,14 @@ test('sync', function (t) {
     
     var file = '/tmp/' + [x,y,z].join('/');
     
-    var err = mkdirp.sync(file, 0755);
+    var err = mkdirp.sync(file);
     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.equal(stat.mode & 0777, (0777 & (~process.umask())));
                 t.ok(stat.isDirectory(), 'target not a directory');
                 t.end();
             }

-- 
NodeJS library to recursively create directories



More information about the Pkg-javascript-commits mailing list