clobber on ENOTDIR, chmod if already exists #10

wants to merge 5 commits into


None yet

2 participants

isaacs commented Nov 6, 2011

So, this is basically a rewrite of the whole "thing that does stuff" part of mkdirp. I usually find that to be a bit presumptuous, but the fact is that mkdirp was tight enough that it was hard to make any significant change without completely altering it.

Tests added, as well.

isaacs added some commits Nov 6, 2011
@isaacs isaacs A test of clobbering a non-dir in the way 87bd635
@isaacs isaacs A test of setting the mode on an existing dir 3caa8c6
@isaacs isaacs Efficienter test command fe0a533
@isaacs isaacs Fix #8, fix #9, and fewer stat calls
The new algorithm is:

1. Try to make the dir.  If that works, then great.
2. If there's an ENOENT or ENOTDIR, then mkdirP the parent.
  1. If that fails, then fail.  Otherwise, try again.
3. If there's an EEXIST, then stat the thing
  1. if it's not a dir, delete it, and try again.
  2. if the mode is wrong, chmod it.
  3. otherwise, all is good, so just cb()
4. Some other error, fail with it.
@isaacs isaacs Remove clobber 5d3f607
@substack substack closed this Nov 6, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment