From fcea91bfb6cbcc32117d7242460f1e58476339ac Mon Sep 17 00:00:00 2001 From: Paulo Castro Date: Fri, 26 Nov 2021 23:13:31 +0000 Subject: [PATCH] os configure, local configure: Reuse disk partition scanning logic Change-type: patch --- lib/commands/local/configure.ts | 6 +++--- lib/commands/os/configure.ts | 3 ++- lib/utils/helpers.ts | 37 --------------------------------- package.json | 2 -- 4 files changed, 5 insertions(+), 43 deletions(-) diff --git a/lib/commands/local/configure.ts b/lib/commands/local/configure.ts index 2f8203e3..b8e596a2 100644 --- a/lib/commands/local/configure.ts +++ b/lib/commands/local/configure.ts @@ -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); diff --git a/lib/commands/os/configure.ts b/lib/commands/os/configure.ts index 7d5000f0..94cc6257 100644 --- a/lib/commands/os/configure.ts +++ b/lib/commands/os/configure.ts @@ -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'); diff --git a/lib/utils/helpers.ts b/lib/utils/helpers.ts index 135240b6..544070d4 100644 --- a/lib/utils/helpers.ts +++ b/lib/utils/helpers.ts @@ -201,43 +201,6 @@ function getApplication( ) as Promise; } -/** - * 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 { - 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); diff --git a/package.json b/package.json index fdd3d5de..5fe3b4e7 100644 --- a/package.json +++ b/package.json @@ -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",