Explicitly remove volumes when purging

Change-type: patch
Closes: #1083
Signed-off-by: Cameron Diver <cameron@balena.io>
This commit is contained in:
Cameron Diver 2019-09-17 14:44:47 +01:00
parent 7d1da38184
commit 15a1f45fd7

View File

@ -1,3 +1,4 @@
Bluebird = require('bluebird')
_ = require('lodash')
{ appNotFoundMessage } = require('../lib/messages')
@ -23,7 +24,7 @@ exports.doRestart = (applications, appId, force) ->
deviceState.triggerApplyTarget()
exports.doPurge = (applications, appId, force) ->
{ logger, _lockingIfNecessary, deviceState } = applications
{ logger, _lockingIfNecessary, deviceState, volumes } = applications
logger.logSystemMessage("Purging data for app #{appId}", { appId }, 'Purge data')
_lockingIfNecessary appId, { force }, ->
@ -38,6 +39,12 @@ exports.doPurge = (applications, appId, force) ->
currentState.local.apps[appId] = purgedApp
deviceState.pausingApply ->
deviceState.applyIntermediateTarget(currentState, { skipLock: true })
.then ->
# Now that we're not running anything, explicitly
# remove the volumes, we must do this here, as the
# application-manager will not remove any volumes
# which are part of an active application
Bluebird.each(volumes.getAllByAppId(appId), (vol) -> vol.remove())
.then ->
currentState.local.apps[appId] = app
deviceState.applyIntermediateTarget(currentState, { skipLock: true })