Skip to content

Commit 0105524

Browse files
shamavladikoff
authored andcommittedMar 15, 2018
Fix race condition with file.mkdir and make it operate more similarily to mkdir -p (#1627) r=@vladikoff
1 parent 303d445 commit 0105524

File tree

2 files changed

+6
-15
lines changed

2 files changed

+6
-15
lines changed
 

‎lib/grunt/file.js

+5-15
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ var YAML = require('js-yaml');
1717
var rimraf = require('rimraf');
1818
var iconv = require('iconv-lite');
1919
var pathIsAbsolute = require('path-is-absolute');
20+
var mkdirp = require('mkdirp').sync;
2021

2122
// Windows?
2223
var win32 = process.platform === 'win32';
@@ -180,22 +181,11 @@ file.expandMapping = function(patterns, destBase, options) {
180181
// Like mkdir -p. Create a directory and any intermediary directories.
181182
file.mkdir = function(dirpath, mode) {
182183
if (grunt.option('no-write')) { return; }
183-
// Set directory mode in a strict-mode-friendly way.
184-
if (mode == null) {
185-
mode = parseInt('0777', 8) & (~process.umask());
184+
try {
185+
mkdirp(dirpath, { mode: mode });
186+
} catch (e) {
187+
throw grunt.util.error('Unable to create directory "' + dirpath + '" (Error code: ' + e.code + ').', e);
186188
}
187-
dirpath.split(pathSeparatorRe).reduce(function(parts, part) {
188-
parts += part + '/';
189-
var subpath = path.resolve(parts);
190-
if (!file.exists(subpath)) {
191-
try {
192-
fs.mkdirSync(subpath, mode);
193-
} catch (e) {
194-
throw grunt.util.error('Unable to create directory "' + subpath + '" (Error code: ' + e.code + ').', e);
195-
}
196-
}
197-
return parts;
198-
}, '');
199189
};
200190

201191
// Recurse into a directory, executing callback for each file.

‎package.json

+1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
"iconv-lite": "~0.4.13",
5151
"js-yaml": "~3.5.2",
5252
"minimatch": "~3.0.2",
53+
"mkdirp": "~0.5.1",
5354
"nopt": "~3.0.6",
5455
"path-is-absolute": "~1.0.0",
5556
"rimraf": "~2.2.8"

0 commit comments

Comments
 (0)
Please sign in to comment.