From f7ac2728b89a6c75502c9c736c46a94ff386889b Mon Sep 17 00:00:00 2001 From: MauriceNino Date: Tue, 23 Jan 2024 11:12:59 +0100 Subject: [PATCH] fix: filter out autofs from sizes --- apps/docs/docs/configuration/storage.mdx | 2 +- apps/server/__TESTS__/dynamic-info.test.ts | 8 + apps/server/__TESTS__/static-info.test.ts | 5 + apps/server/__TESTS__/test-cases.ts | 340 +++++++++++++++++++++ apps/server/src/config.ts | 2 +- apps/server/src/data/storage/dynamic.ts | 11 +- 6 files changed, 357 insertions(+), 11 deletions(-) diff --git a/apps/docs/docs/configuration/storage.mdx b/apps/docs/docs/configuration/storage.mdx index 15ca573a6..876ba3c13 100644 --- a/apps/docs/docs/configuration/storage.mdx +++ b/apps/docs/docs/configuration/storage.mdx @@ -61,7 +61,7 @@ Please also create a [bug ticket](https://github.com/MauriceNino/dashdot/issues/ repository though, so that we can fix this problem for everyone. - type: `string (comma separated list)` -- default: `cifs,9p,fuse.rclone,fuse.mergerfs,nfs4,iso9660,fuse.shfs` +- default: `cifs,9p,fuse.rclone,fuse.mergerfs,nfs4,iso9660,fuse.shfs,autofs` ### `DASHDOT_FS_VIRTUAL_MOUNTS` diff --git a/apps/server/__TESTS__/dynamic-info.test.ts b/apps/server/__TESTS__/dynamic-info.test.ts index c7e158f01..2668603d7 100644 --- a/apps/server/__TESTS__/dynamic-info.test.ts +++ b/apps/server/__TESTS__/dynamic-info.test.ts @@ -14,6 +14,7 @@ import { TEST_CASE_23, TEST_CASE_24, TEST_CASE_25, + TEST_CASE_26, TestCase, } from './test-cases'; @@ -114,5 +115,12 @@ describe('Dynamic Info', () => { ).getMappedLayout(); expect(output).to.deep.equal(TEST_CASE_25.output); }); + it('Test Case 26', () => { + const output = new DynamicStorageMapper( + false, + ...toStorageInp(TEST_CASE_26) + ).getMappedLayout(); + expect(output).to.deep.equal(TEST_CASE_26.output); + }); }); }); diff --git a/apps/server/__TESTS__/static-info.test.ts b/apps/server/__TESTS__/static-info.test.ts index 35876b8e4..63fccdc33 100644 --- a/apps/server/__TESTS__/static-info.test.ts +++ b/apps/server/__TESTS__/static-info.test.ts @@ -14,6 +14,7 @@ import { TEST_CASE_23, TEST_CASE_24, TEST_CASE_25, + TEST_CASE_26, TestCase, } from './test-cases'; @@ -79,5 +80,9 @@ describe('Static Info', () => { const output = mapToStorageLayout(false, ...toStorageInp(TEST_CASE_25)); expect(output).to.deep.equal(TEST_CASE_25.layout); }); + it('Test Case 26', () => { + const output = mapToStorageLayout(false, ...toStorageInp(TEST_CASE_26)); + expect(output).to.deep.equal(TEST_CASE_26.layout); + }); }); }); diff --git a/apps/server/__TESTS__/test-cases.ts b/apps/server/__TESTS__/test-cases.ts index bb8045623..874a954c0 100644 --- a/apps/server/__TESTS__/test-cases.ts +++ b/apps/server/__TESTS__/test-cases.ts @@ -4322,3 +4322,343 @@ export const TEST_CASE_25 = { ], output: [42625843200, 762590027776], } as any as TestCase; + +// Test case from home server (with external disk) +export const TEST_CASE_26 = { + disks: [ + { + device: '/dev/sda', + type: 'HD', + name: 'Portable ', + vendor: 'Seagate', + size: 4000787029504, + bytesPerSector: null, + totalCylinders: null, + totalHeads: null, + totalSectors: null, + totalTracks: null, + tracksPerCylinder: null, + sectorsPerTrack: null, + firmwareRevision: '0712', + serialNum: '', + interfaceType: 'USB', + smartStatus: 'unknown', + temperature: null, + }, + { + device: '/dev/nvme0n1', + type: 'NVMe', + name: 'PCIe SSD ', + vendor: '', + size: 512110190592, + bytesPerSector: null, + totalCylinders: null, + totalHeads: null, + totalSectors: null, + totalTracks: null, + tracksPerCylinder: null, + sectorsPerTrack: null, + firmwareRevision: '', + serialNum: '7FBC07390DD900365059', + interfaceType: 'PCIe', + smartStatus: 'unknown', + temperature: null, + }, + ], + sizes: [ + { + fs: 'overlay', + type: 'overlay', + size: 105089261568, + used: 41106567168, + available: 58597208064, + use: 41.23, + mount: '/', + rw: false, + }, + { + fs: '/dev/mapper/ubuntu--vg-ubuntu--lv', + type: 'ext4', + size: 105089261568, + used: 41106567168, + available: 58597208064, + use: 41.23, + mount: '/mnt/host', + rw: true, + }, + { + fs: 'efivarfs', + type: 'efivarfs', + size: 196608, + used: 92160, + available: 99328, + use: 48.13, + mount: '/mnt/host/sys/firmware/efi/efivars', + rw: false, + }, + { + fs: '/dev/loop0', + type: 'squashfs', + size: 66584576, + used: 66584576, + available: 0, + use: 100, + mount: '/mnt/host/snap/core20/1974', + rw: false, + }, + { + fs: '/dev/loop1', + type: 'squashfs', + size: 67108864, + used: 67108864, + available: 0, + use: 100, + mount: '/mnt/host/snap/core20/2105', + rw: false, + }, + { + fs: '/dev/loop2', + type: 'squashfs', + size: 117440512, + used: 117440512, + available: 0, + use: 100, + mount: '/mnt/host/snap/lxd/24322', + rw: false, + }, + { + fs: '/dev/loop3', + type: 'squashfs', + size: 55967744, + used: 55967744, + available: 0, + use: 100, + mount: '/mnt/host/snap/snapd/19457', + rw: false, + }, + { + fs: '/dev/loop4', + type: 'squashfs', + size: 42467328, + used: 42467328, + available: 0, + use: 100, + mount: '/mnt/host/snap/snapd/20671', + rw: false, + }, + { + fs: '/dev/nvme0n1p2', + type: 'ext4', + size: 2040373248, + used: 284254208, + available: 1631969280, + use: 14.83, + mount: '/mnt/host/boot', + rw: false, + }, + { + fs: '/dev/nvme0n1p1', + type: 'vfat', + size: 1124999168, + used: 6369280, + available: 1118629888, + use: 0.57, + mount: '/mnt/host/boot/efi', + rw: false, + }, + { + fs: '/dev/sda1', + type: 'ext4', + size: 3936820690944, + used: 1772756307968, + available: 1964008259584, + use: 47.44, + mount: '/mnt/host/mnt/media', + rw: false, + }, + ], + blocks: [ + { + name: 'nvme0n1', + type: 'disk', + fsType: '', + mount: '', + size: 512110190592, + physical: 'SSD', + uuid: '', + label: '', + model: 'PCIe SSD', + serial: '7FBC07390DD900365059', + removable: false, + protocol: 'nvme', + group: '', + device: '/dev/nvme0n1', + }, + { + name: 'sda', + type: 'disk', + fsType: '', + mount: '', + size: 4000787029504, + physical: 'HDD', + uuid: '', + label: '', + model: 'Portable', + serial: '', + removable: false, + protocol: 'usb', + group: '', + device: '/dev/sda', + }, + { + name: 'loop0', + type: 'loop', + fsType: 'squashfs', + mount: '/mnt/host/snap/core20/1974', + size: 66531328, + physical: '', + uuid: '', + label: '', + model: '', + serial: '', + removable: false, + protocol: '', + group: '', + }, + { + name: 'loop1', + type: 'loop', + fsType: 'squashfs', + mount: '/mnt/host/snap/core20/2105', + size: 67014656, + physical: '', + uuid: '', + label: '', + model: '', + serial: '', + removable: false, + protocol: '', + group: '', + }, + { + name: 'loop2', + type: 'loop', + fsType: 'squashfs', + mount: '/mnt/host/snap/lxd/24322', + size: 117387264, + physical: '', + uuid: '', + label: '', + model: '', + serial: '', + removable: false, + protocol: '', + group: '', + }, + { + name: 'loop3', + type: 'loop', + fsType: 'squashfs', + mount: '/mnt/host/snap/snapd/19457', + size: 55844864, + physical: '', + uuid: '', + label: '', + model: '', + serial: '', + removable: false, + protocol: '', + group: '', + }, + { + name: 'loop4', + type: 'loop', + fsType: 'squashfs', + mount: '/mnt/host/snap/snapd/20671', + size: 42393600, + physical: '', + uuid: '', + label: '', + model: '', + serial: '', + removable: false, + protocol: '', + group: '', + }, + { + name: 'nvme0n1p1', + type: 'part', + fsType: 'vfat', + mount: '/mnt/host/boot/efi', + size: 1127219200, + physical: '', + uuid: '060E-D169', + label: '', + model: '', + serial: '', + removable: false, + protocol: 'nvme', + group: '', + device: '/dev/nvme0n1', + }, + { + name: 'nvme0n1p2', + type: 'part', + fsType: 'ext4', + mount: '/mnt/host/boot', + size: 2147483648, + physical: '', + uuid: 'dc87bf05-b396-43cb-a967-063d9a4c0466', + label: '', + model: '', + serial: '', + removable: false, + protocol: 'nvme', + group: '', + device: '/dev/nvme0n1', + }, + { + name: 'nvme0n1p3', + type: 'part', + fsType: 'LVM2_member', + mount: '', + size: 508833038336, + physical: '', + uuid: 'YVRqdg-O2wM-Xt1P-u9mk-wtWW-7G56-S5ZFKR', + label: '', + model: '', + serial: '', + removable: false, + protocol: 'nvme', + group: '', + device: '/dev/nvme0n1', + }, + { + name: 'sda1', + type: 'part', + fsType: 'ext4', + mount: '/mnt/host/mnt/media', + size: 4000786992128, + physical: '', + uuid: '4a38cee0-e843-46a9-bcc4-7fdd8b29a11a', + label: '', + model: '', + serial: '', + removable: false, + protocol: '', + group: '', + device: '/dev/sda', + }, + ], + layout: [ + { + disks: [{ brand: '', device: 'nvme0n1', type: 'NVMe' }], + size: 512110190592, + }, + { + disks: [{ brand: 'Seagate', device: 'sda', type: 'HD' }], + size: 4000787029504, + }, + ], + output: [41397190656, 1836722646528], +} as any as TestCase; diff --git a/apps/server/src/config.ts b/apps/server/src/config.ts index 9d82d3688..5ff41621d 100644 --- a/apps/server/src/config.ts +++ b/apps/server/src/config.ts @@ -35,7 +35,7 @@ export const CONFIG: Config = { fs_device_filter: lst(penv('FS_DEVICE_FILTER') ?? ''), fs_type_filter: lst( penv('FS_TYPE_FILTER') ?? - 'cifs,9p,fuse.rclone,fuse.mergerfs,nfs4,iso9660,fuse.shfs' + 'cifs,9p,fuse.rclone,fuse.mergerfs,nfs4,iso9660,fuse.shfs,autofs' ), fs_virtual_mounts: lst(penv('FS_VIRTUAL_MOUNTS') ?? ''), disable_integrations: penv('DISABLE_INTEGRATIONS') === 'true', diff --git a/apps/server/src/data/storage/dynamic.ts b/apps/server/src/data/storage/dynamic.ts index 460cd3fe8..fab65a27e 100644 --- a/apps/server/src/data/storage/dynamic.ts +++ b/apps/server/src/data/storage/dynamic.ts @@ -9,7 +9,6 @@ type Size = si.Systeminformation.FsSizeData; export class DynamicStorageMapper { private validSizes: Size[]; - private validBlocks: Block[]; constructor( private hostWin32: boolean, @@ -18,23 +17,17 @@ export class DynamicStorageMapper { private sizes: Size[] ) { this.validSizes = this.getValidSizes(); - this.validBlocks = this.getValidBlocks(); } // Setup local values private getValidSizes() { return this.sizes.filter( - ({ mount, type, rw }) => + ({ mount, type }) => (this.hostWin32 || mount.startsWith(fromHost('/'))) && - !CONFIG.fs_type_filter.includes(type) && - rw + !CONFIG.fs_type_filter.includes(type) ); } - private getValidBlocks() { - return this.blocks.filter(({ type }) => type === 'part' || type === 'disk'); - } - // Helpers private getBlocksForDisks(disks: StorageInfo[number]['disks']) { return this.blocks.filter(({ name, device }) =>