fix: Perform synchronous removal of applications cache
MODIFY
lib/basedriver/helpers.js
lib/basedriver/helpers.js
@@ -10,6 +10,7 @@ import asyncRequest from 'request-promise';
import LRU from 'lru-cache';
import AsyncLock from 'async-lock';
import sanitize from 'sanitize-filename';
+import rimraf from 'rimraf';
const ZIP_EXTS = ['.zip', '.ipa'];
const ZIP_MIME_TYPES = [
@@ -34,32 +35,25 @@ const APPLICATIONS_CACHE_GUARD = new AsyncLock();
const SANITIZE_REPLACEMENT = '-';
const DEFAULT_BASENAME = 'appium-app';
-
-async function cleanupCachedApps () {
+process.on('exit', () => {
if (!APPLICATIONS_CACHE.length) {
return;
}
+ const appPaths = APPLICATIONS_CACHE.values()
+ .map(({fullPath}) => fullPath);
+ APPLICATIONS_CACHE.reset();
- logger.debug('Performing cleanup of the applications cache');
- const cleanupPromises = [];
- for (const {fullPath} of APPLICATIONS_CACHE.values()) {
- cleanupPromises.push((async () => {
- if (await fs.exists(fullPath)) {
- await fs.rimraf(fullPath);
- }
- })());
- }
+ logger.debug(`Performing cleanup of ${appPaths.length} cached ` +
+ `application${appPaths.length === 1 ? '' : 's'}`);
+ for (const appPath of appPaths) {
try {
- await B.all(cleanupPromises);
+ // Asynchronous calls are not supported in onExit handler
+ rimraf.sync(appPath);
} catch (e) {
- logger.error(e);
- } finally {
- APPLICATIONS_CACHE.reset();
+ logger.warn(e.message);
}
}
-
-process.on('exit', cleanupCachedApps);
-process.on('SIGINT', cleanupCachedApps);
+});
async function retrieveHeaders (link) {
@@ -87,7 +81,7 @@ function getCachedApplicationPath (link, currentModified) {
return fullPath;
}
logger.debug(`'Last-Modified' timestamp of '${link}' has been updated. ` +
- `An updated copy of the application is going to be downloaded.`);
+ `A fresh copy of the application is going to be downloaded.`);
return null;
}

MODIFY
package.json
package.json
"morgan": "^1.9.0",
"request": "^2.83.0",
"request-promise": "^4.2.2",
+ "rimraf": "^3.0.0",
"sanitize-filename": "^1.6.1",
"serve-favicon": "^2.4.5",
"source-map-support": "^0.5.5",

fix: Perform synchronous removal of applications cache (#375)