@@ -190,7 +190,7 @@ function rimrafSync(path, options) {
190190 if ( stats !== undefined && stats . isDirectory ( ) )
191191 _rmdirSync ( path , options , null ) ;
192192 else
193- unlinkSync ( path ) ;
193+ _unlinkSync ( path , options ) ;
194194 } catch ( err ) {
195195 if ( err . code === 'ENOENT' )
196196 return ;
@@ -204,6 +204,25 @@ function rimrafSync(path, options) {
204204}
205205
206206
207+ function _unlinkSync ( path , options ) {
208+ const tries = options . maxRetries + 1 ;
209+
210+ for ( let i = 1 ; i <= tries ; i ++ ) {
211+ try {
212+ return unlinkSync ( path ) ;
213+ } catch ( err ) {
214+ // Only sleep if this is not the last try, and the delay is greater
215+ // than zero, and an error was encountered that warrants a retry.
216+ if ( retryErrorCodes . has ( err . code ) &&
217+ i < tries &&
218+ options . retryDelay > 0 ) {
219+ sleep ( i * options . retryDelay ) ;
220+ }
221+ }
222+ }
223+ }
224+
225+
207226function _rmdirSync ( path , options , originalErr ) {
208227 try {
209228 rmdirSync ( path ) ;
@@ -270,7 +289,7 @@ function fixWinEPERMSync(path, options, originalErr) {
270289 if ( stats . isDirectory ( ) )
271290 _rmdirSync ( path , options , originalErr ) ;
272291 else
273- unlinkSync ( path ) ;
292+ _unlinkSync ( path , options ) ;
274293}
275294
276295
0 commit comments