@@ -31,6 +31,60 @@ exports.fixturesDir = path.join(exports.testDir, 'fixtures');
3131exports . libDir = path . join ( exports . testDir , '../lib' ) ;
3232exports . tmpDirName = 'tmp' ;
3333exports . PORT = + process . env . NODE_COMMON_PORT || 12346 ;
34+ exports . isWindows = process . platform === 'win32' ;
35+
36+ function rimrafSync ( p ) {
37+ try {
38+ var st = fs . lstatSync ( p ) ;
39+ } catch ( e ) {
40+ if ( e . code === 'ENOENT' )
41+ return ;
42+ }
43+
44+ try {
45+ if ( st && st . isDirectory ( ) )
46+ rmdirSync ( p , null ) ;
47+ else
48+ fs . unlinkSync ( p ) ;
49+ } catch ( e ) {
50+ if ( e . code === 'ENOENT' )
51+ return ;
52+ if ( e . code === 'EPERM' )
53+ return rmdirSync ( p , er ) ;
54+ if ( e . code !== 'EISDIR' )
55+ throw e ;
56+ rmdirSync ( p , e ) ;
57+ }
58+ }
59+
60+ function rmdirSync ( p , originalEr ) {
61+ try {
62+ fs . rmdirSync ( p ) ;
63+ } catch ( e ) {
64+ if ( e . code === 'ENOTDIR' )
65+ throw originalEr ;
66+ if ( e . code === 'ENOTEMPTY' || e . code === 'EEXIST' || e . code === 'EPERM' ) {
67+ forEach ( fs . readdirSync ( p ) , function ( f ) {
68+ rimrafSync ( path . join ( p , f ) ) ;
69+ } ) ;
70+ fs . rmdirSync ( p ) ;
71+ }
72+ }
73+ }
74+
75+ function refreshTmpDir ( ) {
76+ if ( ! process . send ) { // Not a child process
77+ try {
78+ rimrafSync ( exports . tmpDir ) ;
79+ } catch ( e ) {
80+ }
81+
82+ try {
83+ fs . mkdirSync ( exports . tmpDir ) ;
84+ } catch ( e ) {
85+ }
86+ }
87+ }
3488
3589if ( process . env . TEST_THREAD_ID ) {
3690 // Distribute ports in parallel tests
@@ -41,6 +95,8 @@ if (process.env.TEST_THREAD_ID) {
4195}
4296exports . tmpDir = path . join ( exports . testDir , exports . tmpDirName ) ;
4397
98+ refreshTmpDir ( ) ;
99+
44100var opensslCli = null ;
45101var inFreeBSDJail = null ;
46102var localhostIPv4 = null ;
0 commit comments