Skip to content

Commit b63196c

Browse files
authored
fix: Continue upon ENOSUP chmod failures (#19)
1 parent 55e5f67 commit b63196c

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

mkdirp.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,15 @@ function mkdirp(dirpath, mode, callback) {
9393
return callback();
9494
}
9595

96-
fs.chmod(dirpath, mode, callback);
96+
fs.chmod(dirpath, mode, onChmod);
97+
}
98+
99+
function onChmod(chmodErr) {
100+
if (chmodErr && chmodErr.code !== 'ENOSUP') {
101+
return callback(chmodErr);
102+
}
103+
104+
callback();
97105
}
98106

99107
function onNonDirectory(err, dirpath, stats) {

test/mkdirp.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,40 @@ function suite() {
272272
});
273273
});
274274

275+
it('surfaces chmod errors', function (done) {
276+
sinon.stub(fs, 'chmod').callsFake(function (p, mode, cb) {
277+
cb(new Error('boom'));
278+
});
279+
280+
var mode = '777';
281+
282+
mkdirp(outputDirpath, mode, function (err) {
283+
fs.chmod.restore();
284+
285+
expect(err).toBeDefined();
286+
287+
done();
288+
});
289+
});
290+
291+
it('does not surface error ENOSUP if chmod is unsupported on the path', function (done) {
292+
sinon.stub(fs, 'chmod').callsFake(function (p, mode, cb) {
293+
var err = new Error('boom');
294+
err.code = 'ENOSUP';
295+
cb(err);
296+
});
297+
298+
var mode = '777';
299+
300+
mkdirp(outputDirpath, mode, function (err) {
301+
fs.chmod.restore();
302+
303+
expect(err).not.toBeDefined();
304+
305+
done();
306+
});
307+
});
308+
275309
it('errors with ENOTDIR if file in path', function (done) {
276310
fs.mkdir(outputDirpath, function (err) {
277311
expect(err).toBeFalsy();

0 commit comments

Comments
 (0)