@@ -11,6 +11,7 @@ const {
11
11
Set,
12
12
} = primordials ;
13
13
14
+ const { Buffer } = require ( 'buffer' ) ;
14
15
const {
15
16
chmod,
16
17
chmodSync,
@@ -25,7 +26,7 @@ const {
25
26
unlink,
26
27
unlinkSync
27
28
} = require ( 'fs' ) ;
28
- const { join } = require ( 'path' ) ;
29
+ const { sep } = require ( 'path' ) ;
29
30
const { setTimeout } = require ( 'timers' ) ;
30
31
const { sleep } = require ( 'internal/util' ) ;
31
32
const notEmptyErrorCodes = new Set ( [ 'ENOTEMPTY' , 'EEXIST' , 'EPERM' ] ) ;
@@ -34,6 +35,8 @@ const retryErrorCodes = new Set(
34
35
const isWindows = process . platform === 'win32' ;
35
36
const epermHandler = isWindows ? fixWinEPERM : _rmdir ;
36
37
const epermHandlerSync = isWindows ? fixWinEPERMSync : _rmdirSync ;
38
+ const readdirEncoding = 'buffer' ;
39
+ const separator = Buffer . from ( sep ) ;
37
40
38
41
39
42
function rimraf ( path , options , callback ) {
@@ -122,7 +125,9 @@ function _rmdir(path, options, originalErr, callback) {
122
125
123
126
124
127
function _rmchildren ( path , options , callback ) {
125
- readdir ( path , ( err , files ) => {
128
+ const pathBuf = Buffer . from ( path ) ;
129
+
130
+ readdir ( pathBuf , readdirEncoding , ( err , files ) => {
126
131
if ( err )
127
132
return callback ( err ) ;
128
133
@@ -134,7 +139,9 @@ function _rmchildren(path, options, callback) {
134
139
let done = false ;
135
140
136
141
files . forEach ( ( child ) => {
137
- rimraf ( join ( path , child ) , options , ( err ) => {
142
+ const childPath = Buffer . concat ( [ pathBuf , separator , child ] ) ;
143
+
144
+ rimraf ( childPath , options , ( err ) => {
138
145
if ( done )
139
146
return ;
140
147
@@ -211,8 +218,12 @@ function _rmdirSync(path, options, originalErr) {
211
218
// original removal. Windows has a habit of not closing handles promptly
212
219
// when files are deleted, resulting in spurious ENOTEMPTY failures. Work
213
220
// around that issue by retrying on Windows.
214
- readdirSync ( path ) . forEach ( ( child ) => {
215
- rimrafSync ( join ( path , child ) , options ) ;
221
+ const pathBuf = Buffer . from ( path ) ;
222
+
223
+ readdirSync ( pathBuf , readdirEncoding ) . forEach ( ( child ) => {
224
+ const childPath = Buffer . concat ( [ pathBuf , separator , child ] ) ;
225
+
226
+ rimrafSync ( childPath , options ) ;
216
227
} ) ;
217
228
218
229
const tries = options . maxRetries + 1 ;
0 commit comments