From: Daan De Meyer Date: Mon, 18 Mar 2024 08:39:03 +0000 (+0100) Subject: Only add directories with modules in them to the kmods initrd X-Git-Tag: v23~82^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=53d533adcb7e919abdbb7a2d2719ee4d1274bd56;p=thirdparty%2Fmkosi.git Only add directories with modules in them to the kmods initrd --- diff --git a/mkosi/kmod.py b/mkosi/kmod.py index c42fab79b..fbbb5cedd 100644 --- a/mkosi/kmod.py +++ b/mkosi/kmod.py @@ -1,5 +1,6 @@ # SPDX-License-Identifier: LGPL-2.1+ +import itertools import logging import os import re @@ -149,6 +150,14 @@ def resolve_module_dependencies( return set(nametofile[m] for m in mods if m in nametofile), set(firmware) +def parents_relative_to(path: Path, other: Path) -> Iterator[Path]: + for p in path.parents: + if p == other or not p.is_relative_to(other): + return + + yield p + + def gen_required_kernel_modules( root: Path, kver: str, @@ -179,12 +188,10 @@ def gen_required_kernel_modules( if (root / "usr/lib/firmware").exists(): yield root / "usr/lib/firmware" - for d in (modulesd, root / "usr/lib/firmware"): - for p in (root / d).rglob("*"): - if p.is_dir(): - yield p + yield from {p for m in sorted(mods) for p in parents_relative_to(m, modulesd / "kernel")} + yield from {p for f in sorted(firmware) for p in parents_relative_to(f, root / "usr/lib/firmware")} - for p in sorted(mods) + sorted(firmware): + for p in itertools.chain(sorted(mods), sorted(firmware)): yield p for p in (root / modulesd).iterdir():