@@ -6,10 +6,13 @@ const assert = require('assert'); |
6 | 6 | const fs = require('fs'); |
7 | 7 | const path = require('path'); |
8 | 8 | const { validateRmdirOptions } = require('internal/fs/utils'); |
9 | | -let count = 0; |
10 | 9 |
|
11 | 10 | tmpdir.refresh(); |
12 | 11 |
|
| 12 | +let count = 0; |
| 13 | +const nextDirPath = (name = 'rmdir-recursive') => |
| 14 | + path.join(tmpdir.path, `${name}-${count++}`); |
| 15 | + |
13 | 16 | function makeNonEmptyDirectory(depth, files, folders, dirname, createSymLinks) { |
14 | 17 | fs.mkdirSync(dirname, { recursive: true }); |
15 | 18 | fs.writeFileSync(path.join(dirname, 'text.txt'), 'hello', 'utf8'); |
@@ -89,27 +92,24 @@ function removeAsync(dir) { |
89 | 92 | // Test the asynchronous version |
90 | 93 | { |
91 | 94 | // Create a 4-level folder hierarchy including symlinks |
92 | | - let dir = `rmdir-recursive-${count}`; |
| 95 | + let dir = nextDirPath(); |
93 | 96 | makeNonEmptyDirectory(4, 10, 2, dir, true); |
94 | 97 | removeAsync(dir); |
95 | 98 |
|
96 | 99 | // Create a 2-level folder hierarchy without symlinks |
97 | | - count++; |
98 | | - dir = `rmdir-recursive-${count}`; |
| 100 | + dir = nextDirPath(); |
99 | 101 | makeNonEmptyDirectory(2, 10, 2, dir, false); |
100 | 102 | removeAsync(dir); |
101 | 103 |
|
102 | 104 | // Create a flat folder including symlinks |
103 | | - count++; |
104 | | - dir = `rmdir-recursive-${count}`; |
| 105 | + dir = nextDirPath(); |
105 | 106 | makeNonEmptyDirectory(1, 10, 2, dir, true); |
106 | 107 | removeAsync(dir); |
107 | 108 | } |
108 | 109 |
|
109 | 110 | // Test the synchronous version. |
110 | 111 | { |
111 | | - count++; |
112 | | - const dir = `rmdir-recursive-${count}`; |
| 112 | + const dir = nextDirPath(); |
113 | 113 | makeNonEmptyDirectory(4, 10, 2, dir, true); |
114 | 114 |
|
115 | 115 | // Removal should fail without the recursive option set to true. |
@@ -132,8 +132,7 @@ function removeAsync(dir) { |
132 | 132 |
|
133 | 133 | // Test the Promises based version. |
134 | 134 | (async () => { |
135 | | - count++; |
136 | | - const dir = `rmdir-recursive-${count}`; |
| 135 | + const dir = nextDirPath(); |
137 | 136 | makeNonEmptyDirectory(4, 10, 2, dir, true); |
138 | 137 |
|
139 | 138 | // Removal should fail without the recursive option set to true. |
|