mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2024-12-19 13:47:54 +00:00
Only migrate apps.json on preload after target has been set
Change-type: patch Signed-off-by: Christina Wang <christina@balena.io> Signed-off-by: Felipe Lalanne <felipe@balena.io>
This commit is contained in:
parent
564ff186e7
commit
95bf4718d6
@ -26,6 +26,26 @@ export function appsJsonBackup(appsPath: string) {
|
||||
return `${appsPath}.preloaded`;
|
||||
}
|
||||
|
||||
async function migrateAppsJson(appsPath: string) {
|
||||
const targetPath = appsJsonBackup(appsPath);
|
||||
if (!(await fsUtils.exists(targetPath))) {
|
||||
// Try to rename the path so the preload target state won't
|
||||
// be used again if the database gets deleted for any reason.
|
||||
// If the target file already exists or something fails, just debug
|
||||
// the failure.
|
||||
await fsUtils
|
||||
.safeRename(appsPath, targetPath)
|
||||
.then(() => fsUtils.writeFileAtomic(appsPath, '{}'))
|
||||
.then(() => log.debug(`Migrated existing apps.json`))
|
||||
.catch((e) =>
|
||||
log.debug(
|
||||
`Continuing without migrating apps.json because of`,
|
||||
e.message,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export async function loadTargetFromFile(appsPath: string): Promise<boolean> {
|
||||
log.info('Attempting to load any preloaded applications');
|
||||
try {
|
||||
@ -119,6 +139,7 @@ export async function loadTargetFromFile(appsPath: string): Promise<boolean> {
|
||||
};
|
||||
|
||||
await deviceState.setTarget(localState);
|
||||
await migrateAppsJson(appsPath);
|
||||
log.success('Preloading complete');
|
||||
if (preloadState.pinDevice) {
|
||||
// Multi-app warning!
|
||||
@ -152,24 +173,6 @@ export async function loadTargetFromFile(appsPath: string): Promise<boolean> {
|
||||
error: e,
|
||||
});
|
||||
}
|
||||
} finally {
|
||||
const targetPath = appsJsonBackup(appsPath);
|
||||
if (!(await fsUtils.exists(targetPath))) {
|
||||
// Try to rename the path so the preload target state won't
|
||||
// be used again if the database gets deleted for any reason.
|
||||
// If the target file already exists or something fails, just debug
|
||||
// the failure.
|
||||
await fsUtils
|
||||
.safeRename(appsPath, targetPath)
|
||||
.then(() => fsUtils.writeFileAtomic(appsPath, '{}'))
|
||||
.then(() => log.debug(`Migrated existing apps.json`))
|
||||
.catch((e) =>
|
||||
log.debug(
|
||||
`Continuing without migrating apps.json because of`,
|
||||
e.message,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user