@@ -5,6 +5,36 @@ import { Files, ReplaceNativeSeparator, Run } from './utility.js';
5
5
6
6
import { createSfx } from './createSfx.js' ;
7
7
8
+ function retry ( command , options , override , progress , onprogress , resolve , reject , archive , noRetry = false ) {
9
+ // Start the command
10
+ return Run ( '7z' , command , options , override )
11
+ . progress ( function ( data ) {
12
+ return progress ( onprogress ( data ) ) ;
13
+ } )
14
+
15
+ // When all is done resolve the Promise.
16
+ . then ( function ( args ) {
17
+ return resolve ( args ) ;
18
+ } )
19
+
20
+ // Catch the error and pass it to the reject function of the Promise.
21
+ . catch ( function ( ) {
22
+ console . error ( archive + ' failed using `7z`, retying with `7za`.' ) ;
23
+ Run ( '7za' , command , options , override )
24
+ . progress ( function ( data ) {
25
+ return progress ( onprogress ( data ) ) ;
26
+ } )
27
+
28
+ . then ( function ( args ) {
29
+ return resolve ( args ) ;
30
+ } )
31
+ . catch ( function ( err ) {
32
+ return reject ( err ) ;
33
+ } ) ;
34
+ } ) ;
35
+ } ;
36
+
37
+
8
38
/**
9
39
* Create/add content to an archive.
10
40
*
@@ -43,35 +73,10 @@ export const createArchive = SevenZip.createArchive = function (filepath, files,
43
73
let command = 'a "' + filepath + '" ' + files ;
44
74
45
75
// Start the command
46
- Run ( '7z' , command , options , override )
47
- . progress ( function ( data ) {
48
- return progress ( onprogress ( data ) ) ;
49
- } )
50
-
51
- // When all is done resolve the Promise.
52
- . then ( function ( args ) {
53
- return resolve ( args ) ;
54
- } )
55
-
56
- // Catch the error and pass it to the reject function of the Promise.
57
- . catch ( function ( ) {
58
- console . error ( 'CreateArchive failed using `7z`, retying with `7za`.' ) ;
59
- Run ( '7za' , command , options , override )
60
- . progress ( function ( data ) {
61
- return progress ( onprogress ( data ) ) ;
62
- } )
63
-
64
- . then ( function ( args ) {
65
- return resolve ( args ) ;
66
- } )
67
- . catch ( function ( err ) {
68
- return reject ( err ) ;
69
- } ) ;
70
- } ) ;
76
+ return retry ( command , options , override , progress , onprogress , resolve , reject , 'CreateArchive' ) ;
71
77
} ) ;
72
78
} ;
73
79
74
-
75
80
/**
76
81
* Delete content from an archive.
77
82
*
@@ -151,30 +156,7 @@ export const extractArchive = SevenZip.extractArchive = function (filepath, dest
151
156
let command = 'e "' + filepath + '" -o"' + dest + '" ' ;
152
157
153
158
// Start the command
154
- Run ( '7z' , command , options , override )
155
- . progress ( function ( data ) {
156
- return progress ( onprogress ( data ) ) ;
157
- } )
158
-
159
- // When all is done resolve the Promise.
160
- . then ( function ( args ) {
161
- return resolve ( args ) ;
162
- } )
163
-
164
- // Catch the error and pass it to the reject function of the Promise.
165
- . catch ( function ( ) {
166
- console . error ( 'ExtractArchive failed using `7z`, retying with `7za`.' ) ;
167
- Run ( '7za' , command , options , override )
168
- . progress ( function ( data ) {
169
- return progress ( onprogress ( data ) ) ;
170
- } )
171
- . then ( function ( args ) {
172
- return resolve ( args ) ;
173
- } )
174
- . catch ( function ( err ) {
175
- return reject ( err ) ;
176
- } ) ;
177
- } ) ;
159
+ return retry ( command , options , override , progress , onprogress , resolve , reject , 'ExtractArchive' ) ;
178
160
} ) ;
179
161
} ;
180
162
@@ -212,26 +194,7 @@ export const fullArchive = SevenZip.fullArchive = function (filepath, dest = '*'
212
194
// Create a string that can be parsed by `run`.
213
195
let command = 'x "' + filepath + '" -o"' + dest + '" ' ;
214
196
215
- Run ( '7z' , command , options , override )
216
- . progress ( function ( data ) {
217
- return progress ( onprogress ( data ) ) ;
218
- } )
219
- . then ( function ( args ) {
220
- return resolve ( args ) ;
221
- } )
222
- . catch ( function ( ) {
223
- console . error ( 'FullArchive failed using `7z`, retying with `7za`.' ) ;
224
- Run ( '7za' , command , options , override )
225
- . progress ( function ( data ) {
226
- return progress ( onprogress ( data ) ) ;
227
- } )
228
- . then ( function ( args ) {
229
- return resolve ( args ) ;
230
- } )
231
- . catch ( function ( err ) {
232
- return reject ( err ) ;
233
- } ) ;
234
- } ) ;
197
+ return retry ( command , options , override , progress , onprogress , resolve , reject , 'FullArchive' ) ;
235
198
} ) ;
236
199
} ;
237
200
@@ -303,6 +266,7 @@ export const listArchive = SevenZip.listArchive = function (filepath, options, o
303
266
304
267
// Create a string that can be parsed by `run`.
305
268
let command = 'l "' + filepath + '" ' ;
269
+
306
270
Run ( ( process . platform == 'win32' ? '7z' : '7za' ) , command , options , override )
307
271
. progress ( function ( data ) {
308
272
return progress ( onprogress ( data ) ) ;
@@ -368,30 +332,7 @@ export const onlyArchive = SevenZip.onlyArchive = function (filepath, dest, file
368
332
let command = 'e "' + filepath + '" -o"' + dest + '"' ;
369
333
370
334
// Start the command
371
- Run ( '7z' , command , options , override )
372
- . progress ( function ( data ) {
373
- return progress ( onprogress ( data ) ) ;
374
- } )
375
-
376
- // When all is done resolve the Promise.
377
- . then ( function ( args ) {
378
- return resolve ( args ) ;
379
- } )
380
-
381
- // Catch the error and pass it to the reject function of the Promise.
382
- . catch ( function ( ) {
383
- console . error ( 'OnlyArchive failed using `7z`, retying with `7za`.' ) ;
384
- Run ( '7za' , command , options , override )
385
- . progress ( function ( data ) {
386
- return progress ( onprogress ( data ) ) ;
387
- } )
388
- . then ( function ( args ) {
389
- return resolve ( args ) ;
390
- } )
391
- . catch ( function ( err ) {
392
- return reject ( err ) ;
393
- } ) ;
394
- } ) ;
335
+ return retry ( command , options , override , progress , onprogress , resolve , reject , 'OnlyArchive' ) ;
395
336
} ) ;
396
337
} ;
397
338
@@ -433,26 +374,7 @@ export const renameArchive = SevenZip.renameArchive = function (filepath, files,
433
374
let command = 'rn "' + filepath + '" ' + files ;
434
375
435
376
// Start the command
436
- Run ( '7z' , command , options , override )
437
- . progress ( function ( data ) {
438
- return progress ( onprogress ( data ) ) ;
439
- } )
440
- . then ( function ( ) {
441
- return resolve ( ) ;
442
- } )
443
- . catch ( function ( ) {
444
- console . error ( 'RenameArchive failed using `7z`, retying with `7za`.' ) ;
445
- Run ( '7za' , command , options , override )
446
- . progress ( function ( data ) {
447
- return progress ( onprogress ( data ) ) ;
448
- } )
449
- . then ( function ( args ) {
450
- return resolve ( args ) ;
451
- } )
452
- . catch ( function ( err ) {
453
- return reject ( err ) ;
454
- } ) ;
455
- } ) ;
377
+ return retry ( command , options , override , progress , onprogress , resolve , reject , 'RenameArchive' ) ;
456
378
} ) ;
457
379
} ;
458
380
@@ -490,31 +412,7 @@ export const testArchive = SevenZip.testArchive = function (filepath, options, o
490
412
let command = 't "' + filepath + '"' ;
491
413
492
414
// Start the command
493
- Run ( '7z' , command , options , override )
494
- . progress ( function ( data ) {
495
- return progress ( onprogress ( data ) ) ;
496
- } )
497
-
498
- // When all is done resolve the Promise.
499
- . then ( function ( args ) {
500
- return resolve ( args ) ;
501
- } )
502
-
503
- // Catch the error and pass it to the reject function of the Promise.
504
- . catch ( function ( ) {
505
- console . error ( 'TestArchive failed using `7z`, retying with `7za`.' ) ;
506
- Run ( '7za' , command , options , override )
507
- . progress ( function ( data ) {
508
- return progress ( onprogress ( data ) ) ;
509
- } )
510
- . then ( function ( args ) {
511
- return resolve ( args ) ;
512
- } )
513
- . catch ( function ( err ) {
514
- return reject ( err ) ;
515
- } ) ;
516
- } ) ;
517
-
415
+ return retry ( command , options , override , progress , onprogress , resolve , reject , 'TestArchive' ) ;
518
416
} ) ;
519
417
} ;
520
418
@@ -556,31 +454,7 @@ export const updateArchive = SevenZip.updateArchive = function (filepath, files,
556
454
let command = 'u "' + filepath + '" ' + files ;
557
455
558
456
// Start the command
559
- Run ( '7z' , command , options , override )
560
- . progress ( function ( data ) {
561
- return progress ( onprogress ( data ) ) ;
562
- } )
563
-
564
- // When all is done resolve the Promise.
565
- . then ( function ( ) {
566
- return resolve ( ) ;
567
- } )
568
-
569
- // Catch the error and pass it to the reject function of the Promise.
570
- . catch ( function ( ) {
571
- console . error ( 'UpdateArchive failed using `7z`, retying with `7za`.' ) ;
572
- Run ( '7za' , command , options , override )
573
- . progress ( function ( data ) {
574
- return progress ( onprogress ( data ) ) ;
575
- } )
576
- . then ( function ( args ) {
577
- return resolve ( args ) ;
578
- } )
579
- . catch ( function ( err ) {
580
- return reject ( err ) ;
581
- } ) ;
582
- } ) ;
583
-
457
+ return retry ( command , options , override , progress , onprogress , resolve , reject , 'UpdateArchive' ) ;
584
458
} ) ;
585
459
} ;
586
460
0 commit comments