Skip to content

Commit

Permalink
os configure: Given the found boot partition precedence over the devi…
Browse files Browse the repository at this point in the history
…ce-type.json contents

Change-type: minor
  • Loading branch information
thgreasi committed Dec 19, 2024
1 parent 5ca8c6c commit b64723f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
18 changes: 18 additions & 0 deletions src/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand Down
5 changes: 4 additions & 1 deletion tests/commands/os/configure.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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...
Expand Down

0 comments on commit b64723f

Please sign in to comment.