From 560ad70aeb685c7ec30fa3730ea2de1db15524f5 Mon Sep 17 00:00:00 2001 From: Simon Quigley Date: Wed, 11 Dec 2024 02:24:17 -0600 Subject: [PATCH] Allow for optional items in unpackfs --- src/modules/unpackfs/main.py | 15 +++++++++++---- src/modules/unpackfs/unpackfs.conf | 12 ++++++++++++ src/modules/unpackfs/unpackfs.schema.yaml | 1 + 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/modules/unpackfs/main.py b/src/modules/unpackfs/main.py index a6a84c3d4..fdb4fc9a8 100644 --- a/src/modules/unpackfs/main.py +++ b/src/modules/unpackfs/main.py @@ -48,7 +48,7 @@ class UnpackEntry: :param destination: """ __slots__ = ('source', 'sourcefs', 'destination', 'copied', 'total', 'exclude', 'excludeFile', - 'mountPoint', 'weight', 'condition') + 'mountPoint', 'weight', 'condition', 'optional') def __init__(self, source, sourcefs, destination): """ @@ -72,6 +72,7 @@ class UnpackEntry: self.mountPoint = None self.weight = 1 self.condition = True + self.optional = False def is_file(self): return self.sourcefs == "file" @@ -461,6 +462,7 @@ def run(): for entry in libcalamares.job.configuration["unpack"]: source = os.path.abspath(entry["source"]) sourcefs = entry["sourcefs"] + optional = entry.get("optional", False) if sourcefs not in supported_filesystems: libcalamares.utils.warning("The filesystem for \"{}\" ({}) is not supported by your current kernel".format(source, sourcefs)) @@ -468,9 +470,14 @@ def run(): return (_("Bad unpackfs configuration"), _("The filesystem for \"{}\" ({}) is not supported by your current kernel").format(source, sourcefs)) if not os.path.exists(source): - libcalamares.utils.warning("The source filesystem \"{}\" does not exist".format(source)) - return (_("Bad unpackfs configuration"), - _("The source filesystem \"{}\" does not exist").format(source)) + if optional: + libcalamares.utils.warning("The source filesystem \"{}\" does not exist but is marked as optional, skipping".format(source)) + entry["condition"] = False + continue + else: + libcalamares.utils.warning("The source filesystem \"{}\" does not exist".format(source)) + return (_("Bad unpackfs configuration"), + _("The source filesystem \"{}\" does not exist").format(source)) if sourcefs == "squashfs": if shutil.which("unsquashfs") is None: libcalamares.utils.warning("Failed to find unsquashfs") diff --git a/src/modules/unpackfs/unpackfs.conf b/src/modules/unpackfs/unpackfs.conf index 42f3a943d..1576fa7f3 100644 --- a/src/modules/unpackfs/unpackfs.conf +++ b/src/modules/unpackfs/unpackfs.conf @@ -102,6 +102,18 @@ # sourcefs: squashfs # destination: "" # condition: exampleGlobalStorageVariable.subkey +# +# You may also wish to include optional squashfses, which may not exist at certain times +# depending on your image tooling. If an optional squashfs is not found, it is simply +# skipped. +# +# - source: ./example.standard.sqfs +# sourcefs: squashfs +# destination: "" +# - source: ./example.extras.sqfs +# sourcefs: squashfs +# destination: "" +# optional: true unpack: - source: ../CHANGES diff --git a/src/modules/unpackfs/unpackfs.schema.yaml b/src/modules/unpackfs/unpackfs.schema.yaml index 03faa9440..9dc53c446 100644 --- a/src/modules/unpackfs/unpackfs.schema.yaml +++ b/src/modules/unpackfs/unpackfs.schema.yaml @@ -18,6 +18,7 @@ properties: excludeFile: { type: string } exclude: { type: array, items: { type: string } } weight: { type: integer, exclusiveMinimum: 0 } + optional: { type: boolean } condition: anyOf: - type: boolean