mirror of
https://github.com/openstf/stf
synced 2025-10-05 10:39:25 +02:00
Remove packages that were not present when the device was connected.
This commit is contained in:
parent
4f00bc3d11
commit
34bf8adb99
2 changed files with 47 additions and 0 deletions
|
@ -30,6 +30,7 @@ module.exports = function(options) {
|
|||
.dependency(require('./plugins/install'))
|
||||
.dependency(require('./plugins/forward'))
|
||||
.dependency(require('./plugins/group'))
|
||||
.dependency(require('./plugins/cleanup'))
|
||||
.dependency(require('./plugins/reboot'))
|
||||
.dependency(require('./plugins/connect'))
|
||||
.dependency(require('./plugins/data'))
|
||||
|
|
46
lib/units/device/plugins/cleanup.js
Normal file
46
lib/units/device/plugins/cleanup.js
Normal file
|
@ -0,0 +1,46 @@
|
|||
var syrup = require('stf-syrup')
|
||||
var Promise = require('bluebird')
|
||||
var _ = require('lodash')
|
||||
|
||||
var logger = require('../../../util/logger')
|
||||
|
||||
module.exports = syrup.serial()
|
||||
.dependency(require('../support/adb'))
|
||||
.dependency(require('../resources/service'))
|
||||
.dependency(require('./group'))
|
||||
.define(function(options, adb, service, group) {
|
||||
var log = logger.createLogger('device:plugins:cleanup')
|
||||
var plugin = Object.create(null)
|
||||
|
||||
function listPackages() {
|
||||
return adb.getPackages(options.serial)
|
||||
}
|
||||
|
||||
function uninstallPackage(pkg) {
|
||||
log.info('Cleaning up package "%s"', pkg)
|
||||
return adb.uninstall(options.serial, pkg)
|
||||
.catch(function(err) {
|
||||
log.warn('Unable to clean up package "%s"', pkg, err)
|
||||
return true
|
||||
})
|
||||
}
|
||||
|
||||
return listPackages()
|
||||
.then(function(initialPackages) {
|
||||
initialPackages.push(service.pkg)
|
||||
|
||||
plugin.removePackages = function() {
|
||||
return listPackages()
|
||||
.then(function(currentPackages) {
|
||||
var remove = _.difference(currentPackages, initialPackages)
|
||||
return Promise.map(remove, uninstallPackage)
|
||||
})
|
||||
}
|
||||
|
||||
group.on('leave', function() {
|
||||
plugin.removePackages()
|
||||
})
|
||||
|
||||
})
|
||||
.return(plugin)
|
||||
})
|
Loading…
Add table
Add a link
Reference in a new issue