@@ -28,26 +28,19 @@ function retry(
28
28
archive : string
29
29
) {
30
30
// Start the command
31
- return Run ( '7z' , command , options , override )
32
- . progress ( function ( data : any ) {
33
- return progress ( onprogress ( data ) ) ;
34
- } ) // When all is done resolve the Promise.
35
- . then ( function ( args : string [ ] ) {
36
- return resolve ( args ) ;
37
- } ) // Catch the error and pass it to the reject function of the Promise.
38
- . catch ( function ( ) {
39
- console . error ( archive + ' failed using `7z`, retying with `7za`.' ) ;
40
- Run ( '7za' , command , options , override )
41
- . progress ( function ( data : any ) {
42
- return progress ( onprogress ( data ) ) ;
43
- } )
44
- . then ( function ( args : string [ ] ) {
45
- return resolve ( args ) ;
46
- } )
47
- . catch ( function ( err : any ) {
48
- return reject ( err ) ;
49
- } ) ;
31
+ const executables = [ '7z' , '7za' ] ; // Two or more items
32
+ let position = 0 ;
33
+ const runner = ( ) => Run ( executables [ position ] , command , options , override )
34
+ . progress ( ( data : any ) => progress ( onprogress ( data ) ) )
35
+ . then ( ( args : string [ ] ) => resolve ( args ) ) // When all is done resolve the Promise.
36
+ . catch ( ( err : any ) => { // Catch the error and pass it to the reject function of the Promise.
37
+ if ( position === executables . length - 1 ) return reject ( err ) ;
38
+ console . error ( archive + ' failed using `' + executables [ position ] +
39
+ '`, retrying with `' + executables [ position + 1 ] + '`.' ) ;
40
+ position ++ ;
41
+ runner ( ) ;
50
42
} ) ;
43
+ return runner ( ) ;
51
44
}
52
45
53
46
/**
@@ -124,24 +117,20 @@ export const deleteArchive =
124
117
// Convert array of files into a string if needed.
125
118
files = Files ( files ) ;
126
119
// Create a string that can be parsed by `run`.
127
- let command = ' d "' + filepath + '" ' + files ;
120
+ let command = ` d "${ filepath } " ${ files } ` ;
128
121
// Start the command
129
- Run ( '7z' , command , options , override ) // When all is done resolve the Promise.
130
- . then ( function ( args ) {
131
- return resolve ( args ) ;
132
- } ) // Catch the error and pass it to the reject function of the Promise.
133
- . catch ( function ( ) {
134
- console . error (
135
- 'DeleteArchive failed using `7z`, retying with `7za`.'
136
- ) ;
137
- Run ( '7za' , command , options , override )
138
- . then ( function ( args ) {
139
- return resolve ( args ) ;
140
- } )
141
- . catch ( function ( err ) {
142
- return reject ( err ) ;
143
- } ) ;
122
+ const executables = [ '7z' , '7za' ] ; // Two or more items
123
+ let position = 0 ;
124
+ const runner = ( ) => Run ( executables [ position ] , command , options , override )
125
+ . then ( ( args : any [ ] ) => resolve ( args ) ) // When all is done resolve the Promise.
126
+ . catch ( ( err : any ) => { // Catch the error and pass it to the reject function of the Promise.
127
+ if ( position === executables . length - 1 ) return reject ( err ) ;
128
+ console . error ( 'DeleteArchive failed using `' + executables [ position ] +
129
+ '`, retrying with `' + executables [ position + 1 ] + '`.' ) ;
130
+ position ++ ;
131
+ runner ( ) ;
144
132
} ) ;
133
+ return runner ( ) ;
145
134
} ) ;
146
135
} ) ;
147
136
@@ -339,32 +328,20 @@ export const listArchive =
339
328
340
329
// Create a string that can be parsed by `run`.
341
330
let command = 'l "' + filepath + '" ' ;
342
- Run ( isWindows ( ) ? '7z' : '7za' , command , options , override )
343
- . progress ( function ( data : string ) {
344
- return progress ( onprogress ( data ) ) ;
345
- } )
346
- . then ( function ( ) {
347
- return resolve ( spec ) ;
348
- } )
349
- . catch ( function ( err : any ) {
350
- if ( isWindows ( ) ) {
351
- console . error (
352
- 'ListArchive failed using `7z`, retying with `7za`.'
353
- ) ;
354
- Run ( '7za' , command , options , override )
355
- . progress ( function ( data : string ) {
356
- return progress ( onprogress ( data ) ) ;
357
- } )
358
- . then ( function ( args : any ) {
359
- return resolve ( args ) ;
360
- } )
361
- . catch ( function ( err : any ) {
362
- return reject ( err ) ;
363
- } ) ;
364
- } else {
365
- return reject ( err ) ;
366
- }
331
+ // Start the command
332
+ const executables = isWindows ( ) ? [ '7z' , '7za' ] : [ '7za' ] ;
333
+ let position = 0 ;
334
+ const runner = ( ) => Run ( executables [ position ] , command , options , override )
335
+ . progress ( ( data : string ) => progress ( onprogress ( data ) ) )
336
+ . then ( ( args : any ) => resolve ( position === 0 ? spec : args ) )
337
+ . catch ( ( err : any ) => {
338
+ if ( position === executables . length - 1 ) return reject ( err ) ;
339
+ console . error ( 'ListArchive failed using `' + executables [ position ] +
340
+ '`, retrying with `' + executables [ position + 1 ] + '`.' ) ;
341
+ position ++ ;
342
+ runner ( ) ;
367
343
} ) ;
344
+ return runner ( ) ;
368
345
} ) ;
369
346
} ) ;
370
347
0 commit comments