@@ -243,6 +243,20 @@ Parse.prototype._readCentralDirectoryFileHeader = function () {
243
243
}
244
244
fileName = fileName . toString ( 'utf8' ) ;
245
245
246
+ var processNextData = function ( ) {
247
+ self . _untilStream . pull ( vars . extraFieldLength , function ( err , extraField ) {
248
+ if ( err ) {
249
+ return self . emit ( 'error' , err ) ;
250
+ }
251
+ self . _untilStream . pull ( vars . fileCommentLength , function ( err , fileComment ) {
252
+ if ( err ) {
253
+ return self . emit ( 'error' , err ) ;
254
+ }
255
+ return self . _readRecord ( ) ;
256
+ } ) ;
257
+ } ) ;
258
+ } ;
259
+
246
260
/*
247
261
Apply the permissions from the "externalFileAttributes" only if the
248
262
zip file was made on UNIX and we are extracting a file onto an
@@ -257,27 +271,31 @@ Parse.prototype._readCentralDirectoryFileHeader = function () {
257
271
if ( self . _opts . verbose ) {
258
272
console . log ( 'Applying mode: 0' + mode . toString ( 8 ) + " to file " + fname ) ;
259
273
}
260
- fs . chmod ( fname , mode , function ( err ) {
261
- if ( err ) {
262
- // This appear when the file is not yet fully written to disk
263
- // while starting to process central directory entries
264
- console . log ( 'Unable to apply mode: 0' + mode . toString ( 8 ) + " to file " + fname ) ;
274
+ var retryNeeded = 10 ;
275
+ var performChmodThenProcessData = function ( ) {
276
+ try {
277
+ if ( ( retryNeeded !== 10 ) && ( self . _opts . verbose ) ) {
278
+ console . log ( retryNeeded + ' - Applying mode: 0' + mode . toString ( 8 ) + " to file " + fname ) ;
279
+ }
280
+ fs . chmodSync ( fname , mode ) ;
281
+ processNextData ( ) ;
282
+ } catch ( error ) {
283
+ if ( retryNeeded -- > 0 ) {
284
+ setTimeout ( performChmodThenProcessData , 100 ) ;
285
+ } else {
286
+ console . log ( 'Unable to apply mode: 0' + mode . toString ( 8 ) + " to file " + fname ) ;
287
+ processNextData ( ) ;
288
+ }
265
289
}
266
- } ) ;
267
- }
268
- }
290
+ } ;
269
291
270
- self . _untilStream . pull ( vars . extraFieldLength , function ( err , extraField ) {
271
- if ( err ) {
272
- return self . emit ( 'error' , err ) ;
292
+ performChmodThenProcessData ( ) ;
293
+ } else {
294
+ processNextData ( ) ;
273
295
}
274
- self . _untilStream . pull ( vars . fileCommentLength , function ( err , fileComment ) {
275
- if ( err ) {
276
- return self . emit ( 'error' , err ) ;
277
- }
278
- return self . _readRecord ( ) ;
279
- } ) ;
280
- } ) ;
296
+ } else {
297
+ processNextData ( ) ;
298
+ }
281
299
} ) ;
282
300
} ) ;
283
301
} ;
0 commit comments