mirror of
https://github.com/balena-io/balena-cli.git
synced 2025-04-09 04:14:15 +00:00
Merge pull request #2398 from balena-io/reuse-getbootpartition
os configure, local configure: Reuse disk partition scanning logic
This commit is contained in:
commit
5574dc0318
@ -97,7 +97,7 @@ export default class LocalConfigureCmd extends Command {
|
||||
|
||||
readonly CONNECTIONS_FOLDER = '/system-connections';
|
||||
|
||||
getConfigurationSchema(bootPartition: number, connectionFileName?: string) {
|
||||
getConfigurationSchema(bootPartition?: number, connectionFileName?: string) {
|
||||
connectionFileName ??= 'resin-wifi';
|
||||
return {
|
||||
mapper: [
|
||||
@ -236,9 +236,9 @@ export default class LocalConfigureCmd extends Command {
|
||||
async prepareConnectionFile(target: string) {
|
||||
const _ = await import('lodash');
|
||||
const imagefs = await import('balena-image-fs');
|
||||
const helpers = await import('../../utils/helpers');
|
||||
const { getBootPartition } = await import('balena-config-json');
|
||||
|
||||
const bootPartition = await helpers.getBootPartition(target);
|
||||
const bootPartition = await getBootPartition(target);
|
||||
|
||||
const files = await imagefs.interact(target, bootPartition, async (_fs) => {
|
||||
return await promisify(_fs.readdir)(this.CONNECTIONS_FOLDER);
|
||||
|
@ -302,7 +302,8 @@ export default class OsConfigureCmd extends Command {
|
||||
}),
|
||||
);
|
||||
|
||||
const bootPartition = await helpers.getBootPartition(params.image);
|
||||
const { getBootPartition } = await import('balena-config-json');
|
||||
const bootPartition = await getBootPartition(params.image);
|
||||
|
||||
const imagefs = await import('balena-image-fs');
|
||||
|
||||
|
@ -201,43 +201,6 @@ function getApplication(
|
||||
) as Promise<ApplicationWithDeviceType>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the boot partition number of the given image.
|
||||
* @param imagePath Local filesystem path to a balenaOS image file
|
||||
*/
|
||||
export async function getBootPartition(imagePath: string): Promise<number> {
|
||||
const imagefs = await import('balena-image-fs');
|
||||
const filedisk = await import('file-disk');
|
||||
const partitioninfo = await import('partitioninfo');
|
||||
|
||||
const partitionNumber = await filedisk.withOpenFile(
|
||||
imagePath,
|
||||
'r',
|
||||
async (handle) => {
|
||||
const disk = new filedisk.FileDisk(handle, true, false, false);
|
||||
const { partitions } = await partitioninfo.getPartitions(disk, {
|
||||
includeExtended: false,
|
||||
getLogical: true,
|
||||
});
|
||||
for (const { index } of partitions) {
|
||||
try {
|
||||
return await imagefs.interact(disk, index, async (fs) => {
|
||||
const statAsync = promisify(fs.stat);
|
||||
const stats = await statAsync('/device-type.json');
|
||||
if (stats.isFile()) {
|
||||
return index;
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
// noop
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
return partitionNumber ?? 1;
|
||||
}
|
||||
|
||||
const second = 1000; // 1000 milliseconds
|
||||
const minute = 60 * second;
|
||||
export const delay = promisify(setTimeout);
|
||||
|
@ -234,7 +234,6 @@
|
||||
"express": "^4.13.3",
|
||||
"fast-boot2": "^1.1.0",
|
||||
"fast-levenshtein": "^3.0.0",
|
||||
"file-disk": "^8.0.1",
|
||||
"filenamify": "^4.3.0",
|
||||
"get-stdin": "^8.0.0",
|
||||
"glob": "^7.1.7",
|
||||
@ -259,7 +258,6 @@
|
||||
"node-unzip-2": "^0.2.8",
|
||||
"oclif": "^1.18.1",
|
||||
"open": "^7.1.0",
|
||||
"partitioninfo": "^6.0.2",
|
||||
"patch-package": "^6.4.7",
|
||||
"prettyjson": "^1.1.3",
|
||||
"progress-stream": "^2.0.0",
|
||||
|
Loading…
x
Reference in New Issue
Block a user