Skip to content

Commit

Permalink
BlockDevice constructor takes an options argument
Browse files Browse the repository at this point in the history
Change-type: major
  • Loading branch information
zvin committed Apr 1, 2020
1 parent e9fb683 commit a216481
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 14 deletions.
12 changes: 6 additions & 6 deletions lib/scanner/adapters/block-device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
25 changes: 18 additions & 7 deletions lib/source-destination/block-device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
7 changes: 6 additions & 1 deletion tests/tester.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit a216481

Please sign in to comment.