Fix installation states
App operations can only be done in 'installed' or 'error' state. If some other operation is in progress, you have to cancel it first. This guarantees that the old app command got killed.
This commit is contained in:
33
src/appdb.js
33
src/appdb.js
@@ -475,7 +475,7 @@ function setHealth(appId, health, healthTime, callback) {
|
||||
|
||||
var values = { health, healthTime };
|
||||
|
||||
var constraints = 'AND runState NOT LIKE "pending_%" AND installationState = "installed"';
|
||||
var constraints = `AND runState NOT LIKE "pending_%" AND installationState = "${exports.ISTATE_INSTALLED}"`;
|
||||
|
||||
updateWithConstraints(appId, values, constraints, callback);
|
||||
}
|
||||
@@ -483,36 +483,13 @@ function setHealth(appId, health, healthTime, callback) {
|
||||
function setInstallationCommand(appId, installationState, values, callback) {
|
||||
assert.strictEqual(typeof appId, 'string');
|
||||
assert.strictEqual(typeof installationState, 'string');
|
||||
|
||||
if (typeof values === 'function') {
|
||||
callback = values;
|
||||
values = { };
|
||||
} else {
|
||||
assert.strictEqual(typeof values, 'object');
|
||||
assert.strictEqual(typeof callback, 'function');
|
||||
}
|
||||
assert.strictEqual(typeof values, 'object');
|
||||
assert.strictEqual(typeof callback, 'function');
|
||||
|
||||
values.installationState = installationState;
|
||||
values.errorMessage = '';
|
||||
|
||||
// Rules are:
|
||||
// uninstall is allowed in any state
|
||||
// force update is allowed in any state including pending_uninstall! (for better or worse)
|
||||
// restore is allowed from installed or error state or currently restoring
|
||||
// configure is allowed in installed state or currently configuring or in error state
|
||||
// update and backup are allowed only in installed state
|
||||
|
||||
if (installationState === exports.ISTATE_PENDING_UNINSTALL || installationState === exports.ISTATE_PENDING_FORCE_UPDATE) {
|
||||
updateWithConstraints(appId, values, '', callback);
|
||||
} else if (installationState === exports.ISTATE_PENDING_RESTORE) {
|
||||
updateWithConstraints(appId, values, 'AND (installationState = "installed" OR installationState = "error" OR installationState = "pending_restore")', callback);
|
||||
} else if (installationState === exports.ISTATE_PENDING_UPDATE || installationState === exports.ISTATE_PENDING_BACKUP) {
|
||||
updateWithConstraints(appId, values, 'AND installationState = "installed"', callback);
|
||||
} else if (installationState === exports.ISTATE_PENDING_CONFIGURE) {
|
||||
updateWithConstraints(appId, values, 'AND (installationState = "installed" OR installationState = "pending_configure" OR installationState = "error")', callback);
|
||||
} else {
|
||||
callback(new DatabaseError(DatabaseError.INTERNAL_ERROR, 'invalid installationState'));
|
||||
}
|
||||
updateWithConstraints(appId, values, `AND (installationState = "${exports.ISTATE_INSTALLED}" OR installationState = "${exports.ISTATE_ERROR}")`, callback);
|
||||
}
|
||||
|
||||
function setRunCommand(appId, runState, callback) {
|
||||
@@ -521,7 +498,7 @@ function setRunCommand(appId, runState, callback) {
|
||||
assert.strictEqual(typeof callback, 'function');
|
||||
|
||||
var values = { runState: runState };
|
||||
updateWithConstraints(appId, values, 'AND runState NOT LIKE "pending_%" AND installationState = "installed"', callback);
|
||||
updateWithConstraints(appId, values, `AND installationState = "${exports.ISTATE_INSTALLED}"`, callback);
|
||||
}
|
||||
|
||||
function getAppStoreIds(callback) {
|
||||
|
||||
Reference in New Issue
Block a user