update: handle change in secondary domains and multiDomain flag
This commit is contained in:
+30
-11
@@ -633,23 +633,42 @@ async function update(app, args, progressCallback) {
|
||||
await services.teardownAddons(app, unusedAddons);
|
||||
if (Object.keys(unusedAddons).includes('localstorage')) await updateApp(app, { storageVolumeId: null, storageVolumePrefix: null }); // lose reference
|
||||
|
||||
// free unused ports
|
||||
const currentPorts = app.portBindings || {};
|
||||
// free unused ports. this is done after backup, so the app object is not in some inconsistent state should backup fail
|
||||
const newTcpPorts = updateConfig.manifest.tcpPorts || {};
|
||||
const newUdpPorts = updateConfig.manifest.udpPorts || {};
|
||||
const portBindings = { ...app.portBindings };
|
||||
|
||||
for (const portName of Object.keys(currentPorts)) {
|
||||
for (const portName of Object.keys(portBindings)) {
|
||||
if (newTcpPorts[portName] || newUdpPorts[portName]) continue; // port still in use
|
||||
|
||||
const [error] = await safe(apps.delPortBinding(currentPorts[portName], apps.PORT_TYPE_TCP));
|
||||
if (error && error.reason === BoxError.NOT_FOUND) debug('update: portbinding does not exist in database: %o', error);
|
||||
else if (error) throw error;
|
||||
|
||||
// also delete from app object for further processing (the db is updated in the next step)
|
||||
delete app.portBindings[portName];
|
||||
delete portBindings[portName];
|
||||
}
|
||||
|
||||
await updateApp(app, _.pick(updateConfig, 'manifest', 'appStoreId', 'memoryLimit')); // switch over to the new config
|
||||
// clear aliasDomains if needed based multiDomain change
|
||||
const aliasDomains = app.manifest.multiDomain && !updateConfig.manifest.multiDomain ? [] : app.aliasDomains;
|
||||
|
||||
// clear unused secondaryDomains
|
||||
const secondaryDomains = [ ...app.secondaryDomains ];
|
||||
const newHttpPorts = updateConfig.manifest.httpPorts || {};
|
||||
for (let i = secondaryDomains.length-1; i >= 0; i--) {
|
||||
const { environmentVariable } = secondaryDomains[i];
|
||||
if (environmentVariable in newHttpPorts) continue; // domain still in use
|
||||
secondaryDomains.splice(i, 1); // remove domain
|
||||
}
|
||||
|
||||
const values = {
|
||||
manifest: updateConfig.manifest,
|
||||
appStoreId: updateConfig.appStoreId,
|
||||
memoryLimit: updateConfig.memoryLimit,
|
||||
portBindings,
|
||||
// all domains have to be updated together
|
||||
subdomain: app.subdomain,
|
||||
domain: app.domain,
|
||||
aliasDomains,
|
||||
secondaryDomains,
|
||||
redirectDomains: app.redirectDomains
|
||||
};
|
||||
|
||||
await updateApp(app, values); // switch over to the new config
|
||||
|
||||
await progressCallback({ percent: 45, message: 'Downloading icon' });
|
||||
await downloadIcon(app);
|
||||
|
||||
Reference in New Issue
Block a user