succeed when directories already exist #11

Closed
mvolkmann opened this Issue Dec 3, 2011 · 4 comments

Projects

None yet

2 participants

@mvolkmann

What do you think about adding an option to make it so if the directories already exist, it doesn't throw EEXIST?
Perhaps that's what it should without any options.

@substack
Owner

That is the present behavior. Just like mkdir -p.

@substack substack closed this Dec 5, 2011
@mvolkmann

I think there's an issue if some of the directories exist, but not the ones at the end. For example, assume that /foo exists and I ask mkdirp to create /foo/bar/baz. I think that doesn't work.

@substack
Owner

Can you write a failing test of this? There are unit tests that cover exactly that scenario, although it might be skipping some cases.

@mvolkmann

Here's a simple test, written using tap. It does work when dirPath is set to 'foo', but it doesn't when it is set to '/tmp'. I'm not sure why. I can run "mkdir /tmp/foo" from a terminal window.

var path = require('path');
var mkdirp = require('mkdirp');
var test = require('tap').test;

test('some exist', function (t) {
  //var dirPath = 'foo';
  var dirPath = '/tmp';
  var mode = '750';
  mkdirp(dirPath, mode, function (err) {
    t.notOk(err);
    t.ok(path.existsSync(dirPath));
    mkdirp('foo/bar', mode, function (err) {
      t.notOk(err);
      t.ok(path.existsSync(dirPath + 'bar'));
      t.end();
    });
    t.end();
  });
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment