11/* eslint-disable node-core/require-common-first, node-core/required-modules */
22'use strict' ;
33
4- const { execSync } = require ( 'child_process' ) ;
54const fs = require ( 'fs' ) ;
65const path = require ( 'path' ) ;
7- const { debuglog } = require ( 'util' ) ;
86
9- const debug = debuglog ( 'test/tmpdir' ) ;
10-
11- function rimrafSync ( pathname , { spawn = true } = { } ) {
12- const st = ( ( ) => {
13- try {
14- return fs . lstatSync ( pathname ) ;
15- } catch ( e ) {
16- if ( fs . existsSync ( pathname ) )
17- throw new Error ( `Something wonky happened rimrafing ${ pathname } ` ) ;
18- debug ( e ) ;
19- }
20- } ) ( ) ;
21-
22- // If (!st) then nothing to do.
23- if ( ! st ) {
24- return ;
25- }
26-
27- // On Windows first try to delegate rmdir to a shell.
28- if ( spawn && process . platform === 'win32' && st . isDirectory ( ) ) {
29- try {
30- // Try `rmdir` first.
31- execSync ( `rmdir /q /s ${ pathname } ` , { timeout : 1000 } ) ;
32- } catch ( e ) {
33- // Attempt failed. Log and carry on.
34- debug ( e ) ;
35- }
36- }
37-
38- fs . rmdirSync ( pathname , { recursive : true , maxRetries : 5 } ) ;
7+ function rimrafSync ( pathname ) {
8+ fs . rmdirSync ( pathname , { maxRetries : 3 , recursive : true } ) ;
399}
4010
4111const testRoot = process . env . NODE_TEST_DIR ?
@@ -46,8 +16,8 @@ const testRoot = process.env.NODE_TEST_DIR ?
4616const tmpdirName = '.tmp.' + ( process . env . TEST_THREAD_ID || '0' ) ;
4717const tmpPath = path . join ( testRoot , tmpdirName ) ;
4818
49- function refresh ( opts = { } ) {
50- rimrafSync ( this . path , opts ) ;
19+ function refresh ( ) {
20+ rimrafSync ( this . path ) ;
5121 fs . mkdirSync ( this . path ) ;
5222}
5323
0 commit comments