@@ -184,7 +184,7 @@ function rimrafSync(path, options) {
184184 if ( stats !== undefined && stats . isDirectory ( ) )
185185 _rmdirSync ( path , options , null ) ;
186186 else
187- unlinkSync ( path ) ;
187+ _unlinkSync ( path , options ) ;
188188 } catch ( err ) {
189189 if ( err . code === 'ENOENT' )
190190 return ;
@@ -198,6 +198,25 @@ function rimrafSync(path, options) {
198198}
199199
200200
201+ function _unlinkSync ( path , options ) {
202+ const tries = options . maxRetries + 1 ;
203+
204+ for ( let i = 1 ; i <= tries ; i ++ ) {
205+ try {
206+ return unlinkSync ( path ) ;
207+ } catch ( err ) {
208+ // Only sleep if this is not the last try, and the delay is greater
209+ // than zero, and an error was encountered that warrants a retry.
210+ if ( retryErrorCodes . has ( err . code ) &&
211+ i < tries &&
212+ options . retryDelay > 0 ) {
213+ sleep ( i * options . retryDelay ) ;
214+ }
215+ }
216+ }
217+ }
218+
219+
201220function _rmdirSync ( path , options , originalErr ) {
202221 try {
203222 rmdirSync ( path ) ;
@@ -264,7 +283,7 @@ function fixWinEPERMSync(path, options, originalErr) {
264283 if ( stats . isDirectory ( ) )
265284 _rmdirSync ( path , options , originalErr ) ;
266285 else
267- unlinkSync ( path ) ;
286+ _unlinkSync ( path , options ) ;
268287}
269288
270289
0 commit comments