diff --git a/src/apps.js b/src/apps.js index 35439f113..9718e1b5b 100644 --- a/src/apps.js +++ b/src/apps.js @@ -1418,11 +1418,12 @@ function restore(appId, backupId, auditSource, callback) { error = checkManifestConstraints(backupInfo.manifest); if (error) return callback(error); - const restoreConfig = { backupId, backupFormat: backupInfo.format, oldManifest: app.manifest }; + const restoreConfig = { backupId, backupFormat: backupInfo.format }; const task = { args: { restoreConfig, + oldManifest: app.manifest, overwriteDns: true }, values: { @@ -1469,11 +1470,12 @@ function importApp(appId, data, auditSource, callback) { testBackupConfig(function (error) { if (error) return callback(error); - const restoreConfig = { backupId, backupFormat, backupConfig, oldManifest: app.manifest }; + const restoreConfig = { backupId, backupFormat, backupConfig }; const task = { args: { restoreConfig, + oldManifest: app.manifest, overwriteDns: true }, values: {} @@ -1570,9 +1572,9 @@ function clone(appId, data, user, auditSource, callback) { purchaseApp({ appId: newAppId, appstoreId: app.appStoreId, manifestId: manifest.id || 'customapp' }, function (error) { if (error) return callback(error); - const restoreConfig = { backupId: backupId, backupFormat: backupInfo.format, oldManifest: null }; + const restoreConfig = { backupId: backupId, backupFormat: backupInfo.format }; const task = { - args: { restoreConfig, overwriteDns }, + args: { restoreConfig, overwriteDns, oldManifest: null }, values: {}, requiredState: exports.ISTATE_PENDING_CLONE }; @@ -1844,17 +1846,19 @@ function restoreInstalledApps(callback) { async.eachSeries(apps, function (app, iteratorDone) { backups.getByAppIdPaged(1, 1, app.id, function (error, results) { - let installationState, restoreConfig; + let installationState, restoreConfig, oldManifest; if (!error && results.length) { installationState = exports.ISTATE_PENDING_RESTORE; - restoreConfig = { backupId: results[0].id, backupFormat: results[0].format, oldManifest: app.manifest }; + restoreConfig = { backupId: results[0].id, backupFormat: results[0].format }; + oldManifest = app.manifest; } else { installationState = exports.ISTATE_PENDING_INSTALL; restoreConfig = null; + oldManifest = null; } const task = { - args: { restoreConfig, overwriteDns: true }, + args: { restoreConfig, overwriteDns: true, oldManifest }, values: {}, scheduleNow: false, // task will be scheduled by autoRestartTasks when platform is ready requireNullTaskId: false // ignore existing stale taskId diff --git a/src/apptask.js b/src/apptask.js index 19e63a6db..a129b5a9a 100644 --- a/src/apptask.js +++ b/src/apptask.js @@ -515,6 +515,7 @@ function install(app, args, progressCallback, callback) { const restoreConfig = args.restoreConfig; // has to be set when restoring const overwriteDns = args.overwriteDns; + const oldManifest = args.oldManifest; async.series([ // this protects against the theoretical possibility of an app being marked for install/restore from @@ -528,8 +529,8 @@ function install(app, args, progressCallback, callback) { function teardownAddons(next) { // when restoring, app does not require these addons anymore. remove carefully to preserve the db passwords let addonsToRemove; - if (restoreConfig && restoreConfig.oldManifest) { // oldManifest is null for clone - addonsToRemove = _.omit(restoreConfig.oldManifest.addons, Object.keys(app.manifest.addons)); + if (oldManifest) { + addonsToRemove = _.omit(oldManifest.addons, Object.keys(app.manifest.addons)); } else { addonsToRemove = app.manifest.addons; } @@ -544,11 +545,9 @@ function install(app, args, progressCallback, callback) { }, function deleteImageIfChanged(done) { - if (!restoreConfig || !restoreConfig.oldManifest) return done(); + if (!oldManifest || oldManifest.dockerImage === app.manifest.dockerImage) return done(); - if (restoreConfig.oldManifest.dockerImage === app.manifest.dockerImage) return done(); - - docker.deleteImage(restoreConfig.oldManifest, done); + docker.deleteImage(oldManifest, done); }, reserveHttpPort.bind(null, app),