From b6688efb9c2b72662a58cd2351d3ef54a76b7f5f Mon Sep 17 00:00:00 2001 From: cjihrig Date: Tue, 20 Aug 2019 17:19:48 -0400 Subject: [PATCH] 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: https://github.com/nodejs/node/pull/30569 Reviewed-By: Jiawen Geng Reviewed-By: Anna Henningsen Reviewed-By: Rich Trott Reviewed-By: Ben Coe Reviewed-By: Ruben Bridgewater --- test/common/tmpdir.js | 48 +------------------------------------------ 1 file changed, 1 insertion(+), 47 deletions(-) diff --git a/test/common/tmpdir.js b/test/common/tmpdir.js index 2be6e530275fbd..5bfd69a2905a7e 100644 --- a/test/common/tmpdir.js +++ b/test/common/tmpdir.js @@ -35,53 +35,7 @@ function rimrafSync(pathname, { spawn = true } = {}) { } } - try { - if (st.isDirectory()) - rmdirSync(pathname, null); - else - fs.unlinkSync(pathname); - } catch (e) { - debug(e); - switch (e.code) { - case 'ENOENT': - // It's not there anymore. Work is done. Exiting. - return; - - case 'EPERM': - // This can happen, try again with `rmdirSync`. - break; - - case 'EISDIR': - // Got 'EISDIR' even after testing `st.isDirectory()`... - // Try again with `rmdirSync`. - break; - - default: - throw e; - } - rmdirSync(pathname, e); - } -} - -function rmdirSync(p, originalEr) { - try { - fs.rmdirSync(p); - } catch (e) { - if (e.code === 'ENOTDIR') - throw originalEr; - if (e.code === 'ENOTEMPTY' || e.code === 'EEXIST' || e.code === 'EPERM') { - const enc = process.platform === 'linux' ? 'buffer' : 'utf8'; - fs.readdirSync(p, enc).forEach((f) => { - if (f instanceof Buffer) { - const buf = Buffer.concat([Buffer.from(p), Buffer.from(path.sep), f]); - rimrafSync(buf); - } else { - rimrafSync(path.join(p, f)); - } - }); - fs.rmdirSync(p); - } - } + fs.rmdirSync(pathname, { recursive: true, maxRetries: 5 }); } const testRoot = process.env.NODE_TEST_DIR ?