1
1
/* eslint-disable node-core/require-common-first, node-core/required-modules */
2
2
'use strict' ;
3
3
4
- const { execSync } = require ( 'child_process' ) ;
5
4
const fs = require ( 'fs' ) ;
6
5
const path = require ( 'path' ) ;
7
- const { debuglog } = require ( 'util' ) ;
8
6
const { isMainThread } = require ( 'worker_threads' ) ;
9
7
10
- const debug = debuglog ( 'test/tmpdir' ) ;
11
-
12
- function rimrafSync ( pathname , { spawn = true } = { } ) {
13
- const st = ( ( ) => {
14
- try {
15
- return fs . lstatSync ( pathname ) ;
16
- } catch ( e ) {
17
- if ( fs . existsSync ( pathname ) )
18
- throw new Error ( `Something wonky happened rimrafing ${ pathname } ` ) ;
19
- debug ( e ) ;
20
- }
21
- } ) ( ) ;
22
-
23
- // If (!st) then nothing to do.
24
- if ( ! st ) {
25
- return ;
26
- }
27
-
28
- // On Windows first try to delegate rmdir to a shell.
29
- if ( spawn && process . platform === 'win32' && st . isDirectory ( ) ) {
30
- try {
31
- // Try `rmdir` first.
32
- execSync ( `rmdir /q /s ${ pathname } ` , { timeout : 1000 } ) ;
33
- } catch ( e ) {
34
- // Attempt failed. Log and carry on.
35
- debug ( e ) ;
36
- }
37
- }
38
-
39
- fs . rmdirSync ( pathname , { recursive : true , maxRetries : 5 } ) ;
40
-
41
- if ( fs . existsSync ( pathname ) )
42
- throw new Error ( `Unable to rimraf ${ pathname } ` ) ;
8
+ function rimrafSync ( pathname ) {
9
+ fs . rmdirSync ( pathname , { maxRetries : 3 , recursive : true } ) ;
43
10
}
44
11
45
12
const testRoot = process . env . NODE_TEST_DIR ?
@@ -52,8 +19,8 @@ const tmpdirName = '.tmp.' +
52
19
const tmpPath = path . join ( testRoot , tmpdirName ) ;
53
20
54
21
let firstRefresh = true ;
55
- function refresh ( opts = { } ) {
56
- rimrafSync ( this . path , opts ) ;
22
+ function refresh ( ) {
23
+ rimrafSync ( this . path ) ;
57
24
fs . mkdirSync ( this . path ) ;
58
25
59
26
if ( firstRefresh ) {
@@ -70,7 +37,7 @@ function onexit() {
70
37
process . chdir ( testRoot ) ;
71
38
72
39
try {
73
- rimrafSync ( tmpPath , { spawn : false } ) ;
40
+ rimrafSync ( tmpPath ) ;
74
41
} catch ( e ) {
75
42
console . error ( 'Can\'t clean tmpdir:' , tmpPath ) ;
76
43
0 commit comments