Skip to content

Commit

Permalink
fix(api): allow storage widget to work with win32 from host
Browse files Browse the repository at this point in the history
  • Loading branch information
MauriceNino committed Feb 1, 2023
1 parent 56ab189 commit e5b9670
Show file tree
Hide file tree
Showing 4 changed files with 198 additions and 6 deletions.
23 changes: 23 additions & 0 deletions apps/api/__TESTS__/dynamic-info.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
TEST_CASE_12,
TEST_CASE_13,
TEST_CASE_14,
TEST_CASE_15,
TEST_CASE_2,
TEST_CASE_3,
TEST_CASE_4,
Expand All @@ -30,88 +31,110 @@ describe('Dynamic Info', () => {
describe('Storage', () => {
it('Test Case 1', () => {
const output = new DynamicStorageMapper(
false,
...toStorageInp(TEST_CASE_1)
).getMappedLayout();
expect(output).to.deep.equal(TEST_CASE_1.output);
});
it('Test Case 2', () => {
const output = new DynamicStorageMapper(
false,
...toStorageInp(TEST_CASE_2)
).getMappedLayout();
expect(output).to.deep.equal(TEST_CASE_2.output);
});
it('Test Case 3', () => {
const output = new DynamicStorageMapper(
false,
...toStorageInp(TEST_CASE_3)
).getMappedLayout();
expect(output).to.deep.equal(TEST_CASE_3.output);
});
it('Test Case 4', () => {
const output = new DynamicStorageMapper(
false,
...toStorageInp(TEST_CASE_4)
).getMappedLayout();
expect(output).to.deep.equal(TEST_CASE_4.output);
});
it('Test Case 5', () => {
const output = new DynamicStorageMapper(
false,
...toStorageInp(TEST_CASE_5)
).getMappedLayout();
expect(output).to.deep.equal(TEST_CASE_5.output);
});
it('Test Case 6', () => {
const output = new DynamicStorageMapper(
false,
...toStorageInp(TEST_CASE_6)
).getMappedLayout();
expect(output).to.deep.equal(TEST_CASE_6.output);
});
it('Test Case 7', () => {
const output = new DynamicStorageMapper(
false,
...toStorageInp(TEST_CASE_7)
).getMappedLayout();
expect(output).to.deep.equal(TEST_CASE_7.output);
});
it('Test Case 8', () => {
const output = new DynamicStorageMapper(
false,
...toStorageInp(TEST_CASE_8)
).getMappedLayout();
expect(output).to.deep.equal(TEST_CASE_8.output);
});
it('Test Case 9', () => {
const output = new DynamicStorageMapper(
false,
...toStorageInp(TEST_CASE_9)
).getMappedLayout();
expect(output).to.deep.equal(TEST_CASE_9.output);
});
it('Test Case 10', () => {
const output = new DynamicStorageMapper(
false,
...toStorageInp(TEST_CASE_10)
).getMappedLayout();
expect(output).to.deep.equal(TEST_CASE_10.output);
});
it('Test Case 11', () => {
const output = new DynamicStorageMapper(
false,
...toStorageInp(TEST_CASE_11)
).getMappedLayout();
expect(output).to.deep.equal(TEST_CASE_11.output);
});
it('Test Case 12', () => {
const output = new DynamicStorageMapper(
false,
...toStorageInp(TEST_CASE_12)
).getMappedLayout();
expect(output).to.deep.equal(TEST_CASE_12.output);
});
it('Test Case 13', () => {
CONFIG.running_in_docker = false;
const output = new DynamicStorageMapper(
false,
...toStorageInp(TEST_CASE_13)
).getMappedLayout();
expect(output).to.deep.equal(TEST_CASE_13.output);
});
it('Test Case 14', () => {
const output = new DynamicStorageMapper(
false,
...toStorageInp(TEST_CASE_14)
).getMappedLayout();
expect(output).to.deep.equal(TEST_CASE_14.output);
});
it('Test Case 15', () => {
CONFIG.running_in_docker = false;
const output = new DynamicStorageMapper(
true,
...toStorageInp(TEST_CASE_15)
).getMappedLayout();
expect(output).to.deep.equal(TEST_CASE_15.output);
});
});
});
6 changes: 6 additions & 0 deletions apps/api/__TESTS__/static-info.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
TEST_CASE_12,
TEST_CASE_13,
TEST_CASE_14,
TEST_CASE_15,
TEST_CASE_2,
TEST_CASE_3,
TEST_CASE_4,
Expand Down Expand Up @@ -85,5 +86,10 @@ describe('Static Info', () => {
const output = mapToStorageLayout(...toStorageInp(TEST_CASE_14));
expect(output).to.deep.equal(TEST_CASE_14.layout);
});
it('Test Case 15', () => {
CONFIG.running_in_docker = false;
const output = mapToStorageLayout(...toStorageInp(TEST_CASE_15));
expect(output).to.deep.equal(TEST_CASE_15.layout);
});
});
});
157 changes: 157 additions & 0 deletions apps/api/__TESTS__/test-cases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5151,3 +5151,160 @@ export const TEST_CASE_14 = {
],
output: { layout: [{ load: 322783203328 }, { load: 0 }] },
} as any as TestCase;

export const TEST_CASE_15 = {
disks: [
{
device: '\\\\.\\PHYSICALDRIVE0',
type: 'HD',
name: 'ST8000DM004-2CX188',
vendor: 'Seagate',
size: 8001560609280,
bytesPerSector: 512,
totalCylinders: 972801,
totalHeads: 255,
totalSectors: 15628048065,
totalTracks: 248064255,
tracksPerCylinder: 255,
sectorsPerTrack: 63,
firmwareRevision: '0001',
serialNum: 'ZCT35GKB',
interfaceType: 'SATA',
smartStatus: 'Ok',
temperature: null,
},
{
device: '\\\\.\\PHYSICALDRIVE1',
type: 'SSD',
name: 'TS256GSSD370',
vendor: '',
size: 256052966400,
bytesPerSector: 512,
totalCylinders: 31130,
totalHeads: 255,
totalSectors: 500103450,
totalTracks: 7938150,
tracksPerCylinder: 255,
sectorsPerTrack: 63,
firmwareRevision: '20140516',
serialNum: 'B669542640',
interfaceType: 'SATA',
smartStatus: 'Ok',
temperature: null,
},
],
sizes: [
{
fs: 'A:',
type: 'NTFS',
size: 537915392,
used: 449269760,
available: 88645632,
use: 83.52,
mount: 'A:',
rw: true,
},
{
fs: 'C:',
type: 'NTFS',
size: 254874218496,
used: 225739960320,
available: 29134258176,
use: 88.57,
mount: 'C:',
rw: true,
},
{
fs: 'E:',
type: 'NTFS',
size: 8001545039872,
used: 7547945865216,
available: 453599174656,
use: 94.33,
mount: 'E:',
rw: true,
},
],
blocks: [
{
name: 'A:',
identifier: 'A:',
type: 'disk',
fsType: 'ntfs',
mount: 'A:',
size: '537915392',
physical: 'Local',
uuid: '860E0ABE',
label: '',
model: '',
serial: '860E0ABE',
removable: false,
protocol: '',
group: '',
device: '\\\\.\\PHYSICALDRIVE1',
},
{
name: 'C:',
identifier: 'C:',
type: 'disk',
fsType: 'ntfs',
mount: 'C:',
size: '254874218496',
physical: 'Local',
uuid: '02712ECC',
label: '',
model: '',
serial: '02712ECC',
removable: false,
protocol: '',
group: '',
device: '\\\\.\\PHYSICALDRIVE1',
},
{
name: 'D:',
identifier: 'D:',
type: 'disk',
fsType: 'cdfs',
mount: 'D:',
size: '0',
physical: 'CD/DVD',
uuid: '00B500CD',
label: 'Audio CD',
model: '',
serial: '00B500CD',
removable: false,
protocol: '',
group: '',
device: '',
},
{
name: 'E:',
identifier: 'E:',
type: 'disk',
fsType: 'ntfs',
mount: 'E:',
size: '8001545039872',
physical: 'Local',
uuid: '2EF6177C',
label: 'Media',
model: '',
serial: '2EF6177C',
removable: false,
protocol: '',
group: '',
device: '\\\\.\\PHYSICALDRIVE0',
},
],
layout: [
{ brand: '', device: 'A:', size: 256052966400, type: 'SSD' },
{ brand: '', device: 'C:', size: 256052966400, type: 'SSD' },
{ brand: 'Seagate', device: 'E:', size: 8001560609280, type: 'HD' },
],
output: {
layout: [
{ load: 449269760 },
{ load: 225739960320 },
{ load: 7547945865216 },
],
},
} as any as TestCase;
18 changes: 12 additions & 6 deletions apps/api/src/data/storage/dynamic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export class DynamicStorageMapper {
private hasExplicitHost = false;

constructor(
private hostWin32: boolean,
private layout: StorageInfo['layout'],
private blocks: Block[],
private sizes: Size[]
Expand All @@ -28,7 +29,8 @@ export class DynamicStorageMapper {
private getValidSizes() {
return this.sizes.filter(
({ mount, type }) =>
mount.startsWith(fromHost('/')) && !CONFIG.fs_type_filter.includes(type)
(this.hostWin32 || mount.startsWith(fromHost('/'))) &&
!CONFIG.fs_type_filter.includes(type)
);
}

Expand All @@ -52,15 +54,18 @@ export class DynamicStorageMapper {
}

private isRootMount(mount: string) {
return mount === fromHost('/') || mount.startsWith(fromHost('/boot/'));
return (
!this.hostWin32 &&
(mount === fromHost('/') || mount.startsWith(fromHost('/boot/')))
);
}

private blocksHaveMounts(deviceBlocks: Block[]) {
return deviceBlocks.some(
({ mount }) =>
mount != null &&
mount.startsWith(fromHost('/')) &&
this.validSizes.some(s => s.mount === mount)
this.validSizes.some(s => s.mount === mount) &&
(this.hostWin32 || mount.startsWith(fromHost('/')))
);
}

Expand Down Expand Up @@ -149,11 +154,12 @@ export class DynamicStorageMapper {
}

export default async (): Promise<StorageLoad> => {
const storageLayout = getStaticServerInfo().storage.layout;
const svInfo = getStaticServerInfo();
const [blocks, sizes] = await Promise.all([si.blockDevices(), si.fsSize()]);

return new DynamicStorageMapper(
storageLayout,
svInfo.os.platform === 'win32',
svInfo.storage.layout,
blocks,
sizes
).getMappedLayout();
Expand Down

0 comments on commit e5b9670

Please sign in to comment.