From b64723faf5122dbb7f67f0e4b803c159dbc0db9f Mon Sep 17 00:00:00 2001 From: Thodoris Greasidis Date: Fri, 20 Dec 2024 00:13:12 +0200 Subject: [PATCH] os configure: Given the found boot partition precedence over the device-type.json contents Change-type: minor --- src/utils/helpers.ts | 18 ++++++++++++++++++ tests/commands/os/configure.spec.ts | 5 ++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/utils/helpers.ts b/src/utils/helpers.ts index 80b94efa5..3efe3d240 100644 --- a/src/utils/helpers.ts +++ b/src/utils/helpers.ts @@ -110,6 +110,24 @@ export async function getManifest( const init = await import('balena-device-init'); const sdk = getBalenaSdk(); const manifest = await init.getImageManifest(image); + if (manifest != null) { + const config = manifest.configuration?.config; + if (config?.partition != null) { + const { getBootPartition } = await import('balena-config-json'); + // Overwrite the deprecated & no longer updated partition number on the device-type.json + // properties, with the boot partition number that we found by inspecting the image. + if (typeof config.partition === 'number') { + config.partition = await getBootPartition(image); + } else if (config.partition.primary != null) { + config.partition.primary = await getBootPartition(image); + } + } + } else { + // TODO: Change this in the next major to throw, after confirming that this works for all supported OS versions. + console.error( + `[warn] Error while finding a device-type.json on the provided image path. Attempting to fetch from the API.`, + ); + } if ( manifest != null && manifest.slug !== deviceType && diff --git a/tests/commands/os/configure.spec.ts b/tests/commands/os/configure.spec.ts index 2e38a3f49..0a5f56c12 100644 --- a/tests/commands/os/configure.spec.ts +++ b/tests/commands/os/configure.spec.ts @@ -74,7 +74,10 @@ if (process.platform !== 'win32') { [warn] Assuming default boot partition number '1'. [warn] "${tmpPath}": [warn] Could not find a previous "/config.json" file in partition '1'. - [warn] Proceeding anyway, but this is unexpected.`.split('\n'), + [warn] Proceeding anyway, but this is unexpected. + [warn] Error while finding a device-type.json on the provided image path. Attempting to fetch from the API.`.split( + '\n', + ), ); // confirm the image contains a config.json...