Skip to content

Commit 7e87f4b

Browse files
committed
refactor deleteArchive function (index.ts)
1 parent 407c3e3 commit 7e87f4b

File tree

1 file changed

+12
-16
lines changed

1 file changed

+12
-16
lines changed

src/index.ts

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -117,24 +117,20 @@ export const deleteArchive =
117117
// Convert array of files into a string if needed.
118118
files = Files(files);
119119
// Create a string that can be parsed by `run`.
120-
let command = 'd "' + filepath + '" ' + files;
120+
let command = `d "${filepath}" ${files}`;
121121
// Start the command
122-
Run('7z', command, options, override) // When all is done resolve the Promise.
123-
.then(function (args) {
124-
return resolve(args);
125-
}) // Catch the error and pass it to the reject function of the Promise.
126-
.catch(function () {
127-
console.error(
128-
'DeleteArchive failed using `7z`, retying with `7za`.'
129-
);
130-
Run('7za', command, options, override)
131-
.then(function (args) {
132-
return resolve(args);
133-
})
134-
.catch(function (err) {
135-
return reject(err);
136-
});
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();
137132
});
133+
return runner();
138134
});
139135
});
140136

0 commit comments

Comments
 (0)