From 9d73b9a119fe7f80e557ca3397ec827eeb0f2083 Mon Sep 17 00:00:00 2001 From: David Hewitt Date: Fri, 13 Dec 2024 00:54:58 +0900 Subject: [PATCH] truncate percentages, add more tests --- src/Views/PartitioningView.vala | 68 +++++++++++++++++++++++++++++++++ src/Widgets/DiskBar.vala | 3 ++ 2 files changed, 71 insertions(+) diff --git a/src/Views/PartitioningView.vala b/src/Views/PartitioningView.vala index dcb61f971..1f2e9abe7 100644 --- a/src/Views/PartitioningView.vala +++ b/src/Views/PartitioningView.vala @@ -521,6 +521,74 @@ public class Installer.PartitioningView : AbstractInstallerView { partitions = {partitions_9, partitions_10} }; + var partitions_11 = InstallerDaemon.Partition () { + device_path = "/dev/nvme0n1p1", + filesystem = InstallerDaemon.FileSystem.FAT32, + start_sector = 4096, + end_sector = 542966, + sectors_used = InstallerDaemon.PartitionUsage () { + tag = 1, + value = 30312 + }, + current_lvm_volume_group = "" + }; + + var partitions_12 = InstallerDaemon.Partition () { + device_path = "/dev/nvme0n1p2", + filesystem = InstallerDaemon.FileSystem.LVM, + start_sector = 542968, + end_sector = 976769070, + sectors_used = InstallerDaemon.PartitionUsage () { + tag = 0, + value = 0 + }, + current_lvm_volume_group = "data" + }; + + physical_disks += InstallerDaemon.Disk () { + name = "Samsung SSD 970 EVO 500GB", + device_path = "/dev/nvme0n1", + sectors = 976773168, + sector_size = 512, + rotational = false, + removable = false, + partitions = {partitions_11, partitions_12} + }; + + var partitions_13 = InstallerDaemon.Partition () { + device_path = "/dev/dm-0", + filesystem = InstallerDaemon.FileSystem.EXT4, + start_sector = 0, + end_sector = 968220672, + sectors_used = InstallerDaemon.PartitionUsage () { + tag = 1, + value = 534569520 + }, + current_lvm_volume_group = "" + }; + + var partitions_14 = InstallerDaemon.Partition () { + device_path = "/dev/dm-1", + filesystem = InstallerDaemon.FileSystem.SWAP, + start_sector = 968220673, + end_sector = 976216065, + sectors_used = InstallerDaemon.PartitionUsage () { + tag = 0, + value = 0 + }, + current_lvm_volume_group = "" + }; + + logical_disks += InstallerDaemon.Disk () { + name = "LVM data", + device_path = "/dev/mapper/data", + sectors = 976226102, + sector_size = 512, + rotational = false, + removable = false, + partitions = {partitions_13, partitions_14} + }; + return InstallerDaemon.DiskInfo () { physical_disks = physical_disks, logical_disks = logical_disks diff --git a/src/Widgets/DiskBar.vala b/src/Widgets/DiskBar.vala index 29d1abc98..cd29ca842 100644 --- a/src/Widgets/DiskBar.vala +++ b/src/Widgets/DiskBar.vala @@ -147,6 +147,9 @@ public class Installer.DiskBar: Gtk.Box { } private void append_partition (Gtk.Widget widget, double percentage) { + // Truncate to 2 decimal places (round down), to ensure we don't go over 100% because of rounding errors + percentage = (int)(percentage * 100) / 100.0; + widget.set_parent (this); var layout_manager = ((Gtk.ConstraintLayout) get_layout_manager ());