fs: fix infinite loop with async recursive mkdir on Windows · nodejs/node@2400cbc (original) (raw)
`@@ -132,6 +132,24 @@ function nextdir() {
`
132
132
`}
`
133
133
`}
`
134
134
``
``
135
`+
// mkdirpSync when part of the path is a file.
`
``
136
`+
{
`
``
137
`+
const filename = path.join(tmpdir.path, nextdir(), nextdir());
`
``
138
`+
const pathname = path.join(filename, nextdir(), nextdir());
`
``
139
+
``
140
`+
fs.mkdirSync(path.dirname(filename));
`
``
141
`+
fs.writeFileSync(filename, '', 'utf8');
`
``
142
+
``
143
`+
try {
`
``
144
`+
fs.mkdirSync(pathname, { recursive: true });
`
``
145
`+
throw new Error('unreachable');
`
``
146
`+
} catch (err) {
`
``
147
`+
assert.notStrictEqual(err.message, 'unreachable');
`
``
148
`+
assert.strictEqual(err.code, 'ENOTDIR');
`
``
149
`+
assert.strictEqual(err.syscall, 'mkdir');
`
``
150
`+
}
`
``
151
`+
}
`
``
152
+
135
153
`` // mkdirp
when folder does not yet exist.
``
136
154
`{
`
137
155
`const pathname = path.join(tmpdir.path, nextdir(), nextdir());
`
`@@ -149,11 +167,25 @@ function nextdir() {
`
149
167
``
150
168
`fs.mkdirSync(path.dirname(pathname));
`
151
169
`fs.writeFileSync(pathname, '', 'utf8');
`
152
``
`-
fs.mkdir(pathname, { recursive: true }, (err) => {
`
``
170
`+
fs.mkdir(pathname, { recursive: true }, common.mustCall((err) => {
`
153
171
`assert.strictEqual(err.code, 'EEXIST');
`
154
172
`assert.strictEqual(err.syscall, 'mkdir');
`
155
173
`assert.strictEqual(fs.statSync(pathname).isDirectory(), false);
`
156
``
`-
});
`
``
174
`+
}));
`
``
175
`+
}
`
``
176
+
``
177
`` +
// mkdirp
when part of the path is a file.
``
``
178
`+
{
`
``
179
`+
const filename = path.join(tmpdir.path, nextdir(), nextdir());
`
``
180
`+
const pathname = path.join(filename, nextdir(), nextdir());
`
``
181
+
``
182
`+
fs.mkdirSync(path.dirname(filename));
`
``
183
`+
fs.writeFileSync(filename, '', 'utf8');
`
``
184
`+
fs.mkdir(pathname, { recursive: true }, common.mustCall((err) => {
`
``
185
`+
assert.strictEqual(err.code, 'ENOTDIR');
`
``
186
`+
assert.strictEqual(err.syscall, 'mkdir');
`
``
187
`+
assert.strictEqual(fs.existsSync(pathname), false);
`
``
188
`+
}));
`
157
189
`}
`
158
190
``
159
191
`// mkdirpSync dirname loop
`