feat(base-driver): prefer system unzip
Backport of to the `2.0` branch of `appium/appium`
MODIFY
packages/base-driver/lib/basedriver/helpers.js
packages/base-driver/lib/basedriver/helpers.js
@@ -2,12 +2,11 @@ import _ from 'lodash';
import path from 'path';
import url from 'url';
import logger from './logger';
-import { tempDir, fs, util, zip, net, timing } from 'appium-support';
+import { system, tempDir, fs, util, zip, net, timing } from 'appium-support';
import LRU from 'lru-cache';
import AsyncLock from 'async-lock';
import axios from 'axios';
-
const IPA_EXT = '.ipa';
const ZIP_EXTS = ['.zip', IPA_EXT];
const ZIP_MIME_TYPES = [
@@ -323,7 +322,15 @@ async function unzipApp (zipPath, dstRoot, supportedAppExtensions) {
try {
logger.debug(`Unzipping '${zipPath}'`);
const timer = new timing.Timer().start();
- const extractionOpts = {};
+ /**
+ * Attempt to use use the system `unzip` (e.g., `/usr/bin/unzip`) due
+ * to the significant performance improvement it provides over the native
+ * JS "unzip" implementation.
+ * @type {import('appium-support/lib/zip').ExtractAllOptions}
+ */
+ const extractionOpts = {
+ useSystemUnzip: !system.isWindows(),
+ };
// https://github.com/appium/appium/issues/14100
if (path.extname(zipPath) === IPA_EXT) {
logger.debug(`Enforcing UTF-8 encoding on the extracted file names for '${path.basename(zipPath)}'`);

MODIFY
packages/base-driver/test/basedriver/helpers-specs.js
packages/base-driver/test/basedriver/helpers-specs.js
-import { isPackageOrBundle, duplicateKeys, parseCapsArray } from '../../lib/basedriver/helpers';
+import { zip, fs, tempDir } from 'appium-support';
+import { configureApp, isPackageOrBundle, duplicateKeys, parseCapsArray } from '../../lib/basedriver/helpers';
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
-
+import sinon from 'sinon';
chai.use(chaiAsPromised);
const should = chai.should();
@@ -92,6 +93,31 @@ describe('helpers', function () {
duplicateKeys(input, 'foo', 'FOO').should.deep.equal(expectedOutput);
});
});
+
+ describe('#configureApp', function () {
+ let sandbox;
+
+ beforeEach(function () {
+ sandbox = sinon.createSandbox();
+ sandbox.stub(zip, 'extractAllTo').resolves();
+ sandbox.stub(zip, 'assertValidZip').resolves();
+ sandbox.stub(fs, 'mv').resolves();
+ sandbox.stub(fs, 'exists').resolves(true);
+ sandbox.stub(fs, 'hash').resolves('0xDEADBEEF');
+ sandbox.stub(fs, 'glob').resolves(['/path/to/an.apk']);
+ sandbox.stub(fs, 'rimraf').resolves();
+ sandbox.stub(tempDir, 'openDir').resolves('/some/dir');
+ });
+
+ afterEach(function () {
+ sandbox.restore();
+ });
+
+ it('should pass "useSystemUnzip" flag through to appium-support', async function () {
+ await configureApp('/path/to/an.apk.zip', '.apk');
+ zip.extractAllTo.getCall(0).lastArg.useSystemUnzip.should.be.true;
+ });
+ });
});
describe('parseCapsArray', function () {

feat(base-driver): prefer system unzip

Backport of https://github.com/appium/appium-base-driver/pull/503 to the `2.0` branch of `appium/appium`