Skip to content

Commit be1e437

Browse files
committed
Fix manual partitioning device wipe status
1 parent 4b07f8a commit be1e437

File tree

2 files changed

+56
-41
lines changed

2 files changed

+56
-41
lines changed

archinstall/lib/disk/partitioning_menu.py

Lines changed: 54 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,20 @@
55
from typing import TYPE_CHECKING, override
66

77
from archinstall.lib.models.device_model import (
8-
BDevice,
98
BtrfsMountOption,
9+
DeviceModification,
1010
FilesystemType,
1111
ModificationStatus,
1212
PartitionFlag,
1313
PartitionModification,
14+
PartitionTable,
1415
PartitionType,
1516
SectorSize,
1617
Size,
1718
Unit,
1819
)
1920
from archinstall.tui import Alignment, EditMenu, FrameProperties, MenuItem, MenuItemGroup, Orientation, ResultType, SelectMenu
2021

21-
from ..hardware import SysInfo
2222
from ..menu import ListManager
2323
from ..output import FormattedOutput
2424
from ..utils.util import prompt_dir
@@ -75,10 +75,17 @@ def table_data(self) -> dict[str, str]:
7575

7676

7777
class PartitioningList(ListManager):
78-
def __init__(self, prompt: str, device: BDevice, device_partitions: list[PartitionModification]):
78+
def __init__(
79+
self,
80+
device_mod: DeviceModification,
81+
partition_table: PartitionTable
82+
) -> None:
83+
device = device_mod.device
84+
7985
self._device = device
86+
self._wipe = device_mod.wipe
8087
self._buffer = Size(1, Unit.MiB, device.device_info.sector_size)
81-
self._using_gpt = SysInfo.has_uefi()
88+
self._using_gpt = device_mod.using_gpt(partition_table)
8289

8390
self._actions = {
8491
'suggest_partition_layout': str(_('Suggest partition layout')),
@@ -93,14 +100,32 @@ def __init__(self, prompt: str, device: BDevice, device_partitions: list[Partiti
93100
'delete_partition': str(_('Delete partition'))
94101
}
95102

103+
device_partitions = []
104+
105+
if not device_mod.partitions:
106+
# we'll display the existing partitions of the device
107+
for partition in device.partition_infos:
108+
device_partitions.append(
109+
PartitionModification.from_existing_partition(partition)
110+
)
111+
else:
112+
device_partitions = device_mod.partitions
113+
114+
prompt = str(_('Partition management: {}')).format(device.device_info.path) + '\n'
115+
prompt += str(_('Total length: {}')).format(device.device_info.total_size.format_size(Unit.MiB))
116+
self._info = prompt + '\n'
117+
96118
display_actions = list(self._actions.values())
97119
super().__init__(
98120
self.as_segments(device_partitions),
99121
display_actions[:1],
100122
display_actions[2:],
101-
prompt
123+
self._info + self.wipe_str()
102124
)
103125

126+
def wipe_str(self) -> str:
127+
return '{}: {}'.format(str(_('Wipe')), self._wipe)
128+
104129
def as_segments(self, device_partitions: list[PartitionModification]) -> list[DiskSegment]:
105130
end = self._device.device_info.total_size
106131

@@ -163,10 +188,10 @@ def get_part_mods(disk_segments: list[DiskSegment]) -> list[PartitionModificatio
163188
if isinstance(s.segment, PartitionModification)
164189
]
165190

166-
@override
167-
def run(self) -> list[PartitionModification]:
191+
def get_device_mod(self) -> DeviceModification:
168192
disk_segments = super().run()
169-
return self.get_part_mods(disk_segments)
193+
partitions = self.get_part_mods(disk_segments)
194+
return DeviceModification(self._device, self._wipe, partitions)
170195

171196
@override
172197
def _run_actions_on_entry(self, entry: DiskSegment) -> None:
@@ -241,9 +266,11 @@ def handle_action(
241266
match action_key:
242267
case 'suggest_partition_layout':
243268
part_mods = self.get_part_mods(data)
244-
new_partitions = self._suggest_partition_layout(part_mods)
245-
if len(new_partitions) > 0:
246-
data = self.as_segments(new_partitions)
269+
device_mod = self._suggest_partition_layout(part_mods)
270+
if device_mod and device_mod.partitions:
271+
data = self.as_segments(device_mod.partitions)
272+
self._wipe = device_mod.wipe
273+
self._prompt = self._info + self.wipe_str()
247274
case 'remove_added_partitions':
248275
if self._reset_confirmation():
249276
data = [
@@ -506,43 +533,32 @@ def _reset_confirmation(self) -> bool:
506533

507534
return result.item() == MenuItem.yes()
508535

509-
def _suggest_partition_layout(self, data: list[PartitionModification]) -> list[PartitionModification]:
536+
def _suggest_partition_layout(
537+
self,
538+
data: list[PartitionModification]
539+
) -> DeviceModification | None:
510540
# if modifications have been done already, inform the user
511541
# that this operation will erase those modifications
512542
if any([not entry.exists() for entry in data]):
513543
if not self._reset_confirmation():
514-
return []
544+
return None
515545

516546
from ..interactions.disk_conf import suggest_single_disk_layout
517547

518-
device_modification = suggest_single_disk_layout(self._device)
519-
return device_modification.partitions
548+
return suggest_single_disk_layout(self._device)
520549

521550

522551
def manual_partitioning(
523-
device: BDevice,
524-
prompt: str = '',
525-
preset: list[PartitionModification] = []
526-
) -> list[PartitionModification]:
527-
if not prompt:
528-
prompt = str(_('Partition management: {}')).format(device.device_info.path) + '\n'
529-
prompt += str(_('Total length: {}')).format(device.device_info.total_size.format_size(Unit.MiB))
530-
531-
manual_preset = []
532-
533-
if not preset:
534-
# we'll display the existing partitions of the device
535-
for partition in device.partition_infos:
536-
manual_preset.append(
537-
PartitionModification.from_existing_partition(partition)
538-
)
539-
else:
540-
manual_preset = preset
541-
542-
menu_list = PartitioningList(prompt, device, manual_preset)
543-
partitions: list[PartitionModification] = menu_list.run()
552+
device_mod: DeviceModification,
553+
partition_table: PartitionTable
554+
) -> DeviceModification | None:
555+
menu_list = PartitioningList(device_mod, partition_table)
556+
mod = menu_list.get_device_mod()
544557

545558
if menu_list.is_last_choice_cancel():
546-
return preset
559+
return device_mod
560+
561+
if mod.partitions:
562+
return mod
547563

548-
return partitions
564+
return None

archinstall/lib/interactions/disk_conf.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,8 @@ def _manual_partitioning(
116116
if not mod:
117117
mod = DeviceModification(device, wipe=False)
118118

119-
if partitions := manual_partitioning(device, preset=mod.partitions):
120-
mod.partitions = partitions
121-
modifications.append(mod)
119+
if device_mod := manual_partitioning(mod, device_handler.partition_table):
120+
modifications.append(device_mod)
122121

123122
return modifications
124123

0 commit comments

Comments
 (0)