Skip to content

Commit cc4a6ed

Browse files
cjihrigtargos
authored andcommitted
test: use fs rimraf to refresh tmpdir
Now that the functionality is built into core, use it to refresh the test suite's tmpdir. PR-URL: #30569 Reviewed-By: Jiawen Geng <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Ben Coe <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
1 parent 18758ef commit cc4a6ed

File tree

1 file changed

+1
-49
lines changed

1 file changed

+1
-49
lines changed

test/common/tmpdir.js

+1-49
Original file line numberDiff line numberDiff line change
@@ -36,60 +36,12 @@ function rimrafSync(pathname, { spawn = true } = {}) {
3636
}
3737
}
3838

39-
try {
40-
if (st.isDirectory())
41-
rmdirSync(pathname, null);
42-
else
43-
fs.unlinkSync(pathname);
44-
} catch (e) {
45-
debug(e);
46-
switch (e.code) {
47-
case 'ENOENT':
48-
// It's not there anymore. Work is done. Exiting.
49-
return;
50-
51-
case 'EPERM':
52-
// This can happen, try again with `rmdirSync`.
53-
break;
54-
55-
case 'EISDIR':
56-
// Got 'EISDIR' even after testing `st.isDirectory()`...
57-
// Try again with `rmdirSync`.
58-
break;
59-
60-
default:
61-
throw e;
62-
}
63-
rmdirSync(pathname, e);
64-
}
39+
fs.rmdirSync(pathname, { recursive: true, maxRetries: 5 });
6540

6641
if (fs.existsSync(pathname))
6742
throw new Error(`Unable to rimraf ${pathname}`);
6843
}
6944

70-
function rmdirSync(p, originalEr) {
71-
try {
72-
fs.rmdirSync(p);
73-
} catch (e) {
74-
if (e.code === 'ENOTDIR')
75-
throw originalEr;
76-
if (e.code === 'ENOTEMPTY' || e.code === 'EEXIST' || e.code === 'EPERM') {
77-
const enc = process.platform === 'linux' ? 'buffer' : 'utf8';
78-
fs.readdirSync(p, enc).forEach((f) => {
79-
if (f instanceof Buffer) {
80-
const buf = Buffer.concat([Buffer.from(p), Buffer.from(path.sep), f]);
81-
rimrafSync(buf);
82-
} else {
83-
rimrafSync(path.join(p, f));
84-
}
85-
});
86-
fs.rmdirSync(p);
87-
return;
88-
}
89-
throw e;
90-
}
91-
}
92-
9345
const testRoot = process.env.NODE_TEST_DIR ?
9446
fs.realpathSync(process.env.NODE_TEST_DIR) : path.resolve(__dirname, '..');
9547

0 commit comments

Comments
 (0)