mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2025-04-19 08:36:14 +00:00
Apply target state if loaded from file (apps.json)
Closes: #1895 Change-type: patch See: https://www.flowdock.com/app/rulemotion/r-supervisor/threads/tSN9BgLxkgJKapbQHQJr-R9yLPM Signed-off-by: 20k-ultra <3946250+20k-ultra@users.noreply.github.com>
This commit is contained in:
parent
ba395b2dbd
commit
b069d6b9d5
@ -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