[Pkg-javascript-commits] [node-mkpath] 01/03: Imported Upstream version 0.1.0

Sebastiaan Couwenberg sebastic at moszumanska.debian.org
Sun Mar 1 19:11:29 UTC 2015


This is an automated email from the git hooks/post-receive script.

sebastic pushed a commit to branch master
in repository node-mkpath.

commit 9cc3d99a3000d0fbbdab7ae4d0893c3b8c9ee925
Author: Bas Couwenberg <sebastic at xs4all.nl>
Date:   Sun Mar 1 19:32:07 2015 +0100

    Imported Upstream version 0.1.0
---
 .npmignore         |  1 +
 LICENSE            |  7 +++++++
 README.md          | 27 +++++++++++++++++++++++++
 mkpath.js          | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 package.json       | 25 +++++++++++++++++++++++
 test/chmod.js      | 42 ++++++++++++++++++++++++++++++++++++++
 test/clobber.js    | 41 +++++++++++++++++++++++++++++++++++++
 test/mkpath.js     | 32 +++++++++++++++++++++++++++++
 test/perm.js       | 36 +++++++++++++++++++++++++++++++++
 test/perm_sync.js  | 43 +++++++++++++++++++++++++++++++++++++++
 test/rel.js        | 36 +++++++++++++++++++++++++++++++++
 test/root.js       | 22 ++++++++++++++++++++
 test/sync.js       | 36 +++++++++++++++++++++++++++++++++
 test/umask.js      | 32 +++++++++++++++++++++++++++++
 test/umask_sync.js | 36 +++++++++++++++++++++++++++++++++
 15 files changed, 475 insertions(+)

diff --git a/.npmignore b/.npmignore
new file mode 100644
index 0000000..c8f50f7
--- /dev/null
+++ b/.npmignore
@@ -0,0 +1 @@
+npm-debug.log
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..45b6725
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,7 @@
+Copyright (C) 2012 Jonathan Rajavuori
+
+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.
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..1a6b51d
--- /dev/null
+++ b/README.md
@@ -0,0 +1,27 @@
+# mkpath
+
+Make all directories in a path, like `mkdir -p`.
+
+## How to use
+
+    var mkpath = require('mkpath');
+    
+    mkpath('red/green/violet', function (err) {
+        if (err) throw err;
+        console.log('Directory structure red/green/violet created');
+    });
+    
+    mkpath.sync('/tmp/blue/orange', 0700);
+
+### mkpath(path, [mode = 0777 & (~process.umask()),] [callback])
+
+Create all directories that don't exist in `path` with permissions `mode`. When finished, `callback(err)` fires with the error, if any.
+
+### mkpath.sync(path, [mode = 0777 & (~process.umask())]);
+
+Synchronous version of the same. Throws error, if any.
+
+## License
+
+This software is released under the [MIT license](http://www.opensource.org/licenses/MIT).
+
diff --git a/mkpath.js b/mkpath.js
new file mode 100644
index 0000000..aa62f04
--- /dev/null
+++ b/mkpath.js
@@ -0,0 +1,59 @@
+var fs = require('fs');
+var path = require('path');
+
+var mkpath = function mkpath(dirpath, mode, callback) {
+    dirpath = path.resolve(dirpath);
+    
+    if (typeof mode === 'function' || typeof mode === 'undefined') {
+        callback = mode;
+        mode = 0777 & (~process.umask());
+    }
+    
+    if (!callback) {
+        callback = function () {};
+    }
+    
+    fs.stat(dirpath, function (err, stats) {
+        if (err) {
+            if (err.code === 'ENOENT') {
+                mkpath(path.dirname(dirpath), mode, function (err) {
+                    if (err) {
+                        callback(err);
+                    } else {
+                        fs.mkdir(dirpath, mode, callback);
+                    }
+                });
+            } else {
+                callback(err);
+            }
+        } else if (stats.isDirectory()) {
+            callback(null);
+        } else {
+            callback(new Error(dirpath + ' exists and is not a directory'));
+        }
+    });
+};
+
+mkpath.sync = function mkpathsync(dirpath, mode) {
+    dirpath = path.resolve(dirpath);
+    
+    if (typeof mode === 'undefined') {
+        mode = 0777 & (~process.umask());
+    }
+    
+    try {
+        if (!fs.statSync(dirpath).isDirectory()) {
+            throw new Error(dirpath + ' exists and is not a directory');
+        }
+    } catch (err) {
+        if (err.code === 'ENOENT') {
+            mkpathsync(path.dirname(dirpath), mode);
+            fs.mkdirSync(dirpath, mode);
+        } else {
+            throw err;
+        }
+    }
+};
+
+module.exports = mkpath;
+
diff --git a/package.json b/package.json
new file mode 100644
index 0000000..85db3b1
--- /dev/null
+++ b/package.json
@@ -0,0 +1,25 @@
+{
+    "name": "mkpath",
+    "version": "0.1.0",
+    "author": "Jonathan Rajavuori <jrajav at gmail.com>",
+    "description": "Make all directories in a path, like mkdir -p",
+    "repository": {
+        "type": "git",
+        "url": "https://github.com/jrajav/mkpath"
+    },
+    "keywords": [
+        "mkdir",
+        "mkdirp",
+        "directory",
+        "path",
+        "tree"
+    ],
+    "main": "./mkpath",
+    "scripts": {
+        "test": "node node_modules/tap/bin/tap.js ./test"
+    },
+    "devDependencies": {
+        "tap": "~0.3"
+    },
+    "license": "MIT"
+}
diff --git a/test/chmod.js b/test/chmod.js
new file mode 100644
index 0000000..96d51bd
--- /dev/null
+++ b/test/chmod.js
@@ -0,0 +1,42 @@
+/* Tests borrowed from substack's node-mkdirp
+ * https://github.com/substack/node-mkdirp */
+
+var mkpath = require('../');
+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
+    mkpath(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
+    mkpath(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();
+        });
+    });
+});
+
diff --git a/test/clobber.js b/test/clobber.js
new file mode 100644
index 0000000..16d48ca
--- /dev/null
+++ b/test/clobber.js
@@ -0,0 +1,41 @@
+/* Tests borrowed from substack's node-mkdirp
+ * https://github.com/substack/node-mkdirp */
+
+var mkpath = require('../');
+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);
+    mkpath(file, 0755, function (err) {
+        t.ok(err);
+        t.equal(err.code, 'ENOTDIR');
+        t.end();
+    });
+});
+
diff --git a/test/mkpath.js b/test/mkpath.js
new file mode 100644
index 0000000..75cd4ec
--- /dev/null
+++ b/test/mkpath.js
@@ -0,0 +1,32 @@
+/* Tests borrowed from substack's node-mkdirp
+ * https://github.com/substack/node-mkdirp */
+
+var mkpath = require('../');
+var path = require('path');
+var fs = require('fs');
+var test = require('tap').test;
+
+test('woo', 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('/');
+    
+    mkpath(file, 0755, 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.ok(stat.isDirectory(), 'target not a directory');
+                    t.end();
+                }
+            })
+        })
+    });
+});
+
diff --git a/test/perm.js b/test/perm.js
new file mode 100644
index 0000000..bb09d20
--- /dev/null
+++ b/test/perm.js
@@ -0,0 +1,36 @@
+/* Tests borrowed from substack's node-mkdirp
+ * https://github.com/substack/node-mkdirp */
+
+var mkpath = require('../');
+var path = require('path');
+var fs = require('fs');
+var test = require('tap').test;
+
+test('async perm', function (t) {
+    t.plan(2);
+    var file = '/tmp/' + (Math.random() * (1<<30)).toString(16);
+    
+    mkpath(file, 0755, 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.ok(stat.isDirectory(), 'target not a directory');
+                    t.end();
+                }
+            })
+        })
+    });
+});
+
+test('async root perm', function (t) {
+    mkpath('/tmp', 0755, function (err) {
+        if (err) t.fail(err);
+        t.end();
+    });
+    t.end();
+});
+
diff --git a/test/perm_sync.js b/test/perm_sync.js
new file mode 100644
index 0000000..ee7f330
--- /dev/null
+++ b/test/perm_sync.js
@@ -0,0 +1,43 @@
+/* Tests borrowed from substack's node-mkdirp
+ * https://github.com/substack/node-mkdirp */
+
+var mkpath = require('../');
+var path = require('path');
+var fs = require('fs');
+var test = require('tap').test;
+
+test('sync perm', function (t) {
+    t.plan(2);
+    var file = '/tmp/' + (Math.random() * (1<<30)).toString(16) + '.json';
+    
+    mkpath.sync(file, 0755);
+    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.ok(stat.isDirectory(), 'target not a directory');
+                t.end();
+            }
+        })
+    });
+});
+
+test('sync root perm', function (t) {
+    t.plan(1);
+    
+    var file = '/tmp';
+    mkpath.sync(file, 0755);
+    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.ok(stat.isDirectory(), 'target not a directory');
+                t.end();
+            }
+        })
+    });
+});
+
diff --git a/test/rel.js b/test/rel.js
new file mode 100644
index 0000000..20ea10e
--- /dev/null
+++ b/test/rel.js
@@ -0,0 +1,36 @@
+/* Tests borrowed from substack's node-mkdirp
+ * https://github.com/substack/node-mkdirp */
+
+var mkpath = require('../');
+var path = require('path');
+var fs = require('fs');
+var test = require('tap').test;
+
+test('rel', 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 cwd = process.cwd();
+    process.chdir('/tmp');
+    
+    var file = [x,y,z].join('/');
+    
+    mkpath(file, 0755, 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 {
+                    process.chdir(cwd);
+                    t.equal(stat.mode & 0777, 0755);
+                    t.ok(stat.isDirectory(), 'target not a directory');
+                    t.end();
+                }
+            })
+        })
+    });
+});
+
diff --git a/test/root.js b/test/root.js
new file mode 100644
index 0000000..78d4a02
--- /dev/null
+++ b/test/root.js
@@ -0,0 +1,22 @@
+/* Tests borrowed from substack's node-mkdirp
+ * https://github.com/substack/node-mkdirp */
+
+var mkpath = 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('/');
+
+    mkpath(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();
+        })
+    });
+});
+
diff --git a/test/sync.js b/test/sync.js
new file mode 100644
index 0000000..20fbc47
--- /dev/null
+++ b/test/sync.js
@@ -0,0 +1,36 @@
+/* Tests borrowed from substack's node-mkdirp
+ * https://github.com/substack/node-mkdirp */
+
+var mkpath = require('../');
+var path = require('path');
+var fs = require('fs');
+var test = require('tap').test;
+
+test('sync', 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('/');
+
+    try {
+        mkpath.sync(file, 0755);
+    } catch (err) {
+        t.fail(err);
+        return t.end();
+    }
+
+    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.ok(stat.isDirectory(), 'target not a directory');
+                t.end();
+            }
+        });
+    });
+});
+
diff --git a/test/umask.js b/test/umask.js
new file mode 100644
index 0000000..d2f8a71
--- /dev/null
+++ b/test/umask.js
@@ -0,0 +1,32 @@
+/* Tests borrowed from substack's node-mkdirp
+ * https://github.com/substack/node-mkdirp */
+
+var mkpath = require('../');
+var path = require('path');
+var fs = require('fs');
+var test = require('tap').test;
+
+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);
+    var z = Math.floor(Math.random() * Math.pow(16,4)).toString(16);
+    
+    var file = '/tmp/' + [x,y,z].join('/');
+    
+    mkpath(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, 0777 & (~process.umask()));
+                    t.ok(stat.isDirectory(), 'target not a directory');
+                    t.end();
+                }
+            })
+        })
+    });
+});
+
diff --git a/test/umask_sync.js b/test/umask_sync.js
new file mode 100644
index 0000000..4b9e7ba
--- /dev/null
+++ b/test/umask_sync.js
@@ -0,0 +1,36 @@
+/* Tests borrowed from substack's node-mkdirp
+ * https://github.com/substack/node-mkdirp */
+
+var mkpath = require('../');
+var path = require('path');
+var fs = require('fs');
+var test = require('tap').test;
+
+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);
+    var z = Math.floor(Math.random() * Math.pow(16,4)).toString(16);
+
+    var file = '/tmp/' + [x,y,z].join('/');
+
+    try {
+        mkpath.sync(file);
+    } catch (err) {
+        t.fail(err);
+        return t.end();
+    }
+
+    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, (0777 & (~process.umask())));
+                t.ok(stat.isDirectory(), 'target not a directory');
+                t.end();
+            }
+        });
+    });
+});
+

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-mkpath.git



More information about the Pkg-javascript-commits mailing list