Browse files

Remove clobber

  • Loading branch information...
1 parent c4bdf27 commit 5d3f607463df1a2b18205482694810562327f140 @isaacs isaacs committed Nov 6, 2011
Showing with 1 addition and 56 deletions.
  1. +1 −6 index.js
  2. +0 −50 test/clobber.js
View
7 index.js
@@ -11,7 +11,6 @@ function mkdirP (p, mode, f) {
fs.mkdir(p, mode, function (er) {
if (!er) return cb();
switch (er.code) {
- case 'ENOTDIR':
case 'ENOENT':
mkdirP(path.dirname(p), mode, function (er) {
if (er) cb(er);
@@ -23,11 +22,7 @@ function mkdirP (p, mode, f) {
fs.stat(p, function (er2, stat) {
// if the stat fails, then that's super weird.
// let the original EEXIST be the failure reason.
- if (er2) cb(er);
- else if (!stat.isDirectory()) fs.unlink(p, function (er) {
- if (er) cb(er);
- else mkdirP(p, mode, cb);
- });
+ if (er2 || !stat.isDirectory()) cb(er);
else if ((stat.mode & 0777) !== mode) fs.chmod(p, mode, cb);
else cb();
});
View
50 test/clobber.js
@@ -1,50 +0,0 @@
-var mkdirp = require('../').mkdirp;
-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) {
- mkdirp(file, 0755, function (err) {
- console.error("mkdir result", file, err)
- if (err) t.fail(err);
- else fs.stat(file, function (ex, stat) {
- if (ex) t.fail('file not created')
- else {
- t.equal(stat.mode & 0777, 0755);
- t.ok(stat.isDirectory(), 'target not a directory');
- fs.stat(itw, function (er, stat) {
- if (er) t.fail('in the way file not there?!?')
- else {
- t.equal(stat.mode & 0777, 0755)
- t.ok(stat.isDirectory(), 'should be directory');
- t.end();
- }
- });
- }
- });
- });
-});

0 comments on commit 5d3f607

Please sign in to comment.