Skip to content

Commit b44c004

Browse files
committed
partially refactor listArchive function (index.ts)
1 parent 7e87f4b commit b44c004

File tree

1 file changed

+13
-25
lines changed

1 file changed

+13
-25
lines changed

src/index.ts

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -328,32 +328,20 @@ export const listArchive =
328328

329329
// Create a string that can be parsed by `run`.
330330
let command = 'l "' + filepath + '" ';
331-
Run(isWindows() ? '7z' : '7za', command, options, override)
332-
.progress(function (data: string) {
333-
return progress(onprogress(data));
334-
})
335-
.then(function () {
336-
return resolve(spec);
337-
})
338-
.catch(function (err: any) {
339-
if (isWindows()) {
340-
console.error(
341-
'ListArchive failed using `7z`, retying with `7za`.'
342-
);
343-
Run('7za', command, options, override)
344-
.progress(function (data: string) {
345-
return progress(onprogress(data));
346-
})
347-
.then(function (args: any) {
348-
return resolve(args);
349-
})
350-
.catch(function (err: any) {
351-
return reject(err);
352-
});
353-
} else {
354-
return reject(err);
355-
}
331+
// Start the command
332+
const executables = ['7z', '7za'];
333+
let position = isWindows() ? 0 : 1; // Windows - 2 attempts, others - 1 attempt
334+
const runner = () => Run(executables[position], command, options, override)
335+
.progress((data: string) => progress(onprogress(data)))
336+
.then((args: any) => resolve(position === 1 && isWindows() ? args : spec))
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();
356343
});
344+
return runner();
357345
});
358346
});
359347

0 commit comments

Comments
 (0)