Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Handle EPERM/EISDIR for mkdir('/') to work properly #19

Merged
merged 1 commit into from

2 participants

@isaacs

No description provided.

@substack substack merged commit af68ea7 into substack:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jun 4, 2012
  1. @isaacs
This page is out of date. Refresh to see the latest.
Showing with 25 additions and 1 deletion.
  1. +7 −1 index.js
  2. +18 −0 test/root.js
View
8 index.js
@@ -27,6 +27,12 @@ function mkdirP (p, mode, f, 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
@@ -35,7 +41,7 @@ function mkdirP (p, mode, f, made) {
case 'EEXIST':
fs.stat(p, function (er2, stat) {
// if the stat fails, then that's super weird.
- // let the original EEXIST be the failure reason.
+ // let the original error be the failure reason.
if (er2 || !stat.isDirectory()) cb(er, made)
else cb(null, made);
});
View
18 test/root.js
@@ -0,0 +1,18 @@
+var mkdirp = 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('/');
+
+ mkdirp(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();
+ })
+ });
+});
Something went wrong with that request. Please try again.