Merge pull request #1897 from balena-os/patch-trigger-apply

Apply target state if loaded from file (apps.json)
This commit is contained in:
bulldozer-balena[bot] 2022-03-14 23:06:52 +00:00 committed by GitHub
commit 2977d22b92
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 6 deletions

View File

@ -415,15 +415,16 @@ export async function loadInitialState() {
update_downloaded: false,
});
let loadedFromFile = false;
if (!conf.provisioned || !conf.targetStateSet) {
await loadTargetFromFile(constants.appsJsonPath);
loadedFromFile = await loadTargetFromFile(constants.appsJsonPath);
} else {
log.debug('Skipping preloading');
}
// Only trigger initial target if we have received a target
// from the cloud at some point
if (conf.targetStateSet) {
// Only apply target if we have received a target
// from the cloud or loaded from file
if (conf.targetStateSet || loadedFromFile) {
triggerApplyTarget({ initial: true });
}
}

View File

@ -19,7 +19,7 @@ export function appsJsonBackup(appsPath: string) {
return `${appsPath}.preloaded`;
}
export async function loadTargetFromFile(appsPath: string): Promise<void> {
export async function loadTargetFromFile(appsPath: string): Promise<boolean> {
log.info('Attempting to load any preloaded applications');
try {
const content = await fs.readFile(appsPath, 'utf8');
@ -43,7 +43,7 @@ export async function loadTargetFromFile(appsPath: string): Promise<void> {
let appToPin: string | undefined;
if (_.isEmpty(preloadState)) {
return;
return false;
}
const imgs: Image[] = [];
@ -100,6 +100,7 @@ export async function loadTargetFromFile(appsPath: string): Promise<void> {
});
}
}
return true;
} catch (e) {
// Ensure that this is actually a file, and not an empty path
// It can be an empty path because if the file does not exist
@ -131,4 +132,5 @@ export async function loadTargetFromFile(appsPath: string): Promise<void> {
);
}
}
return false;
}