Skip to content

Commit 17ee84f

Browse files
committed
Handle EROFS errors
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.
1 parent 7b422c7 commit 17ee84f

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

index.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ function mkdirP (p, mode, f, made) {
99
mode = 0777 & (~process.umask());
1010
}
1111
if (!made) made = null;
12-
12+
1313
var cb = f || function () {};
1414
if (typeof mode === 'string') mode = parseInt(mode, 8);
1515
p = path.resolve(p);
@@ -27,6 +27,11 @@ function mkdirP (p, mode, f, made) {
2727
});
2828
break;
2929

30+
case 'EROFS':
31+
// a read-only file system.
32+
// However, the dir could already exist, in which case
33+
// the EROFS error will be obscuring a EEXIST!
34+
// Fallthrough to that case.
3035
case 'EEXIST':
3136
fs.stat(p, function (er2, stat) {
3237
// if the stat fails, then that's super weird.
@@ -48,7 +53,7 @@ mkdirP.sync = function sync (p, mode, made) {
4853
mode = 0777 & (~process.umask());
4954
}
5055
if (!made) made = null;
51-
56+
5257
if (typeof mode === 'string') mode = parseInt(mode, 8);
5358
p = path.resolve(p);
5459

0 commit comments

Comments
 (0)