From f115a32eddf454a79f908d6b2e5a3563bccb6ffb Mon Sep 17 00:00:00 2001 From: Michael Hudson-Doyle Date: Fri, 15 Jun 2018 11:08:14 +1200 Subject: [PATCH] create mounts for swap when the fs gets created --- subiquity/controllers/filesystem.py | 13 ++++++++- subiquity/models/filesystem.py | 11 +++---- subiquity/ui/views/filesystem/filesystem.py | 32 ++++++++++++--------- 3 files changed, 34 insertions(+), 22 deletions(-) diff --git a/subiquity/controllers/filesystem.py b/subiquity/controllers/filesystem.py index 6fe996a0..0bd96794 100644 --- a/subiquity/controllers/filesystem.py +++ b/subiquity/controllers/filesystem.py @@ -18,7 +18,11 @@ import os from subiquitycore.controller import BaseController -from subiquity.models.filesystem import align_up, DeviceAction +from subiquity.models.filesystem import ( + align_up, + DeviceAction, + Partition, + ) from subiquity.ui.views import ( FilesystemView, GuidedDiskSelectionView, @@ -92,6 +96,13 @@ class FilesystemController(BaseController): if spec['fstype'] is None or spec['fstype'].label is None: return fs = self.model.add_filesystem(volume, spec['fstype'].label) + if isinstance(volume, Partition): + if spec['fstype'].label == "swap": + volume.flag = "swap" + elif volume.flag == "swap": + volume.flag = "" + if spec['fstype'].label == "swap": + self.model.add_mount(fs, "") self.create_mount(fs, spec) return fs diff --git a/subiquity/models/filesystem.py b/subiquity/models/filesystem.py index cefb2c61..9f471b1a 100644 --- a/subiquity/models/filesystem.py +++ b/subiquity/models/filesystem.py @@ -379,7 +379,10 @@ class Mount: path = attr.ib(default=None) def can_delete(self): - # Can't delete /boot/efi mount, anything else is fine. + # Can't delete mount of /boot/efi or swap, anything else is fine. + if not self.path: + # swap mount + return False if not isinstance(self.device.volume, Partition): # Can't be /boot/efi if volume is not a partition return True @@ -438,12 +441,6 @@ class FilesystemModel(object): def render(self): r = [] - for f in self._filesystems: - if f.fstype == 'swap': - if isinstance(f.volume, Partition): - f.volume.flag = "swap" - if f.mount() is None: - self.add_mount(f, "") for d in self._disks.values(): r.append(asdict(d)) for p in self._partitions: diff --git a/subiquity/ui/views/filesystem/filesystem.py b/subiquity/ui/views/filesystem/filesystem.py index 2a13175b..1767a143 100644 --- a/subiquity/ui/views/filesystem/filesystem.py +++ b/subiquity/ui/views/filesystem/filesystem.py @@ -197,7 +197,8 @@ class MountList(WidgetWrap): mountinfos = [ MountInfo(mount=m) for m in sorted( - self.parent.model.all_mounts(), key=lambda m: m.path) + self.parent.model.all_mounts(), + key=lambda m: (m.path == "", m.path)) ] if len(mountinfos) == 0: self.table.set_contents([]) @@ -215,19 +216,22 @@ class MountList(WidgetWrap): for i, mi in enumerate(mountinfos): path_markup = mi.path - for j in range(i-1, -1, -1): - mi2 = mountinfos[j] - if mi.startswith(mi2): - part1 = "/".join(mi.split_path[:len(mi2.split_path)]) - part2 = "/".join( - [''] + mi.split_path[len(mi2.split_path):]) - path_markup = [('info_minor', part1), part2] - break - if j == 0 and mi2.split_path == ['', '']: - path_markup = [ - ('info_minor', "/"), - "/".join(mi.split_path[1:]), - ] + if path_markup == "": + path_markup = ('info_minor', "SWAP") + else: + for j in range(i-1, -1, -1): + mi2 = mountinfos[j] + if mi.startswith(mi2): + part1 = "/".join(mi.split_path[:len(mi2.split_path)]) + part2 = "/".join( + [''] + mi.split_path[len(mi2.split_path):]) + path_markup = [('info_minor', part1), part2] + break + if j == 0 and mi2.split_path == ['', '']: + path_markup = [ + ('info_minor', "/"), + "/".join(mi.split_path[1:]), + ] actions = [(_("Unmount"), mi.mount.can_delete(), 'unmount')] menu = ActionMenu(actions) connect_signal(menu, 'action', self._mount_action, mi.mount)