mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2025-02-20 17:52:51 +00:00
Merge pull request #1897 from balena-os/patch-trigger-apply
Apply target state if loaded from file (apps.json)
This commit is contained in:
commit
2977d22b92
@ -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 });
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user