]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Only add directories with modules in them to the kmods initrd
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Mon, 18 Mar 2024 08:39:03 +0000 (09:39 +0100)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Mon, 18 Mar 2024 09:05:20 +0000 (10:05 +0100)
mkosi/kmod.py

index c42fab79b3c39491ed790ae12c0b41cb213015d4..fbbb5cedd8b67010ba9402175f0c0e93ed78d547 100644 (file)
@@ -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():