[Pkg-javascript-commits] [node-mkdirp] 03/10: Imported Upstream version 0.5.0
Andrew Kelley
andrewrk-guest at moszumanska.debian.org
Sat Sep 13 00:40:52 UTC 2014
This is an automated email from the git hooks/post-receive script.
andrewrk-guest pushed a commit to branch master
in repository node-mkdirp.
commit 5e37e94f9d97ed458ca9c67029bf73be800890c0
Author: Andrew Kelley <superjoe30 at gmail.com>
Date: Sat Sep 13 00:14:07 2014 +0000
Imported Upstream version 0.5.0
---
.travis.yml | 3 +-
README.markdown | 61 -------------------------------
bin/cmd.js | 33 +++++++++++++++++
bin/usage.txt | 12 +++++++
index.js | 75 +++++++++++++++++++-------------------
package.json | 46 +++++++++++++-----------
readme.markdown | 100 +++++++++++++++++++++++++++++++++++++++++++++++++++
test/mkdirp.js | 20 +++++------
test/opts_fs.js | 27 ++++++++++++++
test/opts_fs_sync.js | 25 +++++++++++++
test/perm.js | 20 +++++------
test/perm_sync.js | 35 ++++++++----------
test/race.js | 23 ++++++------
test/rel.js | 22 ++++++------
test/sync.js | 18 +++++-----
test/umask.js | 22 ++++++------
test/umask_sync.js | 18 +++++-----
17 files changed, 343 insertions(+), 217 deletions(-)
diff --git a/.travis.yml b/.travis.yml
index f1d0f13..c693a93 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,4 +1,5 @@
language: node_js
node_js:
- - 0.4
- 0.6
+ - 0.8
+ - "0.10"
diff --git a/README.markdown b/README.markdown
deleted file mode 100644
index 40de04f..0000000
--- a/README.markdown
+++ /dev/null
@@ -1,61 +0,0 @@
-mkdirp
-======
-
-Like `mkdir -p`, but in node.js!
-
-[![build status](https://secure.travis-ci.org/substack/node-mkdirp.png)](http://travis-ci.org/substack/node-mkdirp)
-
-example
-=======
-
-pow.js
-------
- var mkdirp = require('mkdirp');
-
- mkdirp('/tmp/foo/bar/baz', function (err) {
- if (err) console.error(err)
- else console.log('pow!')
- });
-
-Output
- pow!
-
-And now /tmp/foo/bar/baz exists, huzzah!
-
-methods
-=======
-
-var mkdirp = require('mkdirp');
-
-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())`.
-
-`cb(err, made)` fires with the error or the first directory `made`
-that had to be created, if any.
-
-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())`.
-
-Returns the first directory that had to be created, if any.
-
-install
-=======
-
-With [npm](http://npmjs.org) do:
-
- npm install mkdirp
-
-license
-=======
-
-MIT/X11
diff --git a/bin/cmd.js b/bin/cmd.js
new file mode 100755
index 0000000..d95de15
--- /dev/null
+++ b/bin/cmd.js
@@ -0,0 +1,33 @@
+#!/usr/bin/env node
+
+var mkdirp = require('../');
+var minimist = require('minimist');
+var fs = require('fs');
+
+var argv = minimist(process.argv.slice(2), {
+ alias: { m: 'mode', h: 'help' },
+ string: [ 'mode' ]
+});
+if (argv.help) {
+ fs.createReadStream(__dirname + '/usage.txt').pipe(process.stdout);
+ return;
+}
+
+var paths = argv._.slice();
+var mode = argv.mode ? parseInt(argv.mode, 8) : undefined;
+
+(function next () {
+ if (paths.length === 0) return;
+ var p = paths.shift();
+
+ if (mode === undefined) mkdirp(p, cb)
+ else mkdirp(p, mode, cb)
+
+ function cb (err) {
+ if (err) {
+ console.error(err.message);
+ process.exit(1);
+ }
+ else next();
+ }
+})();
diff --git a/bin/usage.txt b/bin/usage.txt
new file mode 100644
index 0000000..f952aa2
--- /dev/null
+++ b/bin/usage.txt
@@ -0,0 +1,12 @@
+usage: mkdirp [DIR1,DIR2..] {OPTIONS}
+
+ Create each supplied directory including any necessary parent directories that
+ don't yet exist.
+
+ If the directory already exists, do nothing.
+
+OPTIONS are:
+
+ -m, --mode If a directory needs to be created, set the mode as an octal
+ permission string.
+
diff --git a/index.js b/index.js
index 874b310..a1742b2 100644
--- a/index.js
+++ b/index.js
@@ -3,90 +3,93 @@ var fs = require('fs');
module.exports = mkdirP.mkdirp = mkdirP.mkdirP = mkdirP;
-function mkdirP (p, mode, f, made) {
- if (typeof mode === 'function' || mode === undefined) {
- f = mode;
+function mkdirP (p, opts, f, made) {
+ if (typeof opts === 'function') {
+ f = opts;
+ opts = {};
+ }
+ else if (!opts || typeof opts !== 'object') {
+ opts = { mode: opts };
+ }
+
+ var mode = opts.mode;
+ var xfs = opts.fs || fs;
+
+ if (mode === undefined) {
mode = 0777 & (~process.umask());
}
if (!made) made = null;
-
+
var cb = f || function () {};
- if (typeof mode === 'string') mode = parseInt(mode, 8);
p = path.resolve(p);
-
- fs.mkdir(p, mode, function (er) {
+
+ xfs.mkdir(p, mode, function (er) {
if (!er) {
made = made || p;
return cb(null, made);
}
switch (er.code) {
case 'ENOENT':
- mkdirP(path.dirname(p), mode, function (er, made) {
+ mkdirP(path.dirname(p), opts, function (er, made) {
if (er) cb(er, made);
- else mkdirP(p, mode, cb, made);
+ else mkdirP(p, opts, cb, made);
});
break;
- case 'EISDIR':
- case 'EPERM':
- // Operation not permitted or already is a dir.
- // This is the error you get when trying to mkdir('c:/')
- // on windows, or mkdir('/') on unix. Make sure it's a
- // dir by falling through to the EEXIST case.
- case 'EROFS':
- // a read-only file system.
- // However, the dir could already exist, in which case
- // the EROFS error will be obscuring a EEXIST!
- // Fallthrough to that case.
- case 'EEXIST':
- fs.stat(p, function (er2, stat) {
+ // In the case of any other error, just see if there's a dir
+ // there already. If so, then hooray! If not, then something
+ // is borked.
+ default:
+ xfs.stat(p, function (er2, stat) {
// if the stat fails, then that's super weird.
// let the original error be the failure reason.
if (er2 || !stat.isDirectory()) cb(er, made)
else cb(null, made);
});
break;
-
- default:
- cb(er, made);
- break;
}
});
}
-mkdirP.sync = function sync (p, mode, made) {
+mkdirP.sync = function sync (p, opts, made) {
+ if (!opts || typeof opts !== 'object') {
+ opts = { mode: opts };
+ }
+
+ var mode = opts.mode;
+ var xfs = opts.fs || fs;
+
if (mode === undefined) {
mode = 0777 & (~process.umask());
}
if (!made) made = null;
- if (typeof mode === 'string') mode = parseInt(mode, 8);
p = path.resolve(p);
try {
- fs.mkdirSync(p, mode);
+ xfs.mkdirSync(p, mode);
made = made || p;
}
catch (err0) {
switch (err0.code) {
case 'ENOENT' :
- made = sync(path.dirname(p), mode, made);
- sync(p, mode, made);
+ made = sync(path.dirname(p), opts, made);
+ sync(p, opts, made);
break;
- case 'EEXIST' :
+ // In the case of any other error, just see if there's a dir
+ // there already. If so, then hooray! If not, then something
+ // is borked.
+ default:
var stat;
try {
- stat = fs.statSync(p);
+ stat = xfs.statSync(p);
}
catch (err1) {
throw err0;
}
if (!stat.isDirectory()) throw err0;
break;
- default :
- throw err0
- break;
}
}
diff --git a/package.json b/package.json
index d7f132d..e637980 100644
--- a/package.json
+++ b/package.json
@@ -1,23 +1,27 @@
{
- "name" : "mkdirp",
- "description" : "Recursively mkdir, like `mkdir -p`",
- "version" : "0.3.3",
- "author" : "James Halliday <mail at substack.net> (http://substack.net)",
- "main" : "./index",
- "keywords" : [
- "mkdir",
- "directory"
- ],
- "repository" : {
- "type" : "git",
- "url" : "http://github.com/substack/node-mkdirp.git"
- },
- "scripts" : {
- "test" : "tap test/*.js"
- },
- "devDependencies" : {
- "tap" : "~0.2.4"
- },
- "license" : "MIT/X11",
- "engines": { "node": "*" }
+ "name": "mkdirp",
+ "description": "Recursively mkdir, like `mkdir -p`",
+ "version": "0.5.0",
+ "author": "James Halliday <mail at substack.net> (http://substack.net)",
+ "main": "./index",
+ "keywords": [
+ "mkdir",
+ "directory"
+ ],
+ "repository": {
+ "type": "git",
+ "url": "https://github.com/substack/node-mkdirp.git"
+ },
+ "scripts": {
+ "test": "tap test/*.js"
+ },
+ "dependencies": {
+ "minimist": "0.0.8"
+ },
+ "devDependencies": {
+ "tap": "~0.4.0",
+ "mock-fs": "~2.2.0"
+ },
+ "bin": "bin/cmd.js",
+ "license": "MIT"
}
diff --git a/readme.markdown b/readme.markdown
new file mode 100644
index 0000000..3cc1315
--- /dev/null
+++ b/readme.markdown
@@ -0,0 +1,100 @@
+# mkdirp
+
+Like `mkdir -p`, but in node.js!
+
+[![build status](https://secure.travis-ci.org/substack/node-mkdirp.png)](http://travis-ci.org/substack/node-mkdirp)
+
+# example
+
+## pow.js
+
+```js
+var mkdirp = require('mkdirp');
+
+mkdirp('/tmp/foo/bar/baz', function (err) {
+ if (err) console.error(err)
+ else console.log('pow!')
+});
+```
+
+Output
+
+```
+pow!
+```
+
+And now /tmp/foo/bar/baz exists, huzzah!
+
+# methods
+
+```js
+var mkdirp = require('mkdirp');
+```
+
+## mkdirp(dir, opts, cb)
+
+Create a new directory and any necessary subdirectories at `dir` with octal
+permission string `opts.mode`. If `opts` is a non-object, it will be treated as
+the `opts.mode`.
+
+If `opts.mode` isn't specified, it defaults to `0777 & (~process.umask())`.
+
+`cb(err, made)` fires with the error or the first directory `made`
+that had to be created, if any.
+
+You can optionally pass in an alternate `fs` implementation by passing in
+`opts.fs`. Your implementation should have `opts.fs.mkdir(path, mode, cb)` and
+`opts.fs.stat(path, cb)`.
+
+## mkdirp.sync(dir, opts)
+
+Synchronously create a new directory and any necessary subdirectories at `dir`
+with octal permission string `opts.mode`. If `opts` is a non-object, it will be
+treated as the `opts.mode`.
+
+If `opts.mode` isn't specified, it defaults to `0777 & (~process.umask())`.
+
+Returns the first directory that had to be created, if any.
+
+You can optionally pass in an alternate `fs` implementation by passing in
+`opts.fs`. Your implementation should have `opts.fs.mkdirSync(path, mode)` and
+`opts.fs.statSync(path)`.
+
+# usage
+
+This package also ships with a `mkdirp` command.
+
+```
+usage: mkdirp [DIR1,DIR2..] {OPTIONS}
+
+ Create each supplied directory including any necessary parent directories that
+ don't yet exist.
+
+ If the directory already exists, do nothing.
+
+OPTIONS are:
+
+ -m, --mode If a directory needs to be created, set the mode as an octal
+ permission string.
+
+```
+
+# install
+
+With [npm](http://npmjs.org) do:
+
+```
+npm install mkdirp
+```
+
+to get the library, or
+
+```
+npm install -g mkdirp
+```
+
+to get the command.
+
+# license
+
+MIT
diff --git a/test/mkdirp.js b/test/mkdirp.js
index b07cd70..3b624dd 100644
--- a/test/mkdirp.js
+++ b/test/mkdirp.js
@@ -1,10 +1,11 @@
var mkdirp = require('../');
var path = require('path');
var fs = require('fs');
+var exists = fs.exists || path.exists;
var test = require('tap').test;
test('woo', function (t) {
- t.plan(2);
+ t.plan(5);
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);
@@ -12,16 +13,13 @@ test('woo', function (t) {
var file = '/tmp/' + [x,y,z].join('/');
mkdirp(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();
- }
+ t.ifError(err);
+ exists(file, function (ex) {
+ t.ok(ex, 'file created');
+ fs.stat(file, function (err, stat) {
+ t.ifError(err);
+ t.equal(stat.mode & 0777, 0755);
+ t.ok(stat.isDirectory(), 'target not a directory');
})
})
});
diff --git a/test/opts_fs.js b/test/opts_fs.js
new file mode 100644
index 0000000..f1fbeca
--- /dev/null
+++ b/test/opts_fs.js
@@ -0,0 +1,27 @@
+var mkdirp = require('../');
+var path = require('path');
+var test = require('tap').test;
+var mockfs = require('mock-fs');
+
+test('opts.fs', function (t) {
+ t.plan(5);
+
+ 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 = '/beep/boop/' + [x,y,z].join('/');
+ var xfs = mockfs.fs();
+
+ mkdirp(file, { fs: xfs, mode: 0755 }, function (err) {
+ t.ifError(err);
+ xfs.exists(file, function (ex) {
+ t.ok(ex, 'created file');
+ xfs.stat(file, function (err, stat) {
+ t.ifError(err);
+ t.equal(stat.mode & 0777, 0755);
+ t.ok(stat.isDirectory(), 'target not a directory');
+ });
+ });
+ });
+});
diff --git a/test/opts_fs_sync.js b/test/opts_fs_sync.js
new file mode 100644
index 0000000..224b506
--- /dev/null
+++ b/test/opts_fs_sync.js
@@ -0,0 +1,25 @@
+var mkdirp = require('../');
+var path = require('path');
+var test = require('tap').test;
+var mockfs = require('mock-fs');
+
+test('opts.fs sync', function (t) {
+ t.plan(4);
+
+ 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 = '/beep/boop/' + [x,y,z].join('/');
+ var xfs = mockfs.fs();
+
+ mkdirp.sync(file, { fs: xfs, mode: 0755 });
+ xfs.exists(file, function (ex) {
+ t.ok(ex, 'created file');
+ xfs.stat(file, function (err, stat) {
+ t.ifError(err);
+ t.equal(stat.mode & 0777, 0755);
+ t.ok(stat.isDirectory(), 'target not a directory');
+ });
+ });
+});
diff --git a/test/perm.js b/test/perm.js
index 23a7abb..2c97590 100644
--- a/test/perm.js
+++ b/test/perm.js
@@ -1,23 +1,21 @@
var mkdirp = require('../');
var path = require('path');
var fs = require('fs');
+var exists = fs.exists || path.exists;
var test = require('tap').test;
test('async perm', function (t) {
- t.plan(2);
+ t.plan(5);
var file = '/tmp/' + (Math.random() * (1<<30)).toString(16);
mkdirp(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();
- }
+ t.ifError(err);
+ exists(file, function (ex) {
+ t.ok(ex, 'file created');
+ fs.stat(file, function (err, stat) {
+ t.ifError(err);
+ t.equal(stat.mode & 0777, 0755);
+ t.ok(stat.isDirectory(), 'target not a directory');
})
})
});
diff --git a/test/perm_sync.js b/test/perm_sync.js
index f685f60..327e54b 100644
--- a/test/perm_sync.js
+++ b/test/perm_sync.js
@@ -1,39 +1,34 @@
var mkdirp = require('../');
var path = require('path');
var fs = require('fs');
+var exists = fs.exists || path.exists;
var test = require('tap').test;
test('sync perm', function (t) {
- t.plan(2);
+ t.plan(4);
var file = '/tmp/' + (Math.random() * (1<<30)).toString(16) + '.json';
mkdirp.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();
- }
- })
+ exists(file, function (ex) {
+ t.ok(ex, 'file created');
+ fs.stat(file, function (err, stat) {
+ t.ifError(err);
+ t.equal(stat.mode & 0777, 0755);
+ t.ok(stat.isDirectory(), 'target not a directory');
+ });
});
});
test('sync root perm', function (t) {
- t.plan(1);
+ t.plan(3);
var file = '/tmp';
mkdirp.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();
- }
+ exists(file, function (ex) {
+ t.ok(ex, 'file created');
+ fs.stat(file, function (err, stat) {
+ t.ifError(err);
+ t.ok(stat.isDirectory(), 'target not a directory');
})
});
});
diff --git a/test/race.js b/test/race.js
index 96a0447..7c295f4 100644
--- a/test/race.js
+++ b/test/race.js
@@ -1,10 +1,11 @@
var mkdirp = require('../').mkdirp;
var path = require('path');
var fs = require('fs');
+var exists = fs.exists || path.exists;
var test = require('tap').test;
test('race', function (t) {
- t.plan(4);
+ t.plan(6);
var ps = [ '', 'tmp' ];
for (var i = 0; i < 25; i++) {
@@ -24,17 +25,15 @@ test('race', function (t) {
function mk (file, cb) {
mkdirp(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');
- if (cb) cb();
- }
- })
+ t.ifError(err);
+ exists(file, function (ex) {
+ t.ok(ex, 'file created');
+ fs.stat(file, function (err, stat) {
+ t.ifError(err);
+ t.equal(stat.mode & 0777, 0755);
+ t.ok(stat.isDirectory(), 'target not a directory');
+ if (cb) cb();
+ });
})
});
}
diff --git a/test/rel.js b/test/rel.js
index 7985824..d1f175c 100644
--- a/test/rel.js
+++ b/test/rel.js
@@ -1,10 +1,11 @@
var mkdirp = require('../');
var path = require('path');
var fs = require('fs');
+var exists = fs.exists || path.exists;
var test = require('tap').test;
test('rel', function (t) {
- t.plan(2);
+ t.plan(5);
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);
@@ -15,17 +16,14 @@ test('rel', function (t) {
var file = [x,y,z].join('/');
mkdirp(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();
- }
+ t.ifError(err);
+ exists(file, function (ex) {
+ t.ok(ex, 'file created');
+ fs.stat(file, function (err, stat) {
+ t.ifError(err);
+ process.chdir(cwd);
+ t.equal(stat.mode & 0777, 0755);
+ t.ok(stat.isDirectory(), 'target not a directory');
})
})
});
diff --git a/test/sync.js b/test/sync.js
index 7530cad..88fa432 100644
--- a/test/sync.js
+++ b/test/sync.js
@@ -1,10 +1,11 @@
var mkdirp = require('../');
var path = require('path');
var fs = require('fs');
+var exists = fs.exists || path.exists;
var test = require('tap').test;
test('sync', function (t) {
- t.plan(2);
+ t.plan(4);
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);
@@ -18,15 +19,12 @@ test('sync', function (t) {
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();
- }
+ exists(file, function (ex) {
+ t.ok(ex, 'file created');
+ fs.stat(file, function (err, stat) {
+ t.ifError(err);
+ t.equal(stat.mode & 0777, 0755);
+ t.ok(stat.isDirectory(), 'target not a directory');
});
});
});
diff --git a/test/umask.js b/test/umask.js
index 64ccafe..82c393a 100644
--- a/test/umask.js
+++ b/test/umask.js
@@ -1,10 +1,11 @@
var mkdirp = require('../');
var path = require('path');
var fs = require('fs');
+var exists = fs.exists || path.exists;
var test = require('tap').test;
test('implicit mode from umask', function (t) {
- t.plan(2);
+ t.plan(5);
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);
@@ -12,17 +13,14 @@ test('implicit mode from umask', function (t) {
var file = '/tmp/' + [x,y,z].join('/');
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, 0777 & (~process.umask()));
- t.ok(stat.isDirectory(), 'target not a directory');
- t.end();
- }
- })
+ t.ifError(err);
+ exists(file, function (ex) {
+ t.ok(ex, 'file created');
+ fs.stat(file, function (err, stat) {
+ t.ifError(err);
+ t.equal(stat.mode & 0777, 0777 & (~process.umask()));
+ t.ok(stat.isDirectory(), 'target not a directory');
+ });
})
});
});
diff --git a/test/umask_sync.js b/test/umask_sync.js
index 35bd5cb..e537fbe 100644
--- a/test/umask_sync.js
+++ b/test/umask_sync.js
@@ -1,10 +1,11 @@
var mkdirp = require('../');
var path = require('path');
var fs = require('fs');
+var exists = fs.exists || path.exists;
var test = require('tap').test;
test('umask sync modes', function (t) {
- t.plan(2);
+ t.plan(4);
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);
@@ -18,15 +19,12 @@ test('umask sync modes', function (t) {
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();
- }
+ exists(file, function (ex) {
+ t.ok(ex, 'file created');
+ fs.stat(file, function (err, stat) {
+ t.ifError(err);
+ t.equal(stat.mode & 0777, (0777 & (~process.umask())));
+ t.ok(stat.isDirectory(), 'target not a directory');
});
});
});
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/collab-maint/node-mkdirp.git
More information about the Pkg-javascript-commits
mailing list