Skip to content

Commit e84d327

Browse files
committedJan 24, 2020
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. (Copied from 17ee84f)
1 parent 6b2632d commit e84d327

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed
 

‎lib/mkdirp-manual.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const mkdirpManual = (path, opts, made) => {
1616
if (er.code === 'ENOENT')
1717
return mkdirpManual(parent, opts)
1818
.then(made => mkdirpManual(path, opts, made))
19-
if (er.code !== 'EEXIST')
19+
if (er.code !== 'EEXIST' && er.code !== 'EROFS')
2020
throw er
2121
return opts.statAsync(path).then(st => {
2222
if (st.isDirectory())
@@ -50,7 +50,7 @@ const mkdirpManualSync = (path, opts, made) => {
5050
} catch (er) {
5151
if (er.code === 'ENOENT')
5252
return mkdirpManualSync(path, opts, mkdirpManualSync(parent, opts, made))
53-
if (er.code !== 'EEXIST')
53+
if (er.code !== 'EEXIST' && er.code !== 'EROFS')
5454
throw er
5555
try {
5656
if (!opts.statSync(path).isDirectory())

‎test/mkdirp-manual.js

+20
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,26 @@ t.test('mkdirpManual / just calls implementation', t => {
6262
t.end()
6363
})
6464

65+
t.test('read-only file system, still succeed if dir exists', t => {
66+
const dir = t.testdir({ foo: {} })
67+
const opt = {
68+
stat,
69+
statAsync,
70+
statSync,
71+
mkdir,
72+
mkdirAsync: () => Promise.reject(Object.assign(new Error('EROFS'), {
73+
code: 'EROFS',
74+
})),
75+
mkdirSync: () => {
76+
throw Object.assign(new Error('EROFS'), {
77+
code: 'EROFS',
78+
})
79+
},
80+
}
81+
t.equal(mkdirpManualSync(`${dir}/foo`, opt), undefined)
82+
return mkdirpManual(`${dir}/foo`, opt).then(made => t.equal(made, undefined))
83+
})
84+
6585
t.test('recurse and return first dir made', t => {
6686
const dir = t.testdir()
6787
const opt = {

0 commit comments

Comments
 (0)
Please sign in to comment.