Dump target-state to hostOS tmp dir

This change is mainly for the hostOS
to know if update locks should be ignored
when updating to a newer version.

Change-type: patch
Signed-off-by: jaomaloy <jao.maloy@balena.io>
This commit is contained in:
jaomaloy 2023-08-29 16:55:39 +08:00 committed by jaomaloy
parent 1e54d66ffe
commit ab513cc021

View File

@ -43,6 +43,12 @@ import type {
CompositionStepT,
CompositionStepAction,
} from './compose/composition-steps';
import * as fsUtils from './lib/fs-utils';
import { pathOnRoot } from './lib/host-utils';
const TARGET_STATE_CONFIG_DUMP = pathOnRoot(
'/tmp/balena-supervisor/target-state-config',
);
function parseTargetState(state: unknown): TargetState {
const res = TargetState.decode(state);
@ -331,6 +337,11 @@ export async function setTarget(target: TargetState, localSource?: boolean) {
const localTarget = target[uuid];
await fsUtils.writeAndSyncFile(
TARGET_STATE_CONFIG_DUMP,
JSON.stringify(localTarget.config),
);
await usingWriteLockTarget(async () => {
await db.transaction(async (trx) => {
await config.set({ name: localTarget.name }, trx);