Skip to content

Commit

Permalink
Handle EROFS errors
Browse files Browse the repository at this point in the history
A EROFS will be raised when trying to write a dir onto a
read-only filesystem.  However, if the dir already is there,
then it should be treated like an EEXIST (since EROFS can
be raised by trying to create a dir over a mount point,
where the mount point is not read-only, but you still can't
just clobber over it).

If the dir doesn't already exist, then the EROFS will be
accurately reported as the reason why it could not be
created.
  • Loading branch information
isaacs committed Apr 16, 2012
1 parent 7b422c7 commit 17ee84f
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function mkdirP (p, mode, f, made) {
mode = 0777 & (~process.umask());
}
if (!made) made = null;

var cb = f || function () {};
if (typeof mode === 'string') mode = parseInt(mode, 8);
p = path.resolve(p);
Expand All @@ -27,6 +27,11 @@ function mkdirP (p, mode, f, made) {
});
break;

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) {
// if the stat fails, then that's super weird.
Expand All @@ -48,7 +53,7 @@ mkdirP.sync = function sync (p, mode, made) {
mode = 0777 & (~process.umask());
}
if (!made) made = null;

if (typeof mode === 'string') mode = parseInt(mode, 8);
p = path.resolve(p);

Expand Down

0 comments on commit 17ee84f

Please sign in to comment.