From 2860535c45a3cdb592a8d3df74a5e5d06632d1c0 Mon Sep 17 00:00:00 2001 From: Pagan Gazzard Date: Thu, 12 Mar 2020 20:50:30 +0000 Subject: [PATCH] Fix `balena local flash` Change-type: patch --- lib/actions/local/flash.ts | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/actions/local/flash.ts b/lib/actions/local/flash.ts index 74f62aa2..66c90ee5 100644 --- a/lib/actions/local/flash.ts +++ b/lib/actions/local/flash.ts @@ -22,7 +22,22 @@ import { getChalk, getVisuals } from '../../utils/lazy'; async function getDrive(options: { drive?: string; }): Promise { - return options.drive || getVisuals().drive('Select a drive'); + const drive = options.drive || (await getVisuals().drive('Select a drive')); + + const sdk = await import('etcher-sdk'); + + const adapter = new sdk.scanner.adapters.BlockDeviceAdapter(() => false); + const scanner = new sdk.scanner.Scanner([adapter]); + await scanner.start(); + try { + const d = scanner.getBy('device', drive); + if (d === undefined || !(d instanceof sdk.sourceDestination.BlockDevice)) { + throw new Error(`Drive not found: ${options.drive}`); + } + return d; + } finally { + scanner.stop(); + } } export const flash: CommandDefinition<