From 17ee84f2073a262a65e201acedb71e0d20bf9273 Mon Sep 17 00:00:00 2001 From: isaacs Date: Mon, 16 Apr 2012 10:12:07 -0700 Subject: [PATCH] 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. --- index.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 6d81c62..e2fe516 100644 --- a/index.js +++ b/index.js @@ -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); @@ -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. @@ -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);