From ab513cc021d90b1337bd79b58e6bb9e0c91e11d0 Mon Sep 17 00:00:00 2001 From: jaomaloy Date: Tue, 29 Aug 2023 16:55:39 +0800 Subject: [PATCH] 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 --- src/device-state.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/device-state.ts b/src/device-state.ts index 20d2d5ca..78c8e953 100644 --- a/src/device-state.ts +++ b/src/device-state.ts @@ -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);