From e4d67b55722679931c83d57ea58d82045a762c0d Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Wed, 28 Nov 2018 13:26:40 +0100 Subject: [PATCH] [mount] Handle missing configuration keys gracefully - If a key is missing from mount.conf, don't raise KeyError - If both keys are missing, suggest that mount.conf might be missing instead (a consequence of INSTALL_CONFIG=OFF, for instance). - Simplify code a bit. - Don't bother returning None explicitly. --- src/modules/mount/main.py | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/modules/mount/main.py b/src/modules/mount/main.py index 16e7a1f89..29d04e310 100644 --- a/src/modules/mount/main.py +++ b/src/modules/mount/main.py @@ -124,25 +124,24 @@ def run(): """ root_mount_point = tempfile.mkdtemp(prefix="calamares-root-") partitions = libcalamares.globalstorage.value("partitions") - extra_mounts = libcalamares.job.configuration["extraMounts"] - extra_mounts_efi = libcalamares.job.configuration["extraMountsEfi"] + + # Guard against missing keys (generally a sign that the config file is bad) + extra_mounts = libcalamares.job.configuration.get("extraMounts") or [] + extra_mounts_efi = libcalamares.job.configuration.get("extraMountsEfi") or [] + if not extra_mounts and not extra_mounts_efi: + libcalamares.utils.warning("No extra mounts defined. Does mount.conf exist?") # Sort by mount points to ensure / is mounted before the rest partitions.sort(key=lambda x: x["mountPoint"]) mount_partitions(root_mount_point, partitions) mount_partitions(root_mount_point, extra_mounts) - fw_type = libcalamares.globalstorage.value("firmwareType") - if fw_type == 'efi': + all_extra_mounts = extra_mounts + if libcalamares.globalstorage.value("firmwareType") == "efi": mount_partitions(root_mount_point, extra_mounts_efi) + all_extra_mounts.extend(extra_mounts_efi) libcalamares.globalstorage.insert("rootMountPoint", root_mount_point) # Remember the extra mounts for the unpackfs module - if fw_type == 'efi': - libcalamares.globalstorage.insert( - "extraMounts", extra_mounts + extra_mounts_efi) - else: - libcalamares.globalstorage.insert("extraMounts", extra_mounts) - - return None + libcalamares.globalstorage.insert("extraMounts", all_extra_mounts)