display a message when the user obstinately types in an unsuitable mount point

This commit is contained in:
Michael Hudson-Doyle 2019-07-24 12:27:59 +12:00
parent e79a71fdea
commit 94df386a6c
3 changed files with 30 additions and 6 deletions

View File

@ -53,6 +53,9 @@ suitable_mountpoints_for_existing_fs = [
class MountSelector(WidgetWrap): class MountSelector(WidgetWrap):
signals = ['change']
def __init__(self, mountpoints): def __init__(self, mountpoints):
opts = [] opts = []
first_opt = None first_opt = None
@ -101,6 +104,8 @@ class MountSelector(WidgetWrap):
self._showhide_other(value == OTHER) self._showhide_other(value == OTHER)
if value == OTHER: if value == OTHER:
self._w.focus_position = 1 self._w.focus_position = 1
value = "/" + self._other.value
self._emit('change', value)
@property @property
def value(self): def value(self):

View File

@ -44,7 +44,11 @@ from subiquity.models.filesystem import (
humanize_size, humanize_size,
LVM_VolGroup, LVM_VolGroup,
) )
from subiquity.ui.mount import MountField from subiquity.ui.mount import (
common_mountpoints,
MountField,
suitable_mountpoints_for_existing_fs,
)
log = logging.getLogger('subiquity.ui.filesystem.add_partition') log = logging.getLogger('subiquity.ui.filesystem.add_partition')
@ -99,16 +103,16 @@ class SizeWidget(StringEditor):
except ValueError: except ValueError:
return return
if sz > self.form.max_size: if sz > self.form.max_size:
self.value = self.form.size_str
self.form.size.show_extra( self.form.size.show_extra(
('info_minor', ('info_minor',
_("Capped partition size at {}").format(self.form.size_str))) _("Capped partition size at {}").format(self.form.size_str)))
self.value = self.form.size_str
elif (align_up(sz) != sz and elif (align_up(sz) != sz and
humanize_size(align_up(sz)) != self.form.size.value): humanize_size(align_up(sz)) != self.form.size.value):
sz_str = humanize_size(align_up(sz)) sz_str = humanize_size(align_up(sz))
self.value = sz_str
self.form.size.show_extra( self.form.size.show_extra(
('info_minor', _("Rounded size up to {}").format(sz_str))) ('info_minor', _("Rounded size up to {}").format(sz_str)))
self.value = sz_str
class SizeField(FormField): class SizeField(FormField):
@ -173,7 +177,6 @@ class PartitionForm(Form):
if fstype is None: if fstype is None:
if self.existing_fs_type == "swap": if self.existing_fs_type == "swap":
show_use = True show_use = True
fstype = self.existing_fs_type
if self.form_pile is not None: if self.form_pile is not None:
for i, (w, o) in enumerate(self.form_pile.contents): for i, (w, o) in enumerate(self.form_pile.contents):
if w is self.mount._table and show_use: if w is self.mount._table and show_use:
@ -181,7 +184,14 @@ class PartitionForm(Form):
elif w is self.use_swap._table and not show_use: elif w is self.use_swap._table and not show_use:
self.form_pile.contents[i] = (self.mount._table, o) self.form_pile.contents[i] = (self.mount._table, o)
if getattr(self.device, 'flag', None) != "boot": if getattr(self.device, 'flag', None) != "boot":
self.mount.enabled = self.model.is_mounted_filesystem(fstype) fstype_for_check = fstype
if fstype_for_check is None:
fstype_for_check = self.existing_fs_type
self.mount.enabled = self.model.is_mounted_filesystem(
fstype_for_check)
self.fstype.value = fstype
self.mount.showing_extra = False
self.mount.validate()
name = LVNameField(_("Name: ")) name = LVNameField(_("Name: "))
size = SizeField() size = SizeField()
@ -239,6 +249,15 @@ class PartitionForm(Form):
if dev is not None: if dev is not None:
return _("{} is already mounted at {}.").format( return _("{} is already mounted at {}.").format(
dev.label.title(), mount) dev.label.title(), mount)
if self.existing_fs_type is not None:
if self.fstype.value is None:
if mount in common_mountpoints:
if mount not in suitable_mountpoints_for_existing_fs:
self.mount.show_extra(
('info_error',
_("Mounting an existing filesystem at {} is "
"usually a bad idea, proceed only with "
"caution.").format(mount)))
def as_rows(self): def as_rows(self):
r = super().as_rows() r = super().as_rows()

View File

@ -182,7 +182,7 @@ class BoundFormField(object):
return value return value
def _change(self, sender, new_val): def _change(self, sender, new_val):
if self.in_error: if self.in_error or self.showing_extra:
self.showing_extra = False self.showing_extra = False
# the validator will likely inspect self.value to decide # the validator will likely inspect self.value to decide
# if the new input is valid. So self.value had better # if the new input is valid. So self.value had better