diff --git a/lib/mkdirp-manual.js b/lib/mkdirp-manual.js index 703b3f5..2eb18cd 100644 --- a/lib/mkdirp-manual.js +++ b/lib/mkdirp-manual.js @@ -16,7 +16,7 @@ const mkdirpManual = (path, opts, made) => { if (er.code === 'ENOENT') return mkdirpManual(parent, opts) .then(made => mkdirpManual(path, opts, made)) - if (er.code !== 'EEXIST') + if (er.code !== 'EEXIST' && er.code !== 'EROFS') throw er return opts.statAsync(path).then(st => { if (st.isDirectory()) @@ -50,7 +50,7 @@ const mkdirpManualSync = (path, opts, made) => { } catch (er) { if (er.code === 'ENOENT') return mkdirpManualSync(path, opts, mkdirpManualSync(parent, opts, made)) - if (er.code !== 'EEXIST') + if (er.code !== 'EEXIST' && er.code !== 'EROFS') throw er try { if (!opts.statSync(path).isDirectory()) diff --git a/test/mkdirp-manual.js b/test/mkdirp-manual.js index c252e21..b19c8d7 100644 --- a/test/mkdirp-manual.js +++ b/test/mkdirp-manual.js @@ -62,6 +62,26 @@ t.test('mkdirpManual / just calls implementation', t => { t.end() }) +t.test('read-only file system, still succeed if dir exists', t => { + const dir = t.testdir({ foo: {} }) + const opt = { + stat, + statAsync, + statSync, + mkdir, + mkdirAsync: () => Promise.reject(Object.assign(new Error('EROFS'), { + code: 'EROFS', + })), + mkdirSync: () => { + throw Object.assign(new Error('EROFS'), { + code: 'EROFS', + }) + }, + } + t.equal(mkdirpManualSync(`${dir}/foo`, opt), undefined) + return mkdirpManual(`${dir}/foo`, opt).then(made => t.equal(made, undefined)) +}) + t.test('recurse and return first dir made', t => { const dir = t.testdir() const opt = {