@@ -11,6 +11,7 @@ const {
1111 Set,
1212} = primordials ;
1313
14+ const { Buffer } = require ( 'buffer' ) ;
1415const {
1516 chmod,
1617 chmodSync,
@@ -25,7 +26,7 @@ const {
2526 unlink,
2627 unlinkSync
2728} = require ( 'fs' ) ;
28- const { join } = require ( 'path' ) ;
29+ const { sep } = require ( 'path' ) ;
2930const { setTimeout } = require ( 'timers' ) ;
3031const { sleep } = require ( 'internal/util' ) ;
3132const notEmptyErrorCodes = new Set ( [ 'ENOTEMPTY' , 'EEXIST' , 'EPERM' ] ) ;
@@ -34,6 +35,8 @@ const retryErrorCodes = new Set(
3435const isWindows = process . platform === 'win32' ;
3536const epermHandler = isWindows ? fixWinEPERM : _rmdir ;
3637const epermHandlerSync = isWindows ? fixWinEPERMSync : _rmdirSync ;
38+ const readdirEncoding = 'buffer' ;
39+ const separator = Buffer . from ( sep ) ;
3740
3841
3942function rimraf ( path , options , callback ) {
@@ -122,7 +125,9 @@ function _rmdir(path, options, originalErr, callback) {
122125
123126
124127function _rmchildren ( path , options , callback ) {
125- readdir ( path , ( err , files ) => {
128+ const pathBuf = Buffer . from ( path ) ;
129+
130+ readdir ( pathBuf , readdirEncoding , ( err , files ) => {
126131 if ( err )
127132 return callback ( err ) ;
128133
@@ -134,7 +139,9 @@ function _rmchildren(path, options, callback) {
134139 let done = false ;
135140
136141 files . forEach ( ( child ) => {
137- rimraf ( join ( path , child ) , options , ( err ) => {
142+ const childPath = Buffer . concat ( [ pathBuf , separator , child ] ) ;
143+
144+ rimraf ( childPath , options , ( err ) => {
138145 if ( done )
139146 return ;
140147
@@ -211,8 +218,12 @@ function _rmdirSync(path, options, originalErr) {
211218 // original removal. Windows has a habit of not closing handles promptly
212219 // when files are deleted, resulting in spurious ENOTEMPTY failures. Work
213220 // 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 ) ;
216227 } ) ;
217228
218229 const tries = options . maxRetries + 1 ;
0 commit comments