Merge pull request #2192 from balena-os/jaomaloy/dump-target-state

Dump target-state to hostOS tmp dir
This commit is contained in:
Jao Maloy 2023-09-15 09:56:48 +08:00 committed by GitHub
commit 8262cfac28
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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);