From a2164815d80d1da77b8851ec08a74de195b6b6f2 Mon Sep 17 00:00:00 2001 From: Alexis Svinartchouk Date: Wed, 1 Apr 2020 12:48:27 +0200 Subject: [PATCH] BlockDevice constructor takes an options argument Change-type: major --- lib/scanner/adapters/block-device.ts | 12 ++++++------ lib/source-destination/block-device.ts | 25 ++++++++++++++++++------- tests/tester.ts | 7 ++++++- 3 files changed, 30 insertions(+), 14 deletions(-) diff --git a/lib/scanner/adapters/block-device.ts b/lib/scanner/adapters/block-device.ts index 69fa8ea9..e8df8d15 100644 --- a/lib/scanner/adapters/block-device.ts +++ b/lib/scanner/adapters/block-device.ts @@ -115,12 +115,12 @@ export class BlockDeviceAdapter extends Adapter { } for (const added of difference(newDevices, oldDevices)) { const drive = drives.get(added); - const blockDevice = new BlockDevice( - drive!, - this.unmountOnSuccess, - this.oWrite, - this.oDirect, - ); + const blockDevice = new BlockDevice({ + drive: drive!, + unmountOnSuccess: this.unmountOnSuccess, + write: this.oWrite, + direct: this.oDirect, + }); this.emit('attach', blockDevice); this.drives.set(added, blockDevice); } diff --git a/lib/source-destination/block-device.ts b/lib/source-destination/block-device.ts index b0df5e26..eb650e9d 100644 --- a/lib/source-destination/block-device.ts +++ b/lib/source-destination/block-device.ts @@ -43,16 +43,27 @@ const UNMOUNT_ON_SUCCESS_TIMEOUT_MS = 2000; const WIN32_FIRST_BYTES_TO_KEEP = 64 * 1024; export class BlockDevice extends File implements AdapterSourceDestination { + private drive: DrivelistDrive; + private unmountOnSuccess: boolean; + public readonly oDirect: boolean; public emitsProgress = false; public readonly alignment: number; - constructor( - private drive: DrivelistDrive, - private unmountOnSuccess = false, - oWrite = false, - public readonly oDirect = true, - ) { - super({ path: drive.raw, write: oWrite }); + constructor({ + drive, + unmountOnSuccess = false, + write = false, + direct = true, + }: { + drive: DrivelistDrive; + unmountOnSuccess?: boolean; + write?: boolean; + direct?: boolean; + }) { + super({ path: drive.raw, write }); + this.drive = drive; + this.unmountOnSuccess = unmountOnSuccess; + this.oDirect = direct; this.alignment = drive.blockSize || DEFAULT_ALIGNMENT; } diff --git a/tests/tester.ts b/tests/tester.ts index d0593763..78bcb8f5 100644 --- a/tests/tester.ts +++ b/tests/tester.ts @@ -67,7 +67,12 @@ export async function blockDeviceFromFile( isVirtual: false, logicalBlockSize: 512, }; - return new FakeBlockDevice(drive, false, true, false); + return new FakeBlockDevice({ + drive, + unmountOnSuccess: false, + write: true, + direct: false, + }); } export async function testImageNoIt(