Skip to content

Commit

Permalink
handle in use partitions in server ui a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
mwhudson committed Jul 19, 2023
1 parent 9d050d4 commit c147945
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
12 changes: 11 additions & 1 deletion subiquity/common/filesystem/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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.")
Expand Down
2 changes: 2 additions & 0 deletions subiquity/common/filesystem/labels.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
4 changes: 4 additions & 0 deletions subiquity/models/filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 1 addition & 3 deletions subiquity/ui/views/filesystem/filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit c147945

Please sign in to comment.