From c147945e10727a656acb72aa08ebf69a1ae5eff9 Mon Sep 17 00:00:00 2001 From: Michael Hudson-Doyle Date: Mon, 10 Jul 2023 16:07:18 +1200 Subject: [PATCH] handle in use partitions in server ui a bit --- subiquity/common/filesystem/actions.py | 12 +++++++++++- subiquity/common/filesystem/labels.py | 2 ++ subiquity/models/filesystem.py | 4 ++++ subiquity/ui/views/filesystem/filesystem.py | 4 +--- 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/subiquity/common/filesystem/actions.py b/subiquity/common/filesystem/actions.py index d8363fc59..ce4b96894 100644 --- a/subiquity/common/filesystem/actions.py +++ b/subiquity/common/filesystem/actions.py @@ -168,7 +168,13 @@ def _can_edit_generic(device): cdname=labels.label(cd)) -_can_edit.register(Partition, _can_edit_generic) +@_can_edit.register(Partition) +def _can_edit_partition(partition): + if partition._is_in_use: + return False + return _can_edit_generic(partition) + + _can_edit.register(LVM_LogicalVolume, _can_edit_generic) @@ -203,6 +209,8 @@ def _can_edit_vg(vg): @_can_reformat.register(Disk) @_can_reformat.register(Raid) def _can_reformat_device(device): + if device._has_in_use_partition: + return False if len(device._partitions) == 0: return False for p in device._partitions: @@ -288,6 +296,8 @@ def _can_delete_generic(device): @_can_delete.register(Partition) def _can_delete_partition(partition): + if partition._is_in_use: + return False if partition.device._has_preexisting_partition(): return _("Cannot delete a single partition from a device that " "already has partitions.") diff --git a/subiquity/common/filesystem/labels.py b/subiquity/common/filesystem/labels.py index 05b37f227..ff32c487b 100644 --- a/subiquity/common/filesystem/labels.py +++ b/subiquity/common/filesystem/labels.py @@ -233,6 +233,8 @@ def _usage_labels_generic(device, *, exclude_final_unused=False): if m: # A filesytem r.append(_("mounted at {path}").format(path=m.path)) + elif device._is_in_use: + r.append(_("in use")) elif not boot.is_esp(device): # A filesytem r.append(_("not mounted")) diff --git a/subiquity/models/filesystem.py b/subiquity/models/filesystem.py index f43255dc4..c2fb5a02a 100644 --- a/subiquity/models/filesystem.py +++ b/subiquity/models/filesystem.py @@ -580,6 +580,8 @@ def available(self): # with a fs that needs to be mounted and is not mounted if self._constructed_device is not None: return False + if self._is_in_use: + return False if self._fs is not None: return self._fs._available() from subiquity.common.filesystem.gaps import ( @@ -762,6 +764,8 @@ def __post_init__(self): def available(self): if self.flag in ['bios_grub', 'prep'] or self.grub_device: return False + if self._is_in_use: + return False if self._constructed_device is not None: return False if self._fs is None: diff --git a/subiquity/ui/views/filesystem/filesystem.py b/subiquity/ui/views/filesystem/filesystem.py index 7450725fb..0c9ab2a43 100644 --- a/subiquity/ui/views/filesystem/filesystem.py +++ b/subiquity/ui/views/filesystem/filesystem.py @@ -66,7 +66,6 @@ from subiquity.common.filesystem import boot, gaps, labels from subiquity.models.filesystem import ( humanize_size, - Disk, ) from .delete import ConfirmDeleteStretchy, ConfirmReformatStretchy @@ -377,9 +376,8 @@ def _action_menu_for_device(self, device): def refresh_model_inputs(self): devices = [ d for d in self.parent.model.all_devices() - if ((d.available() == self.show_available + if (d.available() == self.show_available or (not self.show_available and d.has_unavailable_partition())) - and (not isinstance(d, Disk) or not d._has_in_use_partition)) ] if len(devices) == 0: self._w = Padding.push_2(self._no_devices_content)